2 * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
5 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
8 /* Import plugin specific language pack */
9 tinyMCE
.importPluginLanguagePack('flash');
11 var TinyMCE_FlashPlugin
= {
12 getInfo : function() {
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
) {
30 return tinyMCE
.getButtonHTML(cn
, 'lang_flash_desc', '{$pluginurl}/images/flash.gif', 'mceFlash');
36 execCommand : function(editor_id
, element
, command
, user_interface
, value
) {
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
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');
70 tinyMCE
.openWindow(template
, {editor_id
: editor_id
, inline
: "yes", swffile
: swffile
, swfwidth
: swfwidth
, swfheight
: swfheight
, action
: action
});
74 // Pass to next handler in chain
78 cleanup : function(type
, content
) {
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
);
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
);
113 case "insert_to_editor":
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
132 while ((startPos
= content
.indexOf('<object', startPos
)) != -1) {
133 if (index
>= embedList
.length
)
136 var attribs
= embedList
[index
];
138 // Find end of object
139 endPos
= content
.indexOf('</object>', startPos
);
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
;
154 // Parse all embed tags and replace them with images from the embed data
156 while ((startPos
= content
.indexOf('<embed', startPos
)) != -1) {
157 if (index
>= embedList
.length
)
160 var attribs
= embedList
[index
];
163 endPos
= content
.indexOf('>', startPos
);
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
;
180 case "get_from_editor":
181 // Parse all img tags and replace them with object+embed
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")
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
;
217 // Pass through to next handler in chain
221 handleNodeChange : function(editor_id
, node
, undo_index
, undo_levels
, visual_aid
, any_selection
) {
226 if (node
.nodeName
== "IMG" && tinyMCE
.getAttrib(node
, 'class').indexOf('mceItemFlash') == 0) {
227 tinyMCE
.switchClass(editor_id
+ '_flash', 'mceButtonSelected');
230 } while ((node
= node
.parentNode
));
232 tinyMCE
.switchClass(editor_id
+ '_flash', 'mceButtonNormal');
237 // Private plugin internal functions
239 _parseAttributes : function(attribute_string
) {
240 var attributeName
= "";
241 var attributeValue
= "";
244 var attributes
= new Array();
245 var whiteSpaceRegExp
= new RegExp('^[ \n\r\t]+', 'g');
247 if (attribute_string
== null || attribute_string
.length
< 2)
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
)
257 else if ((chr
== '"' || chr
== "'") && withInValue
) {
260 var pos
= attributeName
.lastIndexOf(' ');
262 attributeName
= attributeName
.substring(pos
+1);
264 attributes
[attributeName
.toLowerCase()] = attributeValue
.substring(1);
268 } else if (!whiteSpaceRegExp
.test(chr
) && !withInName
&& !withInValue
)
271 if (chr
== '=' && withInName
)
275 attributeName
+= chr
;
278 attributeValue
+= chr
;
285 tinyMCE
.addPlugin("flash", TinyMCE_FlashPlugin
);