[ Index ] |
|
Code source de LifeType 1.2.4 |
1 /** 2 * $RCSfile: editor_plugin_src.js,v $ 3 * $Revision: 1.12 $ 4 * $Date: 2006/02/22 20:06:23 $ 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('insertresource', 'en,tr,he,nb,ru,ru_KOI8-R,ru_UTF-8,nn,fi,cy,es,is,pl'); // <- Add a comma separated list of all supported languages 12 13 // Singleton class 14 var TinyMCE_insertresourcePlugin = { 15 getInfo : function() { 16 return { 17 longname : 'insertresource plugin', 18 author : 'Mark Wu', 19 authorurl : 'http://blog.markplace.net', 20 infourl : 'http://blog.markplace.net', 21 version : "1.0" 22 }; 23 }, 24 25 initInstance : function(inst) { 26 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/insertresource/css/content.css"); 27 }, 28 29 getControlHTML : function(cn) { 30 switch (cn) { 31 case "insertresource": 32 return tinyMCE.getButtonHTML(cn, 'lang_insertresource_desc', '{$pluginurl}/images/insertresource.gif', 'mceinsertresource', true); 33 } 34 35 return ""; 36 }, 37 38 /** 39 * Executes a specific command, this function handles plugin commands. 40 * 41 * @param {string} editor_id TinyMCE editor instance id that issued the command. 42 * @param {HTMLElement} element Body or root element for the editor instance. 43 * @param {string} command Command name to be executed. 44 * @param {string} user_interface True/false if a user interface should be presented. 45 * @param {mixed} value Custom value argument, can be anything. 46 * @return true/false if the command was executed by this plugin or not. 47 * @type 48 */ 49 execCommand : function(editor_id, element, command, user_interface, value) { 50 // Handle commands 51 switch (command) { 52 // Remember to have the "mce" prefix for commands so they don't intersect with built in ones in the browser. 53 case "mceinsertresource": 54 // Show UI/Popup 55 if (user_interface) { 56 // Open a popup window and send in some custom data in a window argument 57 var insertresource = new Array(); 58 59 insertresource['file'] = '../../../../admin.php?op=resourceList&mode=1'; // Relative to theme 60 insertresource['width'] = 500; 61 insertresource['height'] = 450; 62 63 tinyMCE.openWindow(insertresource, {editor_id : editor_id, resizable : "yes", scrollbars : "yes"}); 64 65 // Let TinyMCE know that something was modified 66 tinyMCE.triggerNodeChange(false); 67 } else { 68 // Do a command this gets called from the insertresource popup 69 alert("execCommand: mceinsertresource gets called from popup."); 70 } 71 72 return true; 73 } 74 75 // Pass to next handler in chain 76 return false; 77 }, 78 79 cleanup : function(type, content) { 80 switch (type) { 81 case "insert_to_editor_dom": 82 // Force relative/absolute 83 if (tinyMCE.getParam('convert_urls')) { 84 var imgs = content.getElementsByTagName("img"); 85 for (var i=0; i<imgs.length; i++) { 86 if (tinyMCE.getAttrib(imgs[i], "class") == "ltFlashPlayer") { 87 var src = tinyMCE.getAttrib(imgs[i], "alt"); 88 89 if (tinyMCE.getParam('convert_urls')) 90 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);"); 91 92 imgs[i].setAttribute('alt', src); 93 imgs[i].setAttribute('title', src); 94 } 95 } 96 } 97 break; 98 99 case "get_from_editor_dom": 100 var imgs = content.getElementsByTagName("img"); 101 for (var i=0; i<imgs.length; i++) { 102 if (tinyMCE.getAttrib(imgs[i], "class")== "ltFlashPlayer") { 103 var src = tinyMCE.getAttrib(imgs[i], "alt"); 104 105 if (tinyMCE.getParam('convert_urls')) 106 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);"); 107 108 imgs[i].setAttribute('alt', src); 109 imgs[i].setAttribute('title', src); 110 } 111 } 112 break; 113 114 case "insert_to_editor": 115 var startPos = 0; 116 var embedList = new Array(); 117 118 // Fix the embed and object elements 119 content = content.replace(new RegExp('<[ ]*object','gi'),'<object'); 120 content = content.replace(new RegExp('<[ ]*/object[ ]*>','gi'),'</object>'); 121 122 // Parse all object tags and replace them with images from the embed data 123 var index = 0; 124 while ((startPos = content.indexOf('<object', startPos)) != -1) { 125 126 // Find end of object 127 endPos = content.indexOf('</object>', startPos); 128 endPos += 9; 129 130 objectTag = content.substring(startPos,endPos); 131 132 /** 133 * NOTE: this method call relies in a bug of the _parseAttributes method. 134 * This method parses a tag and returns a list of its attributes. It works fine 135 * when presented with a single tag but now that we're passing a whole <object>...</object> 136 * block, it will also parse any other tags in the block. This means that it will return the 137 * value we're looking for as long as "FlashVars" is passed as the last parameter 138 * in the <object> block. 139 */ 140 attribs = TinyMCE_insertresourcePlugin._parseAttributes( objectTag ); 141 142 var cssClass = ""; 143 if( attribs["value"] == undefined || attribs["class"] != "ltPlayer" ) { 144 startPos++; 145 continue; 146 } 147 148 // find the value in "file=XXX" 149 var regexp = /.*file=([a-zA-Z0-9\-\/:._]*)/i; 150 result = regexp.exec( attribs["value"] ); 151 var fileUrl = ""; 152 if( result ) { 153 fileUrl = result[1]; 154 } 155 //window.alert("val = " + attribs["value"] + " - " + fileUrl); 156 157 // default values for height and width in case they were not defined (for some reason) 158 if( attribs["height"] == undefined ) 159 attribs["height"] = 20; 160 if( attribs["width"] == undefined ) 161 attribs["width"] = 320; 162 // Insert image 163 var contentAfter = content.substring(endPos); 164 content = content.substring(0, startPos); 165 content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"'; 166 content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + fileUrl + '"'; 167 content += ' alt="' + fileUrl + '" class="ltFlashPlayer" />' + content.substring(endPos); 168 content += contentAfter; 169 170 index++; 171 172 startPos++; 173 } 174 175 break; 176 177 case "get_from_editor": 178 // Parse all img tags and replace them with object+embed 179 var startPos = -1; 180 181 while ((startPos = content.indexOf('<img', startPos+1)) != -1) { 182 var endPos = content.indexOf('/>', startPos); 183 var attribs = TinyMCE_insertresourcePlugin._parseAttributes(content.substring(startPos + 4, endPos)); 184 185 // If not flash, skip it 186 if (attribs['class'] != "ltFlashPlayer" ) 187 continue; 188 189 type = attribs['class']; 190 191 endPos += 2; 192 193 var embedHTML = ''; 194 195 if( attribs["height"] == undefined ) 196 attribs["height"] = 20; 197 if( attribs["width"] == undefined ) 198 attribs["width"] = 320; 199 200 embedHTML = getFlashPlayerHTML( attribs["alt"], attribs["height"], attribs["width"] ); 201 202 // Insert embed/object chunk 203 chunkBefore = content.substring(0, startPos); 204 chunkAfter = content.substring(endPos); 205 content = chunkBefore + embedHTML + chunkAfter; 206 } 207 break; 208 } 209 210 // Pass through to next handler in chain 211 return content; 212 }, 213 214 // Private plugin internal functions 215 216 _parseAttributes : function(attribute_string) { 217 var attributeName = ""; 218 var attributeValue = ""; 219 var withInName; 220 var withInValue; 221 var attributes = new Array(); 222 var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g'); 223 224 if (attribute_string == null || attribute_string.length < 2) 225 return null; 226 227 withInName = withInValue = false; 228 229 for (var i=0; i<attribute_string.length; i++) { 230 var chr = attribute_string.charAt(i); 231 232 if ((chr == '"' ) && !withInValue) 233 withInValue = true; 234 else if ((chr == '"' ) && withInValue) { 235 withInValue = false; 236 237 var pos = attributeName.lastIndexOf(' '); 238 if (pos != -1) 239 attributeName = attributeName.substring(pos+1); 240 241 attributes[attributeName.toLowerCase()] = attributeValue.substring(1); 242 243 attributeName = ""; 244 attributeValue = ""; 245 } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue) 246 withInName = true; 247 248 if (chr == '=' && withInName) 249 withInName = false; 250 251 if (withInName) 252 attributeName += chr; 253 254 if (withInValue) 255 attributeValue += chr; 256 } 257 258 return attributes; 259 } 260 }; 261 262 tinyMCE.addPlugin("insertresource", TinyMCE_insertresourcePlugin);
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |