[ Index ] |
|
Code source de Seagull 0.6.1 |
1 /** 2 * $RCSfile: editor_plugin_src.js,v $ 3 * $Revision: 1.34 $ 4 * $Date: 2006/02/10 16:29:39 $ 5 * 6 * @author Moxiecode 7 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved. 8 */ 9 10 /* Import plugin specific language pack */ 11 tinyMCE.importPluginLanguagePack('flash', 'en,tr,de,sv,zh_cn,cs,fa,fr_ca,fr,pl,pt_br,nl,da,he,nb,hu,ru,ru_KOI8-R,ru_UTF-8,nn,es,cy,is,zh_tw,zh_tw_utf8,sk,pt_br'); 12 13 var TinyMCE_FlashPlugin = { 14 getInfo : function() { 15 return { 16 longname : 'Flash', 17 author : 'Moxiecode Systems', 18 authorurl : 'http://tinymce.moxiecode.com', 19 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_flash.html', 20 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion 21 }; 22 }, 23 24 initInstance : function(inst) { 25 if (!tinyMCE.settings['flash_skip_plugin_css']) 26 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/flash/css/content.css"); 27 }, 28 29 getControlHTML : function(cn) { 30 switch (cn) { 31 case "flash": 32 return tinyMCE.getButtonHTML(cn, 'lang_flash_desc', '{$pluginurl}/images/flash.gif', 'mceFlash'); 33 } 34 35 return ""; 36 }, 37 38 execCommand : function(editor_id, element, command, user_interface, value) { 39 // Handle commands 40 switch (command) { 41 case "mceFlash": 42 var name = "", swffile = "", swfwidth = "", swfheight = "", action = "insert"; 43 var template = new Array(); 44 var inst = tinyMCE.getInstanceById(editor_id); 45 var focusElm = inst.getFocusElement(); 46 47 template['file'] = '../../plugins/flash/flash.htm'; // Relative to theme 48 template['width'] = 430; 49 template['height'] = 175; 50 51 template['width'] += tinyMCE.getLang('lang_flash_delta_width', 0); 52 template['height'] += tinyMCE.getLang('lang_flash_delta_height', 0); 53 54 // Is selection a image 55 if (focusElm != null && focusElm.nodeName.toLowerCase() == "img") { 56 name = tinyMCE.getAttrib(focusElm, 'class'); 57 58 if (name.indexOf('mceItemFlash') == -1) // Not a Flash 59 return true; 60 61 // Get rest of Flash items 62 swffile = tinyMCE.getAttrib(focusElm, 'alt'); 63 64 if (tinyMCE.getParam('convert_urls')) 65 swffile = eval(tinyMCE.settings['urlconverter_callback'] + "(swffile, null, true);"); 66 67 swfwidth = tinyMCE.getAttrib(focusElm, 'width'); 68 swfheight = tinyMCE.getAttrib(focusElm, 'height'); 69 action = "update"; 70 } 71 72 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes", swffile : swffile, swfwidth : swfwidth, swfheight : swfheight, action : action}); 73 return true; 74 } 75 76 // Pass to next handler in chain 77 return false; 78 }, 79 80 cleanup : function(type, content) { 81 switch (type) { 82 case "insert_to_editor_dom": 83 // Force relative/absolute 84 if (tinyMCE.getParam('convert_urls')) { 85 var imgs = content.getElementsByTagName("img"); 86 for (var i=0; i<imgs.length; i++) { 87 if (tinyMCE.getAttrib(imgs[i], "class") == "mceItemFlash") { 88 var src = tinyMCE.getAttrib(imgs[i], "alt"); 89 90 if (tinyMCE.getParam('convert_urls')) 91 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);"); 92 93 imgs[i].setAttribute('alt', src); 94 imgs[i].setAttribute('title', src); 95 } 96 } 97 } 98 break; 99 100 case "get_from_editor_dom": 101 var imgs = content.getElementsByTagName("img"); 102 for (var i=0; i<imgs.length; i++) { 103 if (tinyMCE.getAttrib(imgs[i], "class") == "mceItemFlash") { 104 var src = tinyMCE.getAttrib(imgs[i], "alt"); 105 106 if (tinyMCE.getParam('convert_urls')) 107 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);"); 108 109 imgs[i].setAttribute('alt', src); 110 imgs[i].setAttribute('title', src); 111 } 112 } 113 break; 114 115 case "insert_to_editor": 116 var startPos = 0; 117 var embedList = new Array(); 118 119 // Fix the embed and object elements 120 content = content.replace(new RegExp('<[ ]*embed','gi'),'<embed'); 121 content = content.replace(new RegExp('<[ ]*/embed[ ]*>','gi'),'</embed>'); 122 content = content.replace(new RegExp('<[ ]*object','gi'),'<object'); 123 content = content.replace(new RegExp('<[ ]*/object[ ]*>','gi'),'</object>'); 124 125 // Parse all embed tags 126 while ((startPos = content.indexOf('<embed', startPos+1)) != -1) { 127 var endPos = content.indexOf('>', startPos); 128 var attribs = TinyMCE_FlashPlugin._parseAttributes(content.substring(startPos + 6, endPos)); 129 embedList[embedList.length] = attribs; 130 } 131 132 // Parse all object tags and replace them with images from the embed data 133 var index = 0; 134 while ((startPos = content.indexOf('<object', startPos)) != -1) { 135 if (index >= embedList.length) 136 break; 137 138 var attribs = embedList[index]; 139 140 // Find end of object 141 endPos = content.indexOf('</object>', startPos); 142 endPos += 9; 143 144 // Insert image 145 var contentAfter = content.substring(endPos); 146 content = content.substring(0, startPos); 147 content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"'; 148 content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["src"] + '"'; 149 content += ' alt="' + attribs["src"] + '" class="mceItemFlash" />' + content.substring(endPos); 150 content += contentAfter; 151 index++; 152 153 startPos++; 154 } 155 156 // Parse all embed tags and replace them with images from the embed data 157 var index = 0; 158 while ((startPos = content.indexOf('<embed', startPos)) != -1) { 159 if (index >= embedList.length) 160 break; 161 162 var attribs = embedList[index]; 163 164 // Find end of embed 165 endPos = content.indexOf('>', startPos); 166 endPos += 9; 167 168 // Insert image 169 var contentAfter = content.substring(endPos); 170 content = content.substring(0, startPos); 171 content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"'; 172 content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["src"] + '"'; 173 content += ' alt="' + attribs["src"] + '" class="mceItemFlash" />' + content.substring(endPos); 174 content += contentAfter; 175 index++; 176 177 startPos++; 178 } 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 186 while ((startPos = content.indexOf('<img', startPos+1)) != -1) { 187 var endPos = content.indexOf('/>', startPos); 188 var attribs = TinyMCE_FlashPlugin._parseAttributes(content.substring(startPos + 4, endPos)); 189 190 // Is not flash, skip it 191 if (attribs['class'] != "mceItemFlash") 192 continue; 193 194 endPos += 2; 195 196 var embedHTML = ''; 197 var wmode = tinyMCE.getParam("flash_wmode", ""); 198 var quality = tinyMCE.getParam("flash_quality", "high"); 199 var menu = tinyMCE.getParam("flash_menu", "false"); 200 201 // Insert object + embed 202 embedHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'; 203 embedHTML += ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"'; 204 embedHTML += ' width="' + attribs["width"] + '" height="' + attribs["height"] + '">'; 205 embedHTML += '<param name="movie" value="' + attribs["title"] + '" />'; 206 embedHTML += '<param name="quality" value="' + quality + '" />'; 207 embedHTML += '<param name="menu" value="' + menu + '" />'; 208 embedHTML += '<param name="wmode" value="' + wmode + '" />'; 209 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 211 // Insert embed/object chunk 212 chunkBefore = content.substring(0, startPos); 213 chunkAfter = content.substring(endPos); 214 content = chunkBefore + embedHTML + chunkAfter; 215 } 216 break; 217 } 218 219 // Pass through to next handler in chain 220 return content; 221 }, 222 223 handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) { 224 if (node == null) 225 return; 226 227 do { 228 if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('mceItemFlash') == 0) { 229 tinyMCE.switchClass(editor_id + '_flash', 'mceButtonSelected'); 230 return true; 231 } 232 } while ((node = node.parentNode)); 233 234 tinyMCE.switchClass(editor_id + '_flash', 'mceButtonNormal'); 235 236 return true; 237 }, 238 239 // Private plugin internal functions 240 241 _parseAttributes : function(attribute_string) { 242 var attributeName = ""; 243 var attributeValue = ""; 244 var withInName; 245 var withInValue; 246 var attributes = new Array(); 247 var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g'); 248 249 if (attribute_string == null || attribute_string.length < 2) 250 return null; 251 252 withInName = withInValue = false; 253 254 for (var i=0; i<attribute_string.length; i++) { 255 var chr = attribute_string.charAt(i); 256 257 if ((chr == '"' || chr == "'") && !withInValue) 258 withInValue = true; 259 else if ((chr == '"' || chr == "'") && withInValue) { 260 withInValue = false; 261 262 var pos = attributeName.lastIndexOf(' '); 263 if (pos != -1) 264 attributeName = attributeName.substring(pos+1); 265 266 attributes[attributeName.toLowerCase()] = attributeValue.substring(1); 267 268 attributeName = ""; 269 attributeValue = ""; 270 } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue) 271 withInName = true; 272 273 if (chr == '=' && withInName) 274 withInName = false; 275 276 if (withInName) 277 attributeName += chr; 278 279 if (withInValue) 280 attributeValue += chr; 281 } 282 283 return attributes; 284 } 285 }; 286 287 tinyMCE.addPlugin("flash", TinyMCE_FlashPlugin);
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 30 01:27:52 2007 | par Balluche grâce à PHPXref 0.7 |