[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/mambots/editors/tinymce/jscripts/tiny_mce/plugins/noneditable/ -> editor_plugin_src.js (source)

   1  /**

   2   * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $

   3   *

   4   * @author Moxiecode

   5   * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.

   6   */
   7  
   8  var TinyMCE_NonEditablePlugin = {
   9      getInfo : function() {
  10          return {
  11              longname : 'Non editable elements',
  12              author : 'Moxiecode Systems AB',
  13              authorurl : 'http://tinymce.moxiecode.com',
  14              infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_noneditable.html',
  15              version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
  16          };
  17      },
  18  
  19      initInstance : function(inst) {
  20          tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/noneditable/css/noneditable.css");
  21  
  22          // Ugly hack

  23          if (tinyMCE.isMSIE5_0)
  24              tinyMCE.settings['plugins'] = tinyMCE.settings['plugins'].replace(/noneditable/gi, 'Noneditable');
  25      },
  26  
  27      handleEvent : function(e) {
  28          return this._moveSelection(e, tinyMCE.selectedInstance);
  29      },
  30  
  31      cleanup : function(type, content, inst) {
  32          // Pass through Gecko

  33          if (tinyMCE.isGecko)
  34              return content;
  35  
  36          switch (type) {
  37              case "insert_to_editor_dom":
  38                  var nodes = tinyMCE.getNodeTree(content, new Array(), 1);
  39                  var editClass = tinyMCE.getParam("noneditable_editable_class", "mceItemEditable");
  40                  var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceItemNonEditable");
  41  
  42                  for (var i=0; i<nodes.length; i++) {
  43                      var elm = nodes[i];
  44  
  45                      // Convert contenteditable to classes

  46                      var editable = tinyMCE.getAttrib(elm, "contenteditable");
  47                      if (new RegExp("true|false","gi").test(editable))
  48                          TinyMCE_NonEditablePlugin._setEditable(elm, editable == "true");
  49  
  50                      if (tinyMCE.isMSIE) {
  51                          var className = elm.className ? elm.className : "";
  52  
  53                          if (className.indexOf(editClass) != -1)
  54                              elm.contentEditable = true;
  55  
  56                          if (className.indexOf(nonEditClass) != -1)
  57                              elm.contentEditable = false;
  58                      }
  59                  }
  60  
  61                  break;
  62  
  63              case "insert_to_editor":
  64                  if (tinyMCE.isMSIE) {
  65                      var editClass = tinyMCE.getParam("noneditable_editable_class", "mceItemEditable");
  66                      var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceItemNonEditable");
  67  
  68                      content = content.replace(new RegExp("class=\"(.*)(" + editClass + ")([^\"]*)\"", "gi"), 'class="$1$2$3" contenteditable="true"');
  69                      content = content.replace(new RegExp("class=\"(.*)(" + nonEditClass + ")([^\"]*)\"", "gi"), 'class="$1$2$3" contenteditable="false"');
  70                  }
  71  
  72                  break;
  73  
  74              case "get_from_editor_dom":
  75                  if (tinyMCE.getParam("noneditable_leave_contenteditable", false)) {
  76                      var nodes = tinyMCE.getNodeTree(content, new Array(), 1);
  77  
  78                      for (var i=0; i<nodes.length; i++)
  79                          nodes[i].removeAttribute("contenteditable");
  80                  }
  81  
  82                  break;
  83          }
  84  
  85          return content;
  86      },
  87  
  88      _moveSelection : function(e, inst) {
  89          var s, r, sc, ec, el, c = tinyMCE.getParam('noneditable_editable_class', 'mceItemNonEditable');
  90  
  91          if (!inst)
  92              return true;
  93  
  94          // Always select whole element

  95          if (tinyMCE.isGecko) {
  96              s = inst.selection.getSel();
  97              r = s.getRangeAt(0);
  98              sc = tinyMCE.getParentNode(r.startContainer, function (n) {return tinyMCE.hasCSSClass(n, c);});
  99              ec = tinyMCE.getParentNode(r.endContainer, function (n) {return tinyMCE.hasCSSClass(n, c);});
 100  
 101              sc && r.setStartBefore(sc);
 102              ec && r.setEndAfter(ec);
 103  
 104              if (sc || ec) {
 105                  if (e.type == 'keypress' && e.keyCode == 39) {
 106                      el = sc || ec;
 107  
 108                      // Try!!

 109                  }
 110  
 111                  s.removeAllRanges();
 112                  s.addRange(r);
 113  
 114                  return tinyMCE.cancelEvent(e);
 115              }
 116          }
 117  
 118          return true;
 119      },
 120  
 121      _setEditable : function(elm, state) {
 122          var editClass = tinyMCE.getParam("noneditable_editable_class", "mceItemEditable");
 123          var nonEditClass = tinyMCE.getParam("noneditable_noneditable_class", "mceItemNonEditable");
 124  
 125          var className = elm.className ? elm.className : "";
 126  
 127          if (className.indexOf(editClass) != -1 || className.indexOf(nonEditClass) != -1)
 128              return;
 129  
 130          if ((className = tinyMCE.getAttrib(elm, "class")) != "")
 131              className += " ";
 132  
 133          className += state ? editClass : nonEditClass;
 134  
 135          elm.setAttribute("class", className);
 136          elm.className = className;
 137      }
 138  };
 139  
 140  tinyMCE.addPlugin("noneditable", TinyMCE_NonEditablePlugin);


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics