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