1 |
3 |
ahitrov@rambler.ru |
/** |
2 |
|
|
* editor_plugin_src.js |
3 |
|
|
* |
4 |
|
|
* Copyright 2009, Moxiecode Systems AB |
5 |
|
|
* Released under LGPL License. |
6 |
|
|
* |
7 |
|
|
* License: http://tinymce.moxiecode.com/license |
8 |
|
|
* Contributing: http://tinymce.moxiecode.com/contributing |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
(function() { |
12 |
|
|
tinymce.create('tinymce.plugins.VisualChars', { |
13 |
|
|
init : function(ed, url) { |
14 |
|
|
var t = this; |
15 |
|
|
|
16 |
|
|
t.editor = ed; |
17 |
|
|
|
18 |
|
|
// Register commands |
19 |
|
|
ed.addCommand('mceVisualChars', t._toggleVisualChars, t); |
20 |
|
|
|
21 |
|
|
// Register buttons |
22 |
|
|
ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'}); |
23 |
|
|
|
24 |
|
|
ed.onBeforeGetContent.add(function(ed, o) { |
25 |
|
|
if (t.state) { |
26 |
|
|
t.state = true; |
27 |
|
|
t._toggleVisualChars(); |
28 |
|
|
} |
29 |
|
|
}); |
30 |
|
|
}, |
31 |
|
|
|
32 |
|
|
getInfo : function() { |
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 |
|
|
}, |
41 |
|
|
|
42 |
|
|
// Private methods |
43 |
|
|
|
44 |
|
|
_toggleVisualChars : function() { |
45 |
|
|
var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo; |
46 |
|
|
|
47 |
|
|
t.state = !t.state; |
48 |
|
|
ed.controlManager.setActive('visualchars', t.state); |
49 |
|
|
|
50 |
|
|
if (t.state) { |
51 |
|
|
nl = []; |
52 |
|
|
tinymce.walk(b, function(n) { |
53 |
|
|
if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1) |
54 |
|
|
nl.push(n); |
55 |
|
|
}, 'childNodes'); |
56 |
|
|
|
57 |
|
|
for (i=0; i<nl.length; i++) { |
58 |
|
|
nv = nl[i].nodeValue; |
59 |
|
|
nv = nv.replace(/(\u00a0+)/g, '<span class="mceItemHidden mceVisualNbsp">$1</span>'); |
60 |
|
|
nv = nv.replace(/\u00a0/g, '\u00b7'); |
61 |
|
|
ed.dom.setOuterHTML(nl[i], nv, d); |
62 |
|
|
} |
63 |
|
|
} else { |
64 |
|
|
nl = tinymce.grep(ed.dom.select('span', b), function(n) { |
65 |
|
|
return ed.dom.hasClass(n, 'mceVisualNbsp'); |
66 |
|
|
}); |
67 |
|
|
|
68 |
|
|
for (i=0; i<nl.length; i++) |
69 |
|
|
ed.dom.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(·|\u00b7)/g, ' '), d); |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
}); |
73 |
|
|
|
74 |
|
|
// Register plugin |
75 |
|
|
tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars); |
76 |
|
|
})(); |