1 /* Import plugin specific language pack */
2 tinyMCE.importPluginLanguagePack('flash', 'en,de,sv,zh_cn,cs,fa,fr_ca,fr,pl,pt_br,nl,da,he,no,hu');
4 function TinyMCE_flash_getInfo() {
7 author : 'Moxiecode Systems',
8 authorurl : 'http://tinymce.moxiecode.com',
9 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_flash.html',
10 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
14 function TinyMCE_flash_initInstance(inst) {
15 if (!tinyMCE.settings['flash_skip_plugin_css'])
16 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/flash/css/content.css");
19 function TinyMCE_flash_getControlHTML(control_name) {
20 switch (control_name) {
22 return '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceFlash\');" target="_self" onmousedown="return false;"><img id="{$editor_id}_flash" src="{$pluginurl}/images/flash.gif" title="{$lang_flash_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';
28 function TinyMCE_flash_parseAttributes(attribute_string) {
29 var attributeName = "";
30 var attributeValue = "";
33 var attributes = new Array();
34 var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
36 if (attribute_string == null || attribute_string.length < 2)
39 withInName = withInValue = false;
41 for (var i=0; i<attribute_string.length; i++) {
42 var chr = attribute_string.charAt(i);
44 if ((chr == '"' || chr == "'") && !withInValue)
46 else if ((chr == '"' || chr == "'") && withInValue) {
49 var pos = attributeName.lastIndexOf(' ');
51 attributeName = attributeName.substring(pos+1);
53 attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
57 } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
60 if (chr == '=' && withInName)
67 attributeValue += chr;
73 function TinyMCE_flash_execCommand(editor_id, element, command, user_interface, value) {
77 var name = "", swffile = "", swfwidth = "", swfheight = "", action = "insert";
78 var template = new Array();
79 var inst = tinyMCE.getInstanceById(editor_id);
80 var focusElm = inst.getFocusElement();
82 template['file'] = '../../plugins/flash/flash.htm'; // Relative to theme
83 template['width'] = 430;
84 template['height'] = 175;
86 template['width'] += tinyMCE.getLang('lang_flash_delta_width', 0);
87 template['height'] += tinyMCE.getLang('lang_flash_delta_height', 0);
89 // Is selection a image
90 if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
91 name = tinyMCE.getAttrib(focusElm, 'class');
93 if (name.indexOf('mceItemFlash') == -1) // Not a Flash
96 // Get rest of Flash items
97 swffile = tinyMCE.getAttrib(focusElm, 'alt');
98 swffile = eval(tinyMCE.settings['urlconverter_callback'] + "(swffile, null, true);");
99 swfwidth = tinyMCE.getAttrib(focusElm, 'width');
100 swfheight = tinyMCE.getAttrib(focusElm, 'height');
104 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes", swffile : swffile, swfwidth : swfwidth, swfheight : swfheight, action : action});
108 // Pass to next handler in chain
112 function TinyMCE_flash_cleanup(type, content) {
114 case "insert_to_editor_dom":
115 var imgs = content.getElementsByTagName("img");
116 for (var i=0; i<imgs.length; i++) {
117 if (tinyMCE.getAttrib(imgs[i], "class") == "mceItemFlash") {
118 var src = tinyMCE.getAttrib(imgs[i], "alt");
120 src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);
122 imgs[i].setAttribute('alt', src);
127 case "get_from_editor_dom":
128 var imgs = content.getElementsByTagName("img");
129 for (var i=0; i<imgs.length; i++) {
130 if (tinyMCE.getAttrib(imgs[i], "class") == "mceItemFlash") {
131 var src = tinyMCE.getAttrib(imgs[i], "alt");
133 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
135 imgs[i].setAttribute('alt', src);
140 case "insert_to_editor":
142 var embedList = new Array();
144 // Fix the embed and object elements
145 content = content.replace(new RegExp('<[ ]*embed','gi'),'<embed');
146 content = content.replace(new RegExp('<[ ]*/embed[ ]*>','gi'),'</embed>');
147 content = content.replace(new RegExp('<[ ]*object','gi'),'<object');
148 content = content.replace(new RegExp('<[ ]*/object[ ]*>','gi'),'</object>');
150 // Parse all embed tags
151 while ((startPos = content.indexOf('<embed', startPos+1)) != -1) {
152 var endPos = content.indexOf('>', startPos);
153 var attribs = TinyMCE_flash_parseAttributes(content.substring(startPos + 6, endPos));
154 embedList[embedList.length] = attribs;
157 // Parse all object tags and replace them with images from the embed data
159 while ((startPos = content.indexOf('<object', startPos)) != -1) {
160 if (index >= embedList.length)
163 var attribs = embedList[index];
165 // Find end of object
166 endPos = content.indexOf('</object>', startPos);
170 var contentAfter = content.substring(endPos);
171 content = content.substring(0, startPos);
172 content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
173 content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["src"] + '"';
174 content += ' alt="' + attribs["src"] + '" class="mceItemFlash" />' + content.substring(endPos);
175 content += contentAfter;
182 case "get_from_editor":
183 // Parse all img tags and replace them with object+embed
185 while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
186 var endPos = content.indexOf('/>', startPos);
187 var attribs = TinyMCE_flash_parseAttributes(content.substring(startPos + 4, endPos));
189 // Is not flash, skip it
190 if (attribs['class'] != "mceItemFlash")
196 var wmode = tinyMCE.getParam("flash_wmode", "");
197 var quality = tinyMCE.getParam("flash_quality", "high");
198 var menu = tinyMCE.getParam("flash_menu", "false");
200 // Insert object + embed
201 embedHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
202 embedHTML += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"';
203 embedHTML += ' width="' + attribs["width"] + '" height="' + attribs["height"] + '">';
204 embedHTML += '<param name="movie" value="' + attribs["title"] + '" />';
205 embedHTML += '<param name="quality" value="' + quality + '" />';
206 embedHTML += '<param name="menu" value="' + menu + '" />';
207 embedHTML += '<param name="wmode" value="' + wmode + '" />';
208 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>';
210 // Insert embed/object chunk
211 chunkBefore = content.substring(0, startPos);
212 chunkAfter = content.substring(endPos);
213 content = chunkBefore + embedHTML + chunkAfter;
218 // Pass through to next handler in chain
222 function TinyMCE_flash_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
223 tinyMCE.switchClassSticky(editor_id + '_flash', 'mceButtonNormal');
229 if (node.nodeName.toLowerCase() == "img" && tinyMCE.getAttrib(node, 'class').indexOf('mceItemFlash') == 0)
230 tinyMCE.switchClassSticky(editor_id + '_flash', 'mceButtonSelected');
231 } while ((node = node.parentNode));