Subversion Repositories Sites.tela-botanica.org

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
420 florian 1
/**
2
 * $Id: editor_plugin_src.js 42 2006-08-08 14:32:24Z spocke $
3
 *
4
 * @author Moxiecode
5
 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
6
 */
7
 
8
/* Import plugin specific language pack */
9
tinyMCE.importPluginLanguagePack('visualchars');
10
 
11
var TinyMCE_VisualCharsPlugin = {
12
	getInfo : function() {
13
		return {
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
19
		};
20
	},
21
 
22
	initInstance : function(inst) {
23
		inst.visualChars = {
24
			state : false
25
		};
26
	},
27
 
28
	getControlHTML : function(cn) {
29
		switch (cn) {
30
			case "visualchars":
31
				return tinyMCE.getButtonHTML(cn, 'lang_visualchars_desc', '{$pluginurl}/images/visualchars.gif', 'mceVisualChars', false);
32
		}
33
 
34
		return "";
35
	},
36
 
37
	execCommand : function(editor_id, element, command, user_interface, value) {
38
		var inst = tinyMCE.getInstanceById(editor_id);
39
 
40
		switch (command) {
41
			case "mceVisualChars":
42
				this._toggleVisualChars(editor_id, inst);
43
				return true;
44
		}
45
 
46
		return false;
47
	},
48
 
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);
53
		}
54
 
55
		return content;
56
	},
57
 
58
	// Private plugin internal methods
59
 
60
	_toggleVisualChars : function(editor_id, inst) {
61
		var nl, i, h, d = inst.getDoc(), b = inst.getBody(), nv, s = inst.selection, bo;
62
 
63
		inst.visualChars.state = !inst.visualChars.state;
64
 
65
		bo = s.getBookmark(true);
66
 
67
		tinyMCE.switchClass(editor_id + '_visualchars', inst.visualChars.state ? 'mceButtonSelected' : 'mceButtonNormal');
68
 
69
		if (inst.visualChars.state) {
70
			nl = tinyMCE.selectNodes(b, function(n) {return n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1;});
71
 
72
			for (i=0; i<nl.length; i++) {
73
				nv = nl[i].nodeValue;
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);
77
			}
78
		} else {
79
			nl = tinyMCE.selectNodes(b, function(n) {return n.nodeType == 1 && n.nodeName == 'SPAN' && n.className == 'mceItemHiddenVisualChar';});
80
 
81
			for (i=0; i<nl.length; i++)
82
				tinyMCE.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(&middot;|\u00b7)/g, '&nbsp;'), d);
83
		}
84
 
85
		//s.moveToBookmark(bo);
86
	}
87
};
88
 
89
tinyMCE.addPlugin("visualchars", TinyMCE_VisualCharsPlugin);