Upgrade TinyMCE to v3.4.5
[citadel.git] / webcit / tiny_mce / plugins / visualchars / editor_plugin_src.js
old mode 100755 (executable)
new mode 100644 (file)
index fb7236d..df98590
@@ -1,89 +1,83 @@
 /**\r
- * $Id: editor_plugin_src.js 42 2006-08-08 14:32:24Z spocke $\r
+ * editor_plugin_src.js\r
  *\r
- * @author Moxiecode\r
- * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.\r
+ * Copyright 2009, Moxiecode Systems AB\r
+ * Released under LGPL License.\r
+ *\r
+ * License: http://tinymce.moxiecode.com/license\r
+ * Contributing: http://tinymce.moxiecode.com/contributing\r
  */\r
 \r
-/* Import plugin specific language pack */\r
-tinyMCE.importPluginLanguagePack('visualchars');\r
-\r
-var TinyMCE_VisualCharsPlugin = {\r
-       getInfo : function() {\r
-               return {\r
-                       longname : 'Visual characters',\r
-                       author : 'Moxiecode Systems AB',\r
-                       authorurl : 'http://tinymce.moxiecode.com',\r
-                       infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars',\r
-                       version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
-               };\r
-       },\r
-\r
-       initInstance : function(inst) {\r
-               inst.visualChars = {\r
-                       state : false\r
-               };\r
-       },\r
-\r
-       getControlHTML : function(cn) {\r
-               switch (cn) {\r
-                       case "visualchars":\r
-                               return tinyMCE.getButtonHTML(cn, 'lang_visualchars_desc', '{$pluginurl}/images/visualchars.gif', 'mceVisualChars', false);\r
-               }\r
-\r
-               return "";\r
-       },\r
-\r
-       execCommand : function(editor_id, element, command, user_interface, value) {\r
-               var inst = tinyMCE.getInstanceById(editor_id);\r
-\r
-               switch (command) {\r
-                       case "mceVisualChars":\r
-                               this._toggleVisualChars(editor_id, inst);\r
-                               return true;\r
-               }\r
-\r
-               return false;\r
-       },\r
-\r
-       cleanup : function(type, content, inst) {\r
-               if (type == "insert_to_editor_dom" || type == "get_from_editor_dom") {\r
-                       inst.visualChars.state = true;\r
-                       this._toggleVisualChars(inst.editorId, inst);\r
-               }\r
-\r
-               return content;\r
-       },\r
-\r
-       // Private plugin internal methods\r
-\r
-       _toggleVisualChars : function(editor_id, inst) {\r
-               var nl, i, h, d = inst.getDoc(), b = inst.getBody(), nv, s = inst.selection, bo;\r
-\r
-               inst.visualChars.state = !inst.visualChars.state;\r
-\r
-               bo = s.getBookmark(true);\r
-\r
-               tinyMCE.switchClass(editor_id + '_visualchars', inst.visualChars.state ? 'mceButtonSelected' : 'mceButtonNormal');\r
-\r
-               if (inst.visualChars.state) {\r
-                       nl = tinyMCE.selectNodes(b, function(n) {return n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1;});\r
-\r
-                       for (i=0; i<nl.length; i++) {\r
-                               nv = nl[i].nodeValue;\r
-                               nv = nv.replace(/(\u00a0+)/g, '<span class="mceItemHiddenVisualChar">$1</span>');\r
-                               nv = nv.replace(/\u00a0/g, '\u00b7');\r
-                               tinyMCE.setOuterHTML(nl[i], nv, d);\r
+(function() {\r
+       tinymce.create('tinymce.plugins.VisualChars', {\r
+               init : function(ed, url) {\r
+                       var t = this;\r
+\r
+                       t.editor = ed;\r
+\r
+                       // Register commands\r
+                       ed.addCommand('mceVisualChars', t._toggleVisualChars, t);\r
+\r
+                       // Register buttons\r
+                       ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'});\r
+\r
+                       ed.onBeforeGetContent.add(function(ed, o) {\r
+                               if (t.state && o.format != 'raw' && !o.draft) {\r
+                                       t.state = true;\r
+                                       t._toggleVisualChars(false);\r
+                               }\r
+                       });\r
+               },\r
+\r
+               getInfo : function() {\r
+                       return {\r
+                               longname : 'Visual characters',\r
+                               author : 'Moxiecode Systems AB',\r
+                               authorurl : 'http://tinymce.moxiecode.com',\r
+                               infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars',\r
+                               version : tinymce.majorVersion + "." + tinymce.minorVersion\r
+                       };\r
+               },\r
+\r
+               // Private methods\r
+\r
+               _toggleVisualChars : function(bookmark) {\r
+                       var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo, div, bm;\r
+\r
+                       t.state = !t.state;\r
+                       ed.controlManager.setActive('visualchars', t.state);\r
+\r
+                       if (bookmark)\r
+                               bm = s.getBookmark();\r
+\r
+                       if (t.state) {\r
+                               nl = [];\r
+                               tinymce.walk(b, function(n) {\r
+                                       if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1)\r
+                                               nl.push(n);\r
+                               }, 'childNodes');\r
+\r
+                               for (i = 0; i < nl.length; i++) {\r
+                                       nv = nl[i].nodeValue;\r
+                                       nv = nv.replace(/(\u00a0)/g, '<span data-mce-bogus="1" class="mceItemHidden mceItemNbsp">$1</span>');\r
+\r
+                                       div = ed.dom.create('div', null, nv);\r
+                                       while (node = div.lastChild)\r
+                                               ed.dom.insertAfter(node, nl[i]);\r
+\r
+                                       ed.dom.remove(nl[i]);\r
+                               }\r
+                       } else {\r
+                               nl = ed.dom.select('span.mceItemNbsp', b);\r
+\r
+                               for (i = nl.length - 1; i >= 0; i--)\r
+                                       ed.dom.remove(nl[i], 1);\r
                        }\r
-               } else {\r
-                       nl = tinyMCE.selectNodes(b, function(n) {return n.nodeType == 1 && n.nodeName == 'SPAN' && n.className == 'mceItemHiddenVisualChar';});\r
 \r
-                       for (i=0; i<nl.length; i++)\r
-                               tinyMCE.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(&middot;|\u00b7)/g, '&nbsp;'), d);\r
+                       s.moveToBookmark(bm);\r
                }\r
+       });\r
 \r
-               //s.moveToBookmark(bo);\r
-       }\r
-};\r
-\r
-tinyMCE.addPlugin("visualchars", TinyMCE_VisualCharsPlugin);\r
+       // Register plugin\r
+       tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars);\r
+})();
\ No newline at end of file