Test to see if log is updated automatically
[citadel.git] / webcit / tiny_mce / plugins / flash / editor_plugin_src.js
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');
3
4 function TinyMCE_flash_getInfo() {
5         return {
6                 longname : 'Flash',
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
11         };
12 };
13
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");
17 }
18
19 function TinyMCE_flash_getControlHTML(control_name) {
20     switch (control_name) {
21         case "flash":
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>';
23     }
24
25     return "";
26 }
27
28 function TinyMCE_flash_parseAttributes(attribute_string) {
29         var attributeName = "";
30         var attributeValue = "";
31         var withInName;
32         var withInValue;
33         var attributes = new Array();
34         var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
35
36         if (attribute_string == null || attribute_string.length < 2)
37                 return null;
38
39         withInName = withInValue = false;
40
41         for (var i=0; i<attribute_string.length; i++) {
42                 var chr = attribute_string.charAt(i);
43
44                 if ((chr == '"' || chr == "'") && !withInValue)
45                         withInValue = true;
46                 else if ((chr == '"' || chr == "'") && withInValue) {
47                         withInValue = false;
48
49                         var pos = attributeName.lastIndexOf(' ');
50                         if (pos != -1)
51                                 attributeName = attributeName.substring(pos+1);
52
53                         attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
54
55                         attributeName = "";
56                         attributeValue = "";
57                 } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
58                         withInName = true;
59
60                 if (chr == '=' && withInName)
61                         withInName = false;
62
63                 if (withInName)
64                         attributeName += chr;
65
66                 if (withInValue)
67                         attributeValue += chr;
68         }
69
70         return attributes;
71 }
72
73 function TinyMCE_flash_execCommand(editor_id, element, command, user_interface, value) {
74     // Handle commands
75     switch (command) {
76         case "mceFlash":
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();
81
82             template['file']   = '../../plugins/flash/flash.htm'; // Relative to theme
83             template['width']  = 430;
84             template['height'] = 175;
85
86                         template['width'] += tinyMCE.getLang('lang_flash_delta_width', 0);
87                         template['height'] += tinyMCE.getLang('lang_flash_delta_height', 0);
88
89                         // Is selection a image
90             if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") {
91                                 name = tinyMCE.getAttrib(focusElm, 'class');
92
93                                 if (name.indexOf('mceItemFlash') == -1) // Not a Flash
94                                         return true;
95
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');
101                                 action = "update";
102             }
103
104             tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes", swffile : swffile, swfwidth : swfwidth, swfheight : swfheight, action : action});
105                 return true;
106    }
107
108    // Pass to next handler in chain
109    return false;
110 }
111
112 function TinyMCE_flash_cleanup(type, content) {
113         switch (type) {
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");
119
120                                         src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);
121
122                                         imgs[i].setAttribute('alt', src);
123                                 }
124                         }
125                         break;
126
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");
132
133                                         src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
134
135                                         imgs[i].setAttribute('alt', src);
136                                 }
137                         }
138                         break;
139
140                 case "insert_to_editor":
141                         var startPos = 0;
142                         var embedList = new Array();
143
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>');
149
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;
155                         }
156
157                         // Parse all object tags and replace them with images from the embed data
158                         var index = 0;
159                         while ((startPos = content.indexOf('<object', startPos)) != -1) {
160                                 if (index >= embedList.length)
161                                         break;
162
163                                 var attribs = embedList[index];
164
165                                 // Find end of object
166                                 endPos = content.indexOf('</object>', startPos);
167                                 endPos += 9;
168
169                                 // Insert image
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;
176                                 index++;
177
178                                 startPos++;
179                         }
180                         break;
181
182                 case "get_from_editor":
183                         // Parse all img tags and replace them with object+embed
184                         var startPos = -1;
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));
188
189                                 // Is not flash, skip it
190                                 if (attribs['class'] != "mceItemFlash")
191                                         continue;
192
193                                 endPos += 2;
194
195                                 var embedHTML = '';
196                                 var wmode = tinyMCE.getParam("flash_wmode", "");
197                                 var quality = tinyMCE.getParam("flash_quality", "high");
198                                 var menu = tinyMCE.getParam("flash_menu", "false");
199
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>';
209
210                                 // Insert embed/object chunk
211                                 chunkBefore = content.substring(0, startPos);
212                                 chunkAfter = content.substring(endPos);
213                                 content = chunkBefore + embedHTML + chunkAfter;
214                         }
215                         break;
216         }
217
218         // Pass through to next handler in chain
219         return content;
220 }
221
222 function TinyMCE_flash_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
223         tinyMCE.switchClassSticky(editor_id + '_flash', 'mceButtonNormal');
224
225         if (node == null)
226                 return;
227
228         do {
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));
232
233         return true;
234 }