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@45
|
25 if (t.state) {
|
bgneal@45
|
26 t.state = true;
|
bgneal@45
|
27 t._toggleVisualChars();
|
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@45
|
44 _toggleVisualChars : function() {
|
bgneal@45
|
45 var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo;
|
bgneal@45
|
46
|
bgneal@45
|
47 t.state = !t.state;
|
bgneal@45
|
48 ed.controlManager.setActive('visualchars', t.state);
|
bgneal@45
|
49
|
bgneal@45
|
50 if (t.state) {
|
bgneal@45
|
51 nl = [];
|
bgneal@45
|
52 tinymce.walk(b, function(n) {
|
bgneal@45
|
53 if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1)
|
bgneal@45
|
54 nl.push(n);
|
bgneal@45
|
55 }, 'childNodes');
|
bgneal@45
|
56
|
bgneal@45
|
57 for (i=0; i<nl.length; i++) {
|
bgneal@45
|
58 nv = nl[i].nodeValue;
|
bgneal@45
|
59 nv = nv.replace(/(\u00a0+)/g, '<span class="mceItemHidden mceVisualNbsp">$1</span>');
|
bgneal@45
|
60 nv = nv.replace(/\u00a0/g, '\u00b7');
|
bgneal@45
|
61 ed.dom.setOuterHTML(nl[i], nv, d);
|
bgneal@45
|
62 }
|
bgneal@45
|
63 } else {
|
bgneal@45
|
64 nl = tinymce.grep(ed.dom.select('span', b), function(n) {
|
bgneal@45
|
65 return ed.dom.hasClass(n, 'mceVisualNbsp');
|
bgneal@45
|
66 });
|
bgneal@45
|
67
|
bgneal@45
|
68 for (i=0; i<nl.length; i++)
|
bgneal@45
|
69 ed.dom.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(·|\u00b7)/g, ' '), d);
|
bgneal@45
|
70 }
|
bgneal@45
|
71 }
|
bgneal@45
|
72 });
|
bgneal@45
|
73
|
bgneal@45
|
74 // Register plugin
|
bgneal@45
|
75 tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars);
|
bgneal@45
|
76 })(); |