tinymce-editor/copy_this/modules/hdi/hdi-tinymce/tinymce/plugins/visualchars/plugin.min.js

1 line
1.0 KiB
JavaScript
Raw Normal View History

2013-11-14 10:10:41 +01:00
tinymce.PluginManager.add("visualchars",function(e){function t(t){var n,i,o,a,s,l,c=e.getBody(),d=e.selection;if(r=!r,e.fire("VisualChars",{state:r}),t&&(l=d.getBookmark()),r)for(i=[],tinymce.walk(c,function(e){3==e.nodeType&&e.nodeValue&&-1!=e.nodeValue.indexOf(" ")&&i.push(e)},"childNodes"),o=0;o<i.length;o++){for(a=i[o].nodeValue,a=a.replace(/(\u00a0)/g,'<span data-mce-bogus="1" class="mce-nbsp">$1</span>'),s=e.dom.create("div",null,a);n=s.lastChild;)e.dom.insertAfter(n,i[o]);e.dom.remove(i[o])}else for(i=e.dom.select("span.mce-nbsp",c),o=i.length-1;o>=0;o--)e.dom.remove(i[o],1);d.moveToBookmark(l)}function n(){var t=this;e.on("VisualChars",function(e){t.active(e.state)})}var r;e.addCommand("mceVisualChars",t),e.addButton("visualchars",{title:"Show invisible characters",cmd:"mceVisualChars",onPostRender:n}),e.addMenuItem("visualchars",{text:"Show invisible characters",cmd:"mceVisualChars",onPostRender:n,selectable:!0,context:"view",prependToContext:!0}),e.on("beforegetcontent",function(e){r&&"raw"!=e.format&&!e.draft&&(r=!0,t(!1))})});