2
* $Id: editor_plugin_src.js 42 2006-08-08 14:32:24Z spocke $
5
* @copyright Copyright � 2004-2007, Moxiecode Systems AB, All rights reserved.
8
/* Import plugin specific language pack */
9
tinyMCE.importPluginLanguagePack('visualchars');
11
var TinyMCE_VisualCharsPlugin = {
12
getInfo : function() {
14
longname : 'Visual characters',
15
author : 'Moxiecode Systems AB',
16
authorurl : 'http://tinymce.moxiecode.com',
17
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars',
18
version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
22
initInstance : function(inst) {
28
getControlHTML : function(cn) {
31
return tinyMCE.getButtonHTML(cn, 'lang_visualchars_desc', '{$pluginurl}/images/visualchars.gif', 'mceVisualChars', false);
37
execCommand : function(editor_id, element, command, user_interface, value) {
38
var inst = tinyMCE.getInstanceById(editor_id);
41
case "mceVisualChars":
42
this._toggleVisualChars(editor_id, inst);
49
cleanup : function(type, content, inst) {
50
if (type == "insert_to_editor_dom" || type == "get_from_editor_dom") {
51
inst.visualChars.state = true;
52
this._toggleVisualChars(inst.editorId, inst);
58
// Private plugin internal methods
60
_toggleVisualChars : function(editor_id, inst) {
61
var nl, i, h, d = inst.getDoc(), b = inst.getBody(), nv, s = inst.selection, bo;
63
inst.visualChars.state = !inst.visualChars.state;
65
bo = s.getBookmark(true);
67
tinyMCE.switchClass(editor_id + '_visualchars', inst.visualChars.state ? 'mceButtonSelected' : 'mceButtonNormal');
69
if (inst.visualChars.state) {
70
nl = tinyMCE.selectNodes(b, function(n) {return n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1;});
72
for (i=0; i<nl.length; i++) {
74
nv = nv.replace(/(\u00a0+)/g, '<span class="mceItemHiddenVisualChar">$1</span>');
75
nv = nv.replace(/\u00a0/g, '\u00b7');
76
tinyMCE.setOuterHTML(nl[i], nv, d);
79
nl = tinyMCE.selectNodes(b, function(n) {return n.nodeType == 1 && n.nodeName == 'SPAN' && n.className == 'mceItemHiddenVisualChar';});
81
for (i=0; i<nl.length; i++)
82
tinyMCE.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(·|\u00b7)/g, ' '), d);
85
//s.moveToBookmark(bo);
89
tinyMCE.addPlugin("visualchars", TinyMCE_VisualCharsPlugin);