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