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