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