Upgrade TinyMCE to v3.4.5
[citadel.git] / webcit / tiny_mce / plugins / visualchars / editor_plugin_src.js
1 /**\r
2  * editor_plugin_src.js\r
3  *\r
4  * Copyright 2009, Moxiecode Systems AB\r
5  * Released under LGPL License.\r
6  *\r
7  * License: http://tinymce.moxiecode.com/license\r
8  * Contributing: http://tinymce.moxiecode.com/contributing\r
9  */\r
10 \r
11 (function() {\r
12         tinymce.create('tinymce.plugins.VisualChars', {\r
13                 init : function(ed, url) {\r
14                         var t = this;\r
15 \r
16                         t.editor = ed;\r
17 \r
18                         // Register commands\r
19                         ed.addCommand('mceVisualChars', t._toggleVisualChars, t);\r
20 \r
21                         // Register buttons\r
22                         ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'});\r
23 \r
24                         ed.onBeforeGetContent.add(function(ed, o) {\r
25                                 if (t.state && o.format != 'raw' && !o.draft) {\r
26                                         t.state = true;\r
27                                         t._toggleVisualChars(false);\r
28                                 }\r
29                         });\r
30                 },\r
31 \r
32                 getInfo : function() {\r
33                         return {\r
34                                 longname : 'Visual characters',\r
35                                 author : 'Moxiecode Systems AB',\r
36                                 authorurl : 'http://tinymce.moxiecode.com',\r
37                                 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars',\r
38                                 version : tinymce.majorVersion + "." + tinymce.minorVersion\r
39                         };\r
40                 },\r
41 \r
42                 // Private methods\r
43 \r
44                 _toggleVisualChars : function(bookmark) {\r
45                         var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo, div, bm;\r
46 \r
47                         t.state = !t.state;\r
48                         ed.controlManager.setActive('visualchars', t.state);\r
49 \r
50                         if (bookmark)\r
51                                 bm = s.getBookmark();\r
52 \r
53                         if (t.state) {\r
54                                 nl = [];\r
55                                 tinymce.walk(b, function(n) {\r
56                                         if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1)\r
57                                                 nl.push(n);\r
58                                 }, 'childNodes');\r
59 \r
60                                 for (i = 0; i < nl.length; i++) {\r
61                                         nv = nl[i].nodeValue;\r
62                                         nv = nv.replace(/(\u00a0)/g, '<span data-mce-bogus="1" class="mceItemHidden mceItemNbsp">$1</span>');\r
63 \r
64                                         div = ed.dom.create('div', null, nv);\r
65                                         while (node = div.lastChild)\r
66                                                 ed.dom.insertAfter(node, nl[i]);\r
67 \r
68                                         ed.dom.remove(nl[i]);\r
69                                 }\r
70                         } else {\r
71                                 nl = ed.dom.select('span.mceItemNbsp', b);\r
72 \r
73                                 for (i = nl.length - 1; i >= 0; i--)\r
74                                         ed.dom.remove(nl[i], 1);\r
75                         }\r
76 \r
77                         s.moveToBookmark(bm);\r
78                 }\r
79         });\r
80 \r
81         // Register plugin\r
82         tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars);\r
83 })();