bgneal@312: /** bgneal@312: * editor_plugin_src.js bgneal@312: * bgneal@312: * Copyright 2009, Moxiecode Systems AB bgneal@312: * Released under LGPL License. bgneal@312: * bgneal@312: * License: http://tinymce.moxiecode.com/license bgneal@312: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@312: */ bgneal@312: bgneal@312: (function() { bgneal@312: tinymce.create('tinymce.plugins.VisualChars', { bgneal@312: init : function(ed, url) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.editor = ed; bgneal@312: bgneal@312: // Register commands bgneal@312: ed.addCommand('mceVisualChars', t._toggleVisualChars, t); bgneal@312: bgneal@312: // Register buttons bgneal@312: ed.addButton('visualchars', {title : 'visualchars.desc', cmd : 'mceVisualChars'}); bgneal@312: bgneal@312: ed.onBeforeGetContent.add(function(ed, o) { bgneal@312: if (t.state && o.format != 'raw' && !o.draft) { bgneal@312: t.state = true; bgneal@312: t._toggleVisualChars(false); bgneal@312: } bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: getInfo : function() { bgneal@312: return { bgneal@312: longname : 'Visual characters', bgneal@312: author : 'Moxiecode Systems AB', bgneal@312: authorurl : 'http://tinymce.moxiecode.com', bgneal@312: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars', bgneal@312: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: // Private methods bgneal@312: bgneal@312: _toggleVisualChars : function(bookmark) { bgneal@312: var t = this, ed = t.editor, nl, i, h, d = ed.getDoc(), b = ed.getBody(), nv, s = ed.selection, bo, div, bm; bgneal@312: bgneal@312: t.state = !t.state; bgneal@312: ed.controlManager.setActive('visualchars', t.state); bgneal@312: bgneal@312: if (bookmark) bgneal@312: bm = s.getBookmark(); bgneal@312: bgneal@312: if (t.state) { bgneal@312: nl = []; bgneal@312: tinymce.walk(b, function(n) { bgneal@312: if (n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1) bgneal@312: nl.push(n); bgneal@312: }, 'childNodes'); bgneal@312: bgneal@312: for (i = 0; i < nl.length; i++) { bgneal@312: nv = nl[i].nodeValue; bgneal@442: nv = nv.replace(/(\u00a0)/g, '$1'); bgneal@312: bgneal@312: div = ed.dom.create('div', null, nv); bgneal@312: while (node = div.lastChild) bgneal@312: ed.dom.insertAfter(node, nl[i]); bgneal@312: bgneal@312: ed.dom.remove(nl[i]); bgneal@312: } bgneal@312: } else { bgneal@312: nl = ed.dom.select('span.mceItemNbsp', b); bgneal@312: bgneal@312: for (i = nl.length - 1; i >= 0; i--) bgneal@312: ed.dom.remove(nl[i], 1); bgneal@312: } bgneal@312: bgneal@312: s.moveToBookmark(bm); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Register plugin bgneal@312: tinymce.PluginManager.add('visualchars', tinymce.plugins.VisualChars); bgneal@312: })();