[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/fckeditor/plugins/imgassist/ -> fckplugin.js (source)

   1  /*
   2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net
   3  * Copyright (C) 2003-2007 Frederico Caldeira Knabben
   4  *
   5  * == BEGIN LICENSE ==
   6  *
   7  * Licensed under the terms of any of the following licenses at your
   8  * choice:
   9  *
  10  *  - GNU General Public License Version 2 or later (the "GPL")
  11  *    http://www.gnu.org/licenses/gpl.html
  12  *
  13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14  *    http://www.gnu.org/licenses/lgpl.html
  15  *
  16  *  - Mozilla Public License Version 1.1 or later (the "MPL")
  17  *    http://www.mozilla.org/MPL/MPL-1.1.html
  18  *
  19  * == END LICENSE ==
  20  *
  21  * Plugin to insert "Placeholders" in the editor.
  22  */
  23  
  24  // The object used for all Placeholder operations.
  25  
  26  //FCK.Events.AttachEvent( 'OnSelectionChange', FCKImgAssist.Redraw ) ;
  27  
  28  
  29  var imgAssistIcon= top.document.getElementById('img_assist-link-' + FCK.Config['TextareaID']);
  30  if (imgAssistIcon){
  31  
  32  var FCKImageAssistProcessor = FCKDocumentProcessor.AppendNew() ;
  33  FCKImageAssistProcessor.ProcessDocument = function( document )
  34  {
  35    // get all elements in FCK document
  36    var elements = document.getElementsByTagName( '*' ) ;
  37  
  38    // check every element for childNodes
  39    var i = 0;
  40    while (element = elements[i++]) {
  41      var nodes = element.childNodes;
  42  
  43      var j = 0;
  44      while (node = nodes[j++]) {
  45        if (node.nodeName == '#text') {
  46            var index = 0;
  47            while (aPlaholders = node.nodeValue.match( /\[img_assist[^\[\]]+\]/g )) {
  48              index = node.nodeValue.indexOf(aPlaholders[0]);
  49              if (index != -1) {
  50                var oImgAs = FCKTools.ImageAssistDecode ( aPlaholders[0] );
  51  
  52                var substr1 = FCK.EditorDocument.createTextNode( node.nodeValue.substring(0, index) );
  53                var substr2 = FCK.EditorDocument.createTextNode( node.nodeValue.substring(index + aPlaholders[0].length) );
  54  
  55                node.parentNode.insertBefore( substr1, node ) ;
  56                node.parentNode.insertBefore( oImgAs, node ) ;
  57                node.parentNode.insertBefore( substr2, node ) ;
  58  
  59                node.parentNode.removeChild( node ) ;
  60                if (node) node.nodeValue='';
  61              }
  62            }
  63        }
  64      }
  65    }
  66  }
  67  
  68  // Open the image_assis dialog on double click.
  69  FCKImageAssistProcessor.OnDoubleClick = function( span ) {
  70    if ( span.tagName == 'IMG' && span._fckimgassist_fckimgassist ) {
  71      FCKCommands.GetCommand( 'Img_Assist' ).Execute() ;
  72    }
  73  }
  74  
  75  //Save reference to the internal FCKeditor TagProcessor
  76  //It must be called to process _fcksavedurl [#352704]
  77  var FCKXHtml_TagProcessors_Img = FCKXHtml.TagProcessors['img'];
  78  
  79  // We must process the IMG tags, change <img...> to [img_assist...]
  80  FCKXHtml.TagProcessors['img'] = function( node, htmlNode )
  81  {
  82    node = FCKXHtml_TagProcessors_Img( node, htmlNode ) ;
  83    
  84    if ( htmlNode.getAttribute('nid') ) {
  85      var IAString = FCKTools.ImageAssistCode ( htmlNode );
  86      if( IAString )
  87      node = FCKXHtml.XML.createTextNode(IAString) ;
  88    }
  89    else{
  90      FCKXHtml._AppendChildNodes( node, htmlNode, false ) ;
  91    }
  92    return node ;
  93  }
  94  
  95  FCKImageAssistProcessor.Redraw = function( document )
  96  {
  97    FCKImageAssistProcessor.ProcessDocument(FCK.EditorDocument);
  98  }
  99  
 100  // Context menu for templates.
 101  FCK.ContextMenu.RegisterListener({
 102    AddItems : function( contextMenu, tag, tagName )
 103    {
 104      if ( tagName == 'IMG' || tagName == 'img') {
 105        if ( tag.getAttribute( '_fckimgassist' ) ) {
 106          contextMenu.RemoveAllItems();
 107          contextMenu.AddItem( 'Img_Assist', 'Image Assist' , FCKConfig.PluginsPath + 'imgassist/imgassist_small.gif') ;
 108        }
 109      }
 110    }
 111  });
 112  
 113  FCKTools.ImageAssistDecode = function( IAString )
 114  {
 115    var IAObj = FCK.EditorDocument.createElement( 'img' ) ;
 116    var IAarg = IAString.match( /\[img_assist\s*([^\]]*?)\]/ );
 117    IAarg=IAarg[1].toString().split("|");
 118    var order = new Array();
 119    for (var k=0;k<IAarg.length;k++) {
 120      index2 = IAarg[k].indexOf('=');
 121      if (index2 != -1) {
 122        var temp_name = IAarg[k].split("=",1)[0];
 123        var temp_val  = IAarg[k].slice(index2+1);
 124        order[k] = temp_name;
 125        if (temp_name == 'width') {
 126          if (parseInt(temp_val) == 'NaN') temp_val=72;
 127          IAObj.style.width = parseInt(temp_val);
 128        }
 129        else if (temp_name == 'height') {
 130          if (parseInt(temp_val) == 'NaN') temp_val=50;
 131          IAObj.style.height = parseInt(temp_val);
 132        }
 133        else {
 134          IAObj.setAttribute(temp_name, temp_val);
 135        }
 136      }
 137    }
 138    if (!IAObj.style.width)  IAObj.setAttribute('width', 72);
 139    if (!IAObj.style.height) IAObj.setAttribute('height', 50);
 140    IAObj.setAttribute ('order', order.join("|"));
 141    IAObj.setAttribute ('src', FCKConfig.BasePath +'images/spacer.gif');
 142    IAObj.setAttribute ('_fckimgassist', 'true');
 143    IAObj._fckimgassist = true ;
 144    IAObj.className = 'image_assist';
 145  
 146    return IAObj;
 147  }
 148  
 149  FCKTools.ImageAssistCode = function( IAObj )
 150  {
 151    var IAString;
 152    if ( IAObj.getAttribute('nid') ) {
 153      var IAString = '[img_assist';
 154      var orderStr = IAObj.getAttribute('order').toString();
 155      var order = orderStr.split("|");
 156      for(var i=1;i<order.length;i++) {
 157        IAString += '|'+ order[i] +'=';
 158        if (IAObj.getAttribute(order[i])) {
 159          IAString += IAObj.getAttribute(order[i]);
 160        }
 161        else if (order[i] == 'width') {
 162          IAString += parseInt(IAObj.style.width);
 163        }
 164        else if (order[i] == 'height') {
 165          IAString += parseInt(IAObj.style.height);
 166        }
 167      }
 168      if ((orderStr.indexOf('width') == -1) && (IAObj.style.width)) {
 169        IAString += '|width='+ parseInt(IAObj.style.width);
 170      }
 171      if ((orderStr.indexOf('height') == -1) && (IAObj.style.height)) {
 172        IAString += '|height='+ parseInt(IAObj.style.height);
 173      }
 174      IAString += ']' ;
 175    }
 176    else {
 177      return false;
 178    }
 179    return IAString;
 180  }
 181  
 182  FCKCommands.RegisterCommand( 'Img_Assist', new FCKDialogCommand( 'Img_Assist', 'Image Assist Object', FCKConfig.PluginsPath + 'imgassist/fck_imgassist.html', 500, 330 ) ) ;
 183  
 184  FCK.Events.AttachEvent( 'OnSelectionChange', FCKImageAssistProcessor.Redraw ) ;
 185  
 186  /*
 187   * Plugin: add image_assist button
 188   */
 189  var FCKimageAssist = function(){
 190    this.EditMode = FCK.EditMode;
 191  }
 192    
 193    FCKimageAssist.prototype.Execute = function(){
 194      if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ) {
 195        return ;
 196      }
 197      ia_icon = top.document.getElementById('img_assist-link-' + FCK.Config['TextareaID']);
 198      ia_href = ia_icon.getAttribute("href");
 199      top.window.open(ia_href, 'img_assist_link', 'width=600,height=350,scrollbars=yes,status=yes,resizable=yes,toolbar=no,menubar=no');
 200    }
 201    // Define the command.
 202    FCKimageAssist.prototype.GetState = function(){
 203      return ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ;
 204    }
 205    FCKCommands.RegisterCommand( 'ImageAssist', new FCKimageAssist() ) ;
 206  
 207    var oIAItem = new FCKToolbarButton( 'ImageAssist', 'Image Assist', null, FCK_TOOLBARITEM_ICONTEXT, true, true ) ;
 208    oIAItem.IconPath = FCKConfig.PluginsPath + 'imgassist/imgassist_small.gif';
 209    // Create the ImageAssist buttons.
 210    FCKToolbarItems.RegisterItem( 'ImageAssist', oIAItem ) ;
 211  
 212    addToolbarElement('ImageAssist', 'Basic', 0);
 213    addToolbarElement('ImageAssist', 'DrupalBasic', 0);
 214    addToolbarElement('ImageAssist', 'Default', 4);
 215    addToolbarElement('ImageAssist', 'DrupalFiltered', 0);
 216    addToolbarElement('ImageAssist', 'DrupalFull', 0);
 217  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7