PageRenderTime 27ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/visualchars/editor_plugin_src.js

#
JavaScript | 83 lines | 53 code | 17 blank | 13 comment | 15 complexity | f285c8f2ffac745325e86687b8cf0fb5 MD5 | raw file
 1/**
 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 && o.format != 'raw' && !o.draft) {
26					t.state = true;
27					t._toggleVisualChars(false);
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(bookmark) {
45			var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo, div, bm;
46
47			t.state = !t.state;
48			ed.controlManager.setActive('visualchars', t.state);
49
50			if (bookmark)
51				bm = s.getBookmark();
52
53			if (t.state) {
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');
59
60				for (i = 0; i < nl.length; i++) {
61					nv = nl[i].nodeValue;
62					nv = nv.replace(/(\u00a0)/g, '<span data-mce-bogus="1" class="mceItemHidden mceItemNbsp">$1</span>');
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]);
69				}
70			} else {
71				nl = ed.dom.select('span.mceItemNbsp', b);
72
73				for (i = nl.length - 1; i >= 0; i--)
74					ed.dom.remove(nl[i], 1);
75			}
76
77			s.moveToBookmark(bm);
78		}
79	});
80
81	// Register plugin
82	tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars);
83})();