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