applied my changes - initial import
[boxroom-stian.git] / public / javascripts / tiny_mce / plugins / flash / editor_plugin_src.js
blobc98a0229683cd95953f5df6b1dea113c09d3bd08
1 /**
2 * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
4 * @author Moxiecode
5 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
6 */
8 /* Import plugin specific language pack */
9 tinyMCE.importPluginLanguagePack('flash');
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://tinymce.moxiecode.com/tinymce/docs/plugin_flash.html',
18 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
22 initInstance : function(inst) {
23 if (!tinyMCE.settings['flash_skip_plugin_css'])
24 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/flash/css/content.css");
27 getControlHTML : function(cn) {
28 switch (cn) {
29 case "flash":
30 return tinyMCE.getButtonHTML(cn, 'lang_flash_desc', '{$pluginurl}/images/flash.gif', 'mceFlash');
33 return "";
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();
45 template['file'] = '../../plugins/flash/flash.htm'; // Relative to theme
46 template['width'] = 430;
47 template['height'] = 175;
49 template['width'] += tinyMCE.getLang('lang_flash_delta_width', 0);
50 template['height'] += tinyMCE.getLang('lang_flash_delta_height', 0);
52 // Is selection a image
53 if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
54 name = tinyMCE.getAttrib(focusElm, 'class');
56 if (name.indexOf('mceItemFlash') == -1) // Not a Flash
57 return true;
59 // Get rest of Flash items
60 swffile = tinyMCE.getAttrib(focusElm, 'alt');
62 if (tinyMCE.getParam('convert_urls'))
63 swffile = eval(tinyMCE.settings['urlconverter_callback'] + "(swffile, null, true);");
65 swfwidth = tinyMCE.getAttrib(focusElm, 'width');
66 swfheight = tinyMCE.getAttrib(focusElm, 'height');
67 action = "update";
70 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes", swffile : swffile, swfwidth : swfwidth, swfheight : swfheight, action : action});
71 return true;
74 // Pass to next handler in chain
75 return false;
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");
88 if (tinyMCE.getParam('convert_urls'))
89 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
91 imgs[i].setAttribute('alt', src);
92 imgs[i].setAttribute('title', src);
96 break;
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");
104 if (tinyMCE.getParam('convert_urls'))
105 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
107 imgs[i].setAttribute('alt', src);
108 imgs[i].setAttribute('title', src);
111 break;
113 case "insert_to_editor":
114 var startPos = 0;
115 var embedList = new Array();
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>');
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;
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;
136 var attribs = embedList[index];
138 // Find end of object
139 endPos = content.indexOf('</object>', startPos);
140 endPos += 9;
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++;
151 startPos++;
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;
160 var attribs = embedList[index];
162 // Find end of embed
163 endPos = content.indexOf('>', startPos);
164 endPos += 9;
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++;
175 startPos++;
178 break;
180 case "get_from_editor":
181 // Parse all img tags and replace them with object+embed
182 var startPos = -1;
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));
188 // Is not flash, skip it
189 if (attribs['class'] != "mceItemFlash")
190 continue;
192 endPos += 2;
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");
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>';
209 // Insert embed/object chunk
210 chunkBefore = content.substring(0, startPos);
211 chunkAfter = content.substring(endPos);
212 content = chunkBefore + embedHTML + chunkAfter;
214 break;
217 // Pass through to next handler in chain
218 return content;
221 handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
222 if (node == null)
223 return;
225 do {
226 if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('mceItemFlash') == 0) {
227 tinyMCE.switchClass(editor_id + '_flash', 'mceButtonSelected');
228 return true;
230 } while ((node = node.parentNode));
232 tinyMCE.switchClass(editor_id + '_flash', 'mceButtonNormal');
234 return true;
237 // Private plugin internal functions
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');
247 if (attribute_string == null || attribute_string.length < 2)
248 return null;
250 withInName = withInValue = false;
252 for (var i=0; i<attribute_string.length; i++) {
253 var chr = attribute_string.charAt(i);
255 if ((chr == '"' || chr == "'") && !withInValue)
256 withInValue = true;
257 else if ((chr == '"' || chr == "'") && withInValue) {
258 withInValue = false;
260 var pos = attributeName.lastIndexOf(' ');
261 if (pos != -1)
262 attributeName = attributeName.substring(pos+1);
264 attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
266 attributeName = "";
267 attributeValue = "";
268 } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
269 withInName = true;
271 if (chr == '=' && withInName)
272 withInName = false;
274 if (withInName)
275 attributeName += chr;
277 if (withInValue)
278 attributeValue += chr;
281 return attributes;
285 tinyMCE.addPlugin("flash", TinyMCE_FlashPlugin);