-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor_plugin_src.js
executable file
·148 lines (115 loc) · 4.41 KB
/
editor_plugin_src.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
*
* @author Moxiecode
* @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
*/
/* Import plugin specific language pack */
tinyMCE.importPluginLanguagePack('ts_advimage');
var TinyMCE_ThriveSmartAdvancedImagePlugin = {
getInfo : function() {
return {
longname : 'ThriveSmart Advanced image',
author : 'ThriveSmart LLC',
authorurl : 'http://www.thrivesmart.com',
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advimage',
version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
};
},
getControlHTML : function(cn) {
switch (cn) {
case "ts_image":
return tinyMCE.getButtonHTML(cn, 'lang_image_desc', '{$themeurl}/images/image.gif', 'mceTSAdvImage');
}
return "";
},
execCommand : function(editor_id, element, command, user_interface, value) {
switch (command) {
case "mceTSAdvImage":
var template = new Array();
template['file'] = '../../plugins/ts_advimage/image.htm';
template['width'] = 480;
template['height'] = 450;
// Language specific width and height addons
template['width'] += tinyMCE.getLang('lang_advimage_delta_width', 0);
template['height'] += tinyMCE.getLang('lang_advimage_delta_height', 0);
var inst = tinyMCE.getInstanceById(editor_id);
var elm = inst.getFocusElement();
if (elm != null && tinyMCE.getAttrib(elm, 'class').indexOf('mceItem') != -1)
return true;
tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
return true;
}
return false;
},
cleanup : function(type, content) {
switch (type) {
case "insert_to_editor_dom":
var imgs = content.getElementsByTagName("img"), src, i;
for (i=0; i<imgs.length; i++) {
var onmouseover = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(imgs[i], 'onmouseover'));
var onmouseout = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(imgs[i], 'onmouseout'));
if ((src = this._getImageSrc(onmouseover)) != "") {
if (tinyMCE.getParam('convert_urls'))
src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);
imgs[i].setAttribute('onmouseover', "this.src='" + src + "';");
}
if ((src = this._getImageSrc(onmouseout)) != "") {
if (tinyMCE.getParam('convert_urls'))
src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);
imgs[i].setAttribute('onmouseout', "this.src='" + src + "';");
}
}
break;
case "get_from_editor_dom":
var imgs = content.getElementsByTagName("img");
for (var i=0; i<imgs.length; i++) {
var onmouseover = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(imgs[i], 'onmouseover'));
var onmouseout = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(imgs[i], 'onmouseout'));
if ((src = this._getImageSrc(onmouseover)) != "") {
if (tinyMCE.getParam('convert_urls'))
src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
imgs[i].setAttribute('onmouseover', "this.src='" + src + "';");
}
if ((src = this._getImageSrc(onmouseout)) != "") {
if (tinyMCE.getParam('convert_urls'))
src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
imgs[i].setAttribute('onmouseout', "this.src='" + src + "';");
}
}
break;
}
return content;
},
handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
if (node == null)
return;
do {
if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('mceItem') == -1) {
tinyMCE.switchClass(editor_id + '_advimage', 'mceButtonSelected');
return true;
}
} while ((node = node.parentNode));
tinyMCE.switchClass(editor_id + '_advimage', 'mceButtonNormal');
return true;
},
/**
* Returns the image src from a scripted mouse over image str.
*
* @param {string} s String to get real src from.
* @return Image src from a scripted mouse over image str.
* @type string
*/
_getImageSrc : function(s) {
var sr, p = -1;
if (!s)
return "";
if ((p = s.indexOf('this.src=')) != -1) {
sr = s.substring(p + 10);
sr = sr.substring(0, sr.indexOf('\''));
return sr;
}
return "";
}
};
tinyMCE.addPlugin("ts_advimage", TinyMCE_ThriveSmartAdvancedImagePlugin);