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('flash');
|
|
10 |
|
|
11 |
var TinyMCE_FlashPlugin = {
|
|
12 |
getInfo : function() {
|
|
13 |
return {
|
|
14 |
longname : 'Flash',
|
|
15 |
author : 'Moxiecode Systems AB',
|
|
16 |
authorurl : 'http://tinymce.moxiecode.com',
|
|
17 |
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/flash',
|
|
18 |
version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
|
|
19 |
};
|
|
20 |
},
|
|
21 |
|
|
22 |
initInstance : function(inst) {
|
|
23 |
if (!tinyMCE.settings['flash_skip_plugin_css'])
|
|
24 |
tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/flash/css/content.css");
|
|
25 |
},
|
|
26 |
|
|
27 |
getControlHTML : function(cn) {
|
|
28 |
switch (cn) {
|
|
29 |
case "flash":
|
|
30 |
return tinyMCE.getButtonHTML(cn, 'lang_flash_desc', '{$pluginurl}/images/flash.gif', 'mceFlash');
|
|
31 |
}
|
|
32 |
|
|
33 |
return "";
|
|
34 |
},
|
|
35 |
|
|
36 |
execCommand : function(editor_id, element, command, user_interface, value) {
|
|
37 |
// Handle commands
|
|
38 |
switch (command) {
|
|
39 |
case "mceFlash":
|
|
40 |
var name = "", swffile = "", swfwidth = "", swfheight = "", action = "insert";
|
|
41 |
var template = new Array();
|
|
42 |
var inst = tinyMCE.getInstanceById(editor_id);
|
|
43 |
var focusElm = inst.getFocusElement();
|
|
44 |
|
|
45 |
template['file'] = '../../plugins/flash/flash.htm'; // Relative to theme
|
|
46 |
template['width'] = 430;
|
|
47 |
template['height'] = 175;
|
|
48 |
|
|
49 |
template['width'] += tinyMCE.getLang('lang_flash_delta_width', 0);
|
|
50 |
template['height'] += tinyMCE.getLang('lang_flash_delta_height', 0);
|
|
51 |
|
|
52 |
// Is selection a image
|
|
53 |
if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
|
|
54 |
name = tinyMCE.getAttrib(focusElm, 'class');
|
|
55 |
|
|
56 |
if (name.indexOf('mceItemFlash') == -1) // Not a Flash
|
|
57 |
return true;
|
|
58 |
|
|
59 |
// Get rest of Flash items
|
|
60 |
swffile = tinyMCE.getAttrib(focusElm, 'alt');
|
|
61 |
|
|
62 |
if (tinyMCE.getParam('convert_urls'))
|
|
63 |
swffile = eval(tinyMCE.settings['urlconverter_callback'] + "(swffile, null, true);");
|
|
64 |
|
|
65 |
swfwidth = tinyMCE.getAttrib(focusElm, 'width');
|
|
66 |
swfheight = tinyMCE.getAttrib(focusElm, 'height');
|
|
67 |
action = "update";
|
|
68 |
}
|
|
69 |
|
|
70 |
tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes", swffile : swffile, swfwidth : swfwidth, swfheight : swfheight, action : action});
|
|
71 |
return true;
|
|
72 |
}
|
|
73 |
|
|
74 |
// Pass to next handler in chain
|
|
75 |
return false;
|
|
76 |
},
|
|
77 |
|
|
78 |
cleanup : function(type, content) {
|
|
79 |
switch (type) {
|
|
80 |
case "insert_to_editor_dom":
|
|
81 |
// Force relative/absolute
|
|
82 |
if (tinyMCE.getParam('convert_urls')) {
|
|
83 |
var imgs = content.getElementsByTagName("img");
|
|
84 |
for (var i=0; i<imgs.length; i++) {
|
|
85 |
if (tinyMCE.getAttrib(imgs[i], "class") == "mceItemFlash") {
|
|
86 |
var src = tinyMCE.getAttrib(imgs[i], "alt");
|
|
87 |
|
|
88 |
if (tinyMCE.getParam('convert_urls'))
|
|
89 |
src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
|
|
90 |
|
|
91 |
imgs[i].setAttribute('alt', src);
|
|
92 |
imgs[i].setAttribute('title', src);
|
|
93 |
}
|
|
94 |
}
|
|
95 |
}
|
|
96 |
break;
|
|
97 |
|
|
98 |
case "get_from_editor_dom":
|
|
99 |
var imgs = content.getElementsByTagName("img");
|
|
100 |
for (var i=0; i<imgs.length; i++) {
|
|
101 |
if (tinyMCE.getAttrib(imgs[i], "class") == "mceItemFlash") {
|
|
102 |
var src = tinyMCE.getAttrib(imgs[i], "alt");
|
|
103 |
|
|
104 |
if (tinyMCE.getParam('convert_urls'))
|
|
105 |
src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
|
|
106 |
|
|
107 |
imgs[i].setAttribute('alt', src);
|
|
108 |
imgs[i].setAttribute('title', src);
|
|
109 |
}
|
|
110 |
}
|
|
111 |
break;
|
|
112 |
|
|
113 |
case "insert_to_editor":
|
|
114 |
var startPos = 0;
|
|
115 |
var embedList = new Array();
|
|
116 |
|
|
117 |
// Fix the embed and object elements
|
|
118 |
content = content.replace(new RegExp('<[ ]*embed','gi'),'<embed');
|
|
119 |
content = content.replace(new RegExp('<[ ]*/embed[ ]*>','gi'),'</embed>');
|
|
120 |
content = content.replace(new RegExp('<[ ]*object','gi'),'<object');
|
|
121 |
content = content.replace(new RegExp('<[ ]*/object[ ]*>','gi'),'</object>');
|
|
122 |
|
|
123 |
// Parse all embed tags
|
|
124 |
while ((startPos = content.indexOf('<embed', startPos+1)) != -1) {
|
|
125 |
var endPos = content.indexOf('>', startPos);
|
|
126 |
var attribs = TinyMCE_FlashPlugin._parseAttributes(content.substring(startPos + 6, endPos));
|
|
127 |
embedList[embedList.length] = attribs;
|
|
128 |
}
|
|
129 |
|
|
130 |
// Parse all object tags and replace them with images from the embed data
|
|
131 |
var index = 0;
|
|
132 |
while ((startPos = content.indexOf('<object', startPos)) != -1) {
|
|
133 |
if (index >= embedList.length)
|
|
134 |
break;
|
|
135 |
|
|
136 |
var attribs = embedList[index];
|
|
137 |
|
|
138 |
// Find end of object
|
|
139 |
endPos = content.indexOf('</object>', startPos);
|
|
140 |
endPos += 9;
|
|
141 |
|
|
142 |
// Insert image
|
|
143 |
var contentAfter = content.substring(endPos);
|
|
144 |
content = content.substring(0, startPos);
|
|
145 |
content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
|
|
146 |
content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["src"] + '"';
|
|
147 |
content += ' alt="' + attribs["src"] + '" class="mceItemFlash" />' + content.substring(endPos);
|
|
148 |
content += contentAfter;
|
|
149 |
index++;
|
|
150 |
|
|
151 |
startPos++;
|
|
152 |
}
|
|
153 |
|
|
154 |
// Parse all embed tags and replace them with images from the embed data
|
|
155 |
var index = 0;
|
|
156 |
while ((startPos = content.indexOf('<embed', startPos)) != -1) {
|
|
157 |
if (index >= embedList.length)
|
|
158 |
break;
|
|
159 |
|
|
160 |
var attribs = embedList[index];
|
|
161 |
|
|
162 |
// Find end of embed
|
|
163 |
endPos = content.indexOf('>', startPos);
|
|
164 |
endPos += 9;
|
|
165 |
|
|
166 |
// Insert image
|
|
167 |
var contentAfter = content.substring(endPos);
|
|
168 |
content = content.substring(0, startPos);
|
|
169 |
content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
|
|
170 |
content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["src"] + '"';
|
|
171 |
content += ' alt="' + attribs["src"] + '" class="mceItemFlash" />' + content.substring(endPos);
|
|
172 |
content += contentAfter;
|
|
173 |
index++;
|
|
174 |
|
|
175 |
startPos++;
|
|
176 |
}
|
|
177 |
|
|
178 |
break;
|
|
179 |
|
|
180 |
case "get_from_editor":
|
|
181 |
// Parse all img tags and replace them with object+embed
|
|
182 |
var startPos = -1;
|
|
183 |
|
|
184 |
while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
|
|
185 |
var endPos = content.indexOf('/>', startPos);
|
|
186 |
var attribs = TinyMCE_FlashPlugin._parseAttributes(content.substring(startPos + 4, endPos));
|
|
187 |
|
|
188 |
// Is not flash, skip it
|
|
189 |
if (attribs['class'] != "mceItemFlash")
|
|
190 |
continue;
|
|
191 |
|
|
192 |
endPos += 2;
|
|
193 |
|
|
194 |
var embedHTML = '';
|
|
195 |
var wmode = tinyMCE.getParam("flash_wmode", "");
|
|
196 |
var quality = tinyMCE.getParam("flash_quality", "high");
|
|
197 |
var menu = tinyMCE.getParam("flash_menu", "false");
|
|
198 |
|
|
199 |
// Insert object + embed
|
|
200 |
embedHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
|
|
201 |
embedHTML += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"';
|
|
202 |
embedHTML += ' width="' + attribs["width"] + '" height="' + attribs["height"] + '">';
|
|
203 |
embedHTML += '<param name="movie" value="' + attribs["title"] + '" />';
|
|
204 |
embedHTML += '<param name="quality" value="' + quality + '" />';
|
|
205 |
embedHTML += '<param name="menu" value="' + menu + '" />';
|
|
206 |
embedHTML += '<param name="wmode" value="' + wmode + '" />';
|
|
207 |
embedHTML += '<embed src="' + attribs["title"] + '" wmode="' + wmode + '" quality="' + quality + '" menu="' + menu + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + attribs["width"] + '" height="' + attribs["height"] + '"></embed></object>';
|
|
208 |
|
|
209 |
// Insert embed/object chunk
|
|
210 |
chunkBefore = content.substring(0, startPos);
|
|
211 |
chunkAfter = content.substring(endPos);
|
|
212 |
content = chunkBefore + embedHTML + chunkAfter;
|
|
213 |
}
|
|
214 |
break;
|
|
215 |
}
|
|
216 |
|
|
217 |
// Pass through to next handler in chain
|
|
218 |
return content;
|
|
219 |
},
|
|
220 |
|
|
221 |
handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
|
|
222 |
if (node == null)
|
|
223 |
return;
|
|
224 |
|
|
225 |
do {
|
|
226 |
if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('mceItemFlash') == 0) {
|
|
227 |
tinyMCE.switchClass(editor_id + '_flash', 'mceButtonSelected');
|
|
228 |
return true;
|
|
229 |
}
|
|
230 |
} while ((node = node.parentNode));
|
|
231 |
|
|
232 |
tinyMCE.switchClass(editor_id + '_flash', 'mceButtonNormal');
|
|
233 |
|
|
234 |
return true;
|
|
235 |
},
|
|
236 |
|
|
237 |
// Private plugin internal functions
|
|
238 |
|
|
239 |
_parseAttributes : function(attribute_string) {
|
|
240 |
var attributeName = "";
|
|
241 |
var attributeValue = "";
|
|
242 |
var withInName;
|
|
243 |
var withInValue;
|
|
244 |
var attributes = new Array();
|
|
245 |
var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
|
|
246 |
|
|
247 |
if (attribute_string == null || attribute_string.length < 2)
|
|
248 |
return null;
|
|
249 |
|
|
250 |
withInName = withInValue = false;
|
|
251 |
|
|
252 |
for (var i=0; i<attribute_string.length; i++) {
|
|
253 |
var chr = attribute_string.charAt(i);
|
|
254 |
|
|
255 |
if ((chr == '"' || chr == "'") && !withInValue)
|
|
256 |
withInValue = true;
|
|
257 |
else if ((chr == '"' || chr == "'") && withInValue) {
|
|
258 |
withInValue = false;
|
|
259 |
|
|
260 |
var pos = attributeName.lastIndexOf(' ');
|
|
261 |
if (pos != -1)
|
|
262 |
attributeName = attributeName.substring(pos+1);
|
|
263 |
|
|
264 |
attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
|
|
265 |
|
|
266 |
attributeName = "";
|
|
267 |
attributeValue = "";
|
|
268 |
} else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
|
|
269 |
withInName = true;
|
|
270 |
|
|
271 |
if (chr == '=' && withInName)
|
|
272 |
withInName = false;
|
|
273 |
|
|
274 |
if (withInName)
|
|
275 |
attributeName += chr;
|
|
276 |
|
|
277 |
if (withInValue)
|
|
278 |
attributeValue += chr;
|
|
279 |
}
|
|
280 |
|
|
281 |
return attributes;
|
|
282 |
}
|
|
283 |
};
|
|
284 |
|
|
285 |
tinyMCE.addPlugin("flash", TinyMCE_FlashPlugin);
|