web/drupal/modules/fckeditor/img_assist_fckeditor.js
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 //
       
     2 // Load the img_assist_textarea.js script
       
     3 //
       
     4 // Get the header of the document
       
     5 var head= document.getElementsByTagName('head')[0];
       
     6 // Create a new script object
       
     7 
       
     8 function fckeditor_add_script(src) {
       
     9   var script= document.createElement('script');
       
    10   script.type= 'text/javascript';
       
    11   script.src = src;
       
    12   head.appendChild(script);
       
    13 }
       
    14 
       
    15 // Source dirname is built from the second script tag found in the document
       
    16 for (var i = 0; i < head.getElementsByTagName('script').length; i++) {
       
    17   if ( head.getElementsByTagName('script')[i].src.match( /img_assist/ ) ) {
       
    18     fckeditor_add_script(head.getElementsByTagName('script')[i].src.replace( /img_assist[_a-z]*\.js/, 'img_assist_textarea.js' ));
       
    19     break;
       
    20   }
       
    21 }
       
    22 
       
    23 setTimeout("InitFCKeditorImgAssist();", 1000);
       
    24 
       
    25 function InitFCKeditorImgAssist() {
       
    26   var oldInsertToEditor = insertToEditor;
       
    27 
       
    28   insertToEditor = function(content) {
       
    29 
       
    30     //handle FCKeditor in popup mode
       
    31     if ((myTextarea == '') && (window.opener)) {
       
    32       var myDoc = window.opener;
       
    33       if (myDoc.oFCKeditor) {
       
    34         var inst= myDoc.oFCKeditor.InstanceName;
       
    35         var oEditor = myDoc.FCKeditorAPI.GetInstance( inst );
       
    36         if (oEditor.EditMode == myDoc.FCK_EDITMODE_WYSIWYG) {
       
    37           oEditor.InsertHtml(content) ;
       
    38         }
       
    39         else {
       
    40           alert('Inserting image into FCKeditor is allowed only in WYSIWYG mode');
       
    41         }
       
    42         cancelAction();
       
    43         return false;
       
    44       }
       
    45     }
       
    46 
       
    47     //FCKeditor enabled and running == textarea not displayed
       
    48     if ( myTextarea.style.display == 'none' ) {
       
    49       var opener = window.opener;
       
    50       if (opener.fckLaunchedJsId)
       
    51       for( var i = 0 ; i < opener.fckLaunchedJsId.length ; i++ ) {
       
    52         if ( opener.fckLaunchedTextareaId[i] == myTextarea.id ) {
       
    53           var oEditor = opener.FCKeditorAPI.GetInstance( opener.fckLaunchedJsId[i] );
       
    54           if (oEditor.EditMode == opener.FCK_EDITMODE_WYSIWYG) {
       
    55             oEditor.InsertHtml(content) ;
       
    56           }
       
    57           else {
       
    58             alert('Inserting image into FCKeditor is allowed only in WYSIWYG mode');
       
    59           }
       
    60         }
       
    61       }
       
    62       cancelAction();
       
    63       return false;
       
    64     }
       
    65 
       
    66     oldInsertToEditor(content);
       
    67   };
       
    68 }
       
    69 
       
    70 //#321844
       
    71 if (typeof(initLoader) == 'undefined') {
       
    72   var myDoc, myForm, myTextarea, hasInputFormat;
       
    73 
       
    74   var initLoader = function() {
       
    75     // Save the references to the parent form and textarea to be used later.
       
    76     myDoc      = window.opener.document; // global (so don't use var keyword)
       
    77     myForm     = '';
       
    78     myTextarea = '';
       
    79     hasInputFormat = false;
       
    80 
       
    81     var args = getArgs(); // get the querystring arguments
       
    82     var textarea = args.textarea;
       
    83 
       
    84     // Reference the form object for this textarea.
       
    85     if (myDoc.getElementsByTagName) {
       
    86       var f = myDoc.getElementsByTagName('form');
       
    87       for (var i=0; i<f.length; i++) {
       
    88         // Is this textarea is using an input format?
       
    89         if (f[i]['edit-format']) {
       
    90           hasInputFormat = true;
       
    91         }
       
    92         if (f[i][textarea]) {
       
    93           myForm = f[i];
       
    94           myTextarea = f[i][textarea];
       
    95           break;
       
    96         }
       
    97       }
       
    98     }
       
    99     frames['img_assist_main'].window.location.href = BASE_URL + 'index.php?q=img_assist/thumbs/myimages';
       
   100   }
       
   101 }