2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
\r
5 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
\r
8 /* Import plugin specific language pack */
\r
9 tinyMCE.importPluginLanguagePack('flash');
\r
11 var TinyMCE_FlashPlugin = {
\r
12 getInfo : function() {
\r
15 author : 'Moxiecode Systems AB',
\r
16 authorurl : 'http://tinymce.moxiecode.com',
\r
17 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/flash',
\r
18 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
\r
22 initInstance : function(inst) {
\r
23 if (!tinyMCE.settings['flash_skip_plugin_css'])
\r
24 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/flash/css/content.css");
\r
27 getControlHTML : function(cn) {
\r
30 return tinyMCE.getButtonHTML(cn, 'lang_flash_desc', '{$pluginurl}/images/flash.gif', 'mceFlash');
\r
36 execCommand : function(editor_id, element, command, user_interface, value) {
\r
40 var name = "", swffile = "", swfwidth = "", swfheight = "", action = "insert";
\r
41 var template = new Array();
\r
42 var inst = tinyMCE.getInstanceById(editor_id);
\r
43 var focusElm = inst.getFocusElement();
\r
45 template['file'] = '../../plugins/flash/flash.htm'; // Relative to theme
\r
46 template['width'] = 430;
\r
47 template['height'] = 175;
\r
49 template['width'] += tinyMCE.getLang('lang_flash_delta_width', 0);
\r
50 template['height'] += tinyMCE.getLang('lang_flash_delta_height', 0);
\r
52 // Is selection a image
\r
53 if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
\r
54 name = tinyMCE.getAttrib(focusElm, 'class');
\r
56 if (name.indexOf('mceItemFlash') == -1) // Not a Flash
\r
59 // Get rest of Flash items
\r
60 swffile = tinyMCE.getAttrib(focusElm, 'alt');
\r
62 if (tinyMCE.getParam('convert_urls'))
\r
63 swffile = eval(tinyMCE.settings['urlconverter_callback'] + "(swffile, null, true);");
\r
65 swfwidth = tinyMCE.getAttrib(focusElm, 'width');
\r
66 swfheight = tinyMCE.getAttrib(focusElm, 'height');
\r
70 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes", swffile : swffile, swfwidth : swfwidth, swfheight : swfheight, action : action});
\r
74 // Pass to next handler in chain
\r
78 cleanup : function(type, content) {
\r
80 case "insert_to_editor_dom":
\r
81 // Force relative/absolute
\r
82 if (tinyMCE.getParam('convert_urls')) {
\r
83 var imgs = content.getElementsByTagName("img");
\r
84 for (var i=0; i<imgs.length; i++) {
\r
85 if (tinyMCE.getAttrib(imgs[i], "class") == "mceItemFlash") {
\r
86 var src = tinyMCE.getAttrib(imgs[i], "alt");
\r
88 if (tinyMCE.getParam('convert_urls'))
\r
89 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
\r
91 imgs[i].setAttribute('alt', src);
\r
92 imgs[i].setAttribute('title', src);
\r
98 case "get_from_editor_dom":
\r
99 var imgs = content.getElementsByTagName("img");
\r
100 for (var i=0; i<imgs.length; i++) {
\r
101 if (tinyMCE.getAttrib(imgs[i], "class") == "mceItemFlash") {
\r
102 var src = tinyMCE.getAttrib(imgs[i], "alt");
\r
104 if (tinyMCE.getParam('convert_urls'))
\r
105 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
\r
107 imgs[i].setAttribute('alt', src);
\r
108 imgs[i].setAttribute('title', src);
\r
113 case "insert_to_editor":
\r
115 var embedList = new Array();
\r
117 // Fix the embed and object elements
\r
118 content = content.replace(new RegExp('<[ ]*embed','gi'),'<embed');
\r
119 content = content.replace(new RegExp('<[ ]*/embed[ ]*>','gi'),'</embed>');
\r
120 content = content.replace(new RegExp('<[ ]*object','gi'),'<object');
\r
121 content = content.replace(new RegExp('<[ ]*/object[ ]*>','gi'),'</object>');
\r
123 // Parse all embed tags
\r
124 while ((startPos = content.indexOf('<embed', startPos+1)) != -1) {
\r
125 var endPos = content.indexOf('>', startPos);
\r
126 var attribs = TinyMCE_FlashPlugin._parseAttributes(content.substring(startPos + 6, endPos));
\r
127 embedList[embedList.length] = attribs;
\r
130 // Parse all object tags and replace them with images from the embed data
\r
132 while ((startPos = content.indexOf('<object', startPos)) != -1) {
\r
133 if (index >= embedList.length)
\r
136 var attribs = embedList[index];
\r
138 // Find end of object
\r
139 endPos = content.indexOf('</object>', startPos);
\r
143 var contentAfter = content.substring(endPos);
\r
144 content = content.substring(0, startPos);
\r
145 content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
\r
146 content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["src"] + '"';
\r
147 content += ' alt="' + attribs["src"] + '" class="mceItemFlash" />' + content.substring(endPos);
\r
148 content += contentAfter;
\r
154 // Parse all embed tags and replace them with images from the embed data
\r
156 while ((startPos = content.indexOf('<embed', startPos)) != -1) {
\r
157 if (index >= embedList.length)
\r
160 var attribs = embedList[index];
\r
162 // Find end of embed
\r
163 endPos = content.indexOf('>', startPos);
\r
167 var contentAfter = content.substring(endPos);
\r
168 content = content.substring(0, startPos);
\r
169 content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
\r
170 content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["src"] + '"';
\r
171 content += ' alt="' + attribs["src"] + '" class="mceItemFlash" />' + content.substring(endPos);
\r
172 content += contentAfter;
\r
180 case "get_from_editor":
\r
181 // Parse all img tags and replace them with object+embed
\r
184 while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
\r
185 var endPos = content.indexOf('/>', startPos);
\r
186 var attribs = TinyMCE_FlashPlugin._parseAttributes(content.substring(startPos + 4, endPos));
\r
188 // Is not flash, skip it
\r
189 if (attribs['class'] != "mceItemFlash")
\r
194 var embedHTML = '';
\r
195 var wmode = tinyMCE.getParam("flash_wmode", "");
\r
196 var quality = tinyMCE.getParam("flash_quality", "high");
\r
197 var menu = tinyMCE.getParam("flash_menu", "false");
\r
199 // Insert object + embed
\r
200 embedHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
\r
201 embedHTML += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"';
\r
202 embedHTML += ' width="' + attribs["width"] + '" height="' + attribs["height"] + '">';
\r
203 embedHTML += '<param name="movie" value="' + attribs["title"] + '" />';
\r
204 embedHTML += '<param name="quality" value="' + quality + '" />';
\r
205 embedHTML += '<param name="menu" value="' + menu + '" />';
\r
206 embedHTML += '<param name="wmode" value="' + wmode + '" />';
\r
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>';
\r
209 // Insert embed/object chunk
\r
210 chunkBefore = content.substring(0, startPos);
\r
211 chunkAfter = content.substring(endPos);
\r
212 content = chunkBefore + embedHTML + chunkAfter;
\r
217 // Pass through to next handler in chain
\r
221 handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
\r
226 if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('mceItemFlash') == 0) {
\r
227 tinyMCE.switchClass(editor_id + '_flash', 'mceButtonSelected');
\r
230 } while ((node = node.parentNode));
\r
232 tinyMCE.switchClass(editor_id + '_flash', 'mceButtonNormal');
\r
237 // Private plugin internal functions
\r
239 _parseAttributes : function(attribute_string) {
\r
240 var attributeName = "";
\r
241 var attributeValue = "";
\r
244 var attributes = new Array();
\r
245 var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
\r
247 if (attribute_string == null || attribute_string.length < 2)
\r
250 withInName = withInValue = false;
\r
252 for (var i=0; i<attribute_string.length; i++) {
\r
253 var chr = attribute_string.charAt(i);
\r
255 if ((chr == '"' || chr == "'") && !withInValue)
\r
256 withInValue = true;
\r
257 else if ((chr == '"' || chr == "'") && withInValue) {
\r
258 withInValue = false;
\r
260 var pos = attributeName.lastIndexOf(' ');
\r
262 attributeName = attributeName.substring(pos+1);
\r
264 attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
\r
266 attributeName = "";
\r
267 attributeValue = "";
\r
268 } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
\r
271 if (chr == '=' && withInName)
\r
272 withInName = false;
\r
275 attributeName += chr;
\r
278 attributeValue += chr;
\r
285 tinyMCE.addPlugin("flash", TinyMCE_FlashPlugin);
\r