]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/js/tiny_mce/plugins/media/editor_plugin_src.js
Imported Upstream version 0.1~rc2
[roundcube.git] / program / js / tiny_mce / plugins / media / editor_plugin_src.js
diff --git a/program/js/tiny_mce/plugins/media/editor_plugin_src.js b/program/js/tiny_mce/plugins/media/editor_plugin_src.js
new file mode 100644 (file)
index 0000000..4478ebb
--- /dev/null
@@ -0,0 +1,435 @@
+/**\r
+ * $Id: editor_plugin_src.js 275 2007-05-01 15:35:08Z spocke $\r
+ *\r
+ * @author Moxiecode\r
+ * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.\r
+ */\r
+\r
+/* Import plugin specific language pack */\r
+tinyMCE.importPluginLanguagePack('media');\r
+\r
+var TinyMCE_MediaPlugin = {\r
+       getInfo : function() {\r
+               return {\r
+                       longname : 'Media',\r
+                       author : 'Moxiecode Systems AB',\r
+                       authorurl : 'http://tinymce.moxiecode.com',\r
+                       infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',\r
+                       version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
+               };\r
+       },\r
+\r
+       initInstance : function(inst) {\r
+               // Warn if user has flash plugin and media plugin at the same time\r
+               if (inst.hasPlugin('flash') && !tinyMCE.flashWarn) {\r
+                       alert('Flash plugin is deprecated and should not be used together with the media plugin.');\r
+                       tinyMCE.flashWarn = true;\r
+               }\r
+\r
+               if (!tinyMCE.settings['media_skip_plugin_css'])\r
+                       tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/media/css/content.css");\r
+       },\r
+\r
+       getControlHTML : function(cn) {\r
+               switch (cn) {\r
+                       case "media":\r
+                               return tinyMCE.getButtonHTML(cn, 'lang_media_desc', '{$pluginurl}/images/media.gif', 'mceMedia');\r
+               }\r
+\r
+               return "";\r
+       },\r
+\r
+       execCommand : function(editor_id, element, command, user_interface, value) {\r
+               // Handle commands\r
+               switch (command) {\r
+                       case "mceMedia":\r
+                               tinyMCE.openWindow({\r
+                                               file : '../../plugins/media/media.htm',\r
+                                               width : 430 + tinyMCE.getLang('lang_media_delta_width', 0),\r
+                                               height : 470 + tinyMCE.getLang('lang_media_delta_height', 0)\r
+                                       }, {\r
+                                               editor_id : editor_id,\r
+                                               inline : "yes"\r
+                               });\r
+\r
+                               return true;\r
+          }\r
+\r
+          // Pass to next handler in chain\r
+          return false;\r
+       },\r
+\r
+       cleanup : function(type, content, inst) {\r
+               var nl, img, i, ne, d, s, ci;\r
+\r
+               switch (type) {\r
+                       case "insert_to_editor":\r
+                               img = tinyMCE.getParam("theme_href") + '/images/spacer.gif';\r
+                               content = content.replace(/<script[^>]*>\s*write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\(\{([^\)]*)\}\);\s*<\/script>/gi, '<img class="mceItem$1" title="$2" src="' + img + '" />');\r
+                               content = content.replace(/<object([^>]*)>/gi, '<div class="mceItemObject" $1>');\r
+                               content = content.replace(/<embed([^>]*)>/gi, '<div class="mceItemObjectEmbed" $1>');\r
+                               content = content.replace(/<\/(object|embed)([^>]*)>/gi, '</div>');\r
+                               content = content.replace(/<param([^>]*)>/gi, '<div $1 class="mceItemParam"></div>');\r
+                               content = content.replace(new RegExp('\\/ class="mceItemParam"><\\/div>', 'gi'), 'class="mceItemParam"></div>');\r
+                               break;\r
+\r
+                       case "insert_to_editor_dom":\r
+                               d = inst.getDoc();\r
+                               nl = content.getElementsByTagName("img");\r
+                               for (i=0; i<nl.length; i++) {\r
+                                       if (/mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(nl[i].className)) {\r
+                                               nl[i].width = nl[i].title.replace(/.*width:[^0-9]?([0-9]+)%?.*/g, '$1');\r
+                                               nl[i].height = nl[i].title.replace(/.*height:[^0-9]?([0-9]+)%?.*/g, '$1');\r
+                                               //nl[i].align = nl[i].title.replace(/.*align:([a-z]+).*/gi, '$1');\r
+                                       }\r
+                               }\r
+\r
+                               nl = tinyMCE.selectElements(content, 'DIV', function (n) {return tinyMCE.hasCSSClass(n, 'mceItemObject');});\r
+                               for (i=0; i<nl.length; i++) {\r
+                                       ci = tinyMCE.getAttrib(nl[i], "classid").toLowerCase().replace(/\s+/g, '');\r
+\r
+                                       switch (ci) {\r
+                                               case 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000':\r
+                                                       nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemFlash', d, nl[i]), nl[i]);\r
+                                                       break;\r
+\r
+                                               case 'clsid:166b1bca-3f9c-11cf-8075-444553540000':\r
+                                                       nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemShockWave', d, nl[i]), nl[i]);\r
+                                                       break;\r
+\r
+                                               case 'clsid:6bf52a52-394a-11d3-b153-00c04f79faa6':\r
+                                               case 'clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95':\r
+                                               case 'clsid:05589fa1-c356-11ce-bf01-00aa0055595a':\r
+                                                       nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemWindowsMedia', d, nl[i]), nl[i]);\r
+                                                       break;\r
+\r
+                                               case 'clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b':\r
+                                                       nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemQuickTime', d, nl[i]), nl[i]);\r
+                                                       break;\r
+\r
+                                               case 'clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa':\r
+                                                       nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemRealMedia', d, nl[i]), nl[i]);\r
+                                                       break;\r
+                                       }\r
+                               }\r
+\r
+                               // Handle embed (if any)\r
+                               nl = tinyMCE.selectNodes(content, function (n) {return n.className == 'mceItemObjectEmbed';});\r
+                               for (i=0; i<nl.length; i++) {\r
+                                       switch (tinyMCE.getAttrib(nl[i], 'type')) {\r
+                                               case 'application/x-shockwave-flash':\r
+                                                       TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemFlash');\r
+                                                       break;\r
+\r
+                                               case 'application/x-director':\r
+                                                       TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemShockWave');\r
+                                                       break;\r
+\r
+                                               case 'application/x-mplayer2':\r
+                                                       TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemWindowsMedia');\r
+                                                       break;\r
+\r
+                                               case 'video/quicktime':\r
+                                                       TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemQuickTime');\r
+                                                       break;\r
+\r
+                                               case 'audio/x-pn-realaudio-plugin':\r
+                                                       TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemRealMedia');\r
+                                                       break;\r
+                                       }\r
+                               }\r
+                               break;\r
+\r
+                       case "get_from_editor":\r
+                               var startPos = -1, endPos, attribs, chunkBefore, chunkAfter, embedHTML, at, pl, cb, mt, ex;\r
+\r
+                               while ((startPos = content.indexOf('<img', startPos+1)) != -1) {\r
+                                       endPos = content.indexOf('/>', startPos);\r
+                                       attribs = TinyMCE_MediaPlugin._parseAttributes(content.substring(startPos + 4, endPos));\r
+\r
+                                       // Is not flash, skip it\r
+                                       if (!/mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(attribs['class']))\r
+                                               continue;\r
+\r
+                                       endPos += 2;\r
+\r
+                                       // Parse attributes\r
+                                       at = attribs['title'];\r
+                                       if (at) {\r
+                                               at = at.replace(/&(#39|apos);/g, "'");\r
+                                               at = at.replace(/&#quot;/g, '"');\r
+\r
+                                               try {\r
+                                                       pl = eval('x={' + at + '};');\r
+                                               } catch (ex) {\r
+                                                       pl = {};\r
+                                               }\r
+                                       }\r
+\r
+                                       // Use object/embed\r
+                                       if (!tinyMCE.getParam('media_use_script', false)) {\r
+                                               switch (attribs['class']) {\r
+                                                       case 'mceItemFlash':\r
+                                                               ci = 'd27cdb6e-ae6d-11cf-96b8-444553540000';\r
+                                                               cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';\r
+                                                               mt = 'application/x-shockwave-flash';\r
+                                                               break;\r
+\r
+                                                       case 'mceItemShockWave':\r
+                                                               ci = '166B1BCA-3F9C-11CF-8075-444553540000';\r
+                                                               cb = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';\r
+                                                               mt = 'application/x-director';\r
+                                                               break;\r
+\r
+                                                       case 'mceItemWindowsMedia':\r
+                                                               ci = tinyMCE.getParam('media_wmp6_compatible') ? '05589FA1-C356-11CE-BF01-00AA0055595A' : '6BF52A52-394A-11D3-B153-00C04F79FAA6';\r
+                                                               cb = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';\r
+                                                               mt = 'application/x-mplayer2';\r
+                                                               break;\r
+\r
+                                                       case 'mceItemQuickTime':\r
+                                                               ci = '02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';\r
+                                                               cb = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';\r
+                                                               mt = 'video/quicktime';\r
+                                                               break;\r
+\r
+                                                       case 'mceItemRealMedia':\r
+                                                               ci = 'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA';\r
+                                                               cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';\r
+                                                               mt = 'audio/x-pn-realaudio-plugin';\r
+                                                               break;\r
+                                               }\r
+\r
+                                               // Force absolute URL\r
+                                               if (!tinyMCE.getParam("relative_urls"))\r
+                                                       pl.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], pl.src);\r
+\r
+                                               embedHTML = TinyMCE_MediaPlugin._getEmbed(ci, cb, mt, pl, attribs);\r
+                                       } else {\r
+                                               // Use script version\r
+                                               switch (attribs['class']) {\r
+                                                       case 'mceItemFlash':\r
+                                                               s = 'writeFlash';\r
+                                                               break;\r
+\r
+                                                       case 'mceItemShockWave':\r
+                                                               s = 'writeShockWave';\r
+                                                               break;\r
+\r
+                                                       case 'mceItemWindowsMedia':\r
+                                                               s = 'writeWindowsMedia';\r
+                                                               break;\r
+\r
+                                                       case 'mceItemQuickTime':\r
+                                                               s = 'writeQuickTime';\r
+                                                               break;\r
+\r
+                                                       case 'mceItemRealMedia':\r
+                                                               s = 'writeRealMedia';\r
+                                                               break;\r
+                                               }\r
+\r
+                                               if (attribs.width)\r
+                                                       at = at.replace(/width:[^0-9]?[0-9]+%?[^0-9]?/g, "width:'" + attribs.width + "'");\r
+\r
+                                               if (attribs.height)\r
+                                                       at = at.replace(/height:[^0-9]?[0-9]+%?[^0-9]?/g, "height:'" + attribs.height + "'");\r
+\r
+                                               // Force absolute URL\r
+                                               if (!tinyMCE.getParam("relative_urls")) {\r
+                                                       pl.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], pl.src);\r
+                                                       at = at.replace(new RegExp("src:'[^']*'", "g"), "src:'" + pl.src + "'");\r
+                                               }\r
+\r
+                                               embedHTML = '<script type="text/javascript">' + s + '({' + at + '});</script>';\r
+                                       }\r
+\r
+                                       // Insert embed/object chunk\r
+                                       chunkBefore = content.substring(0, startPos);\r
+                                       chunkAfter = content.substring(endPos);\r
+                                       content = chunkBefore + embedHTML + chunkAfter;\r
+                               }\r
+                               break;\r
+               }\r
+\r
+               return content;\r
+       },\r
+\r
+       handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {\r
+               if (node == null)\r
+                       return;\r
+\r
+               do {\r
+                       if (node.nodeName == "IMG" && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(tinyMCE.getAttrib(node, 'class'))) {\r
+                               tinyMCE.switchClass(editor_id + '_media', 'mceButtonSelected');\r
+                               return true;\r
+                       }\r
+               } while ((node = node.parentNode));\r
+\r
+               tinyMCE.switchClass(editor_id + '_media', 'mceButtonNormal');\r
+\r
+               return true;\r
+       },\r
+\r
+       _createImgFromEmbed : function(n, d, cl) {\r
+               var ne, at, i, ti = '', an;\r
+\r
+               ne = d.createElement('img');\r
+               ne.src = tinyMCE.getParam("theme_href") + '/images/spacer.gif';\r
+               ne.width = tinyMCE.getAttrib(n, 'width');\r
+               ne.height = tinyMCE.getAttrib(n, 'height');\r
+               ne.className = cl;\r
+\r
+               at = n.attributes;\r
+               for (i=0; i<at.length; i++) {\r
+                       if (at[i].specified && at[i].nodeValue) {\r
+                               an = at[i].nodeName.toLowerCase();\r
+\r
+                               if (an == 'src')\r
+                                       continue;\r
+\r
+                               if (an == 'mce_src')\r
+                                       an = 'src';\r
+\r
+                               if (an.indexOf('mce_') == -1 && !new RegExp('^(class|type)$').test(an))\r
+                                       ti += an.toLowerCase() + ':\'' + at[i].nodeValue + "',";\r
+                       }\r
+               }\r
+\r
+               ti = ti.length > 0 ? ti.substring(0, ti.length - 1) : ti;\r
+               ne.title = ti;\r
+\r
+               n.parentNode.replaceChild(ne, n);\r
+       },\r
+\r
+       _createImg : function(cl, d, n) {\r
+               var i, nl, ti = "", an, av, al = new Array();\r
+\r
+               ne = d.createElement('img');\r
+               ne.src = tinyMCE.getParam("theme_href") + '/images/spacer.gif';\r
+               ne.width = tinyMCE.getAttrib(n, 'width');\r
+               ne.height = tinyMCE.getAttrib(n, 'height');\r
+               ne.className = cl;\r
+\r
+               al.id = tinyMCE.getAttrib(n, 'id');\r
+               al.name = tinyMCE.getAttrib(n, 'name');\r
+               al.width = tinyMCE.getAttrib(n, 'width');\r
+               al.height = tinyMCE.getAttrib(n, 'height');\r
+               al.bgcolor = tinyMCE.getAttrib(n, 'bgcolor');\r
+               al.align = tinyMCE.getAttrib(n, 'align');\r
+               al.class_name = tinyMCE.getAttrib(n, 'mce_class');\r
+\r
+               nl = n.getElementsByTagName('div');\r
+               for (i=0; i<nl.length; i++) {\r
+                       av = tinyMCE.getAttrib(nl[i], 'value');\r
+                       av = av.replace(new RegExp('\\\\', 'g'), '\\\\');\r
+                       av = av.replace(new RegExp('"', 'g'), '\\"');\r
+                       av = av.replace(new RegExp("'", 'g'), "\\'");\r
+                       an = tinyMCE.getAttrib(nl[i], 'name');\r
+                       al[an] = av;\r
+               }\r
+\r
+               if (al.movie) {\r
+                       al.src = al.movie;\r
+                       al.movie = null;\r
+               }\r
+\r
+               for (an in al) {\r
+                       if (al[an] != null && typeof(al[an]) != "function" && al[an] != '')\r
+                               ti += an.toLowerCase() + ':\'' + al[an] + "',";\r
+               }\r
+\r
+               ti = ti.length > 0 ? ti.substring(0, ti.length - 1) : ti;\r
+               ne.title = ti;\r
+\r
+               return ne;\r
+       },\r
+\r
+       _getEmbed : function(cls, cb, mt, p, at) {\r
+               var h = '', n;\r
+\r
+               p.width = at.width ? at.width : p.width;\r
+               p.height = at.height ? at.height : p.height;\r
+\r
+               h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';\r
+               h += typeof(p.id) != "undefined" ? ' id="' + p.id + '"' : '';\r
+               h += typeof(p.name) != "undefined" ? ' name="' + p.name + '"' : '';\r
+               h += typeof(p.width) != "undefined" ? ' width="' + p.width + '"' : '';\r
+               h += typeof(p.height) != "undefined" ? ' height="' + p.height + '"' : '';\r
+               h += typeof(p.align) != "undefined" ? ' align="' + p.align + '"' : '';\r
+               h += '>';\r
+\r
+               for (n in p) {\r
+                       if (typeof(p[n]) != "undefined" && typeof(p[n]) != "function") {\r
+                               h += '<param name="' + n + '" value="' + p[n] + '" />';\r
+\r
+                               // Add extra url parameter if it's an absolute URL on WMP\r
+                               if (n == 'src' && p[n].indexOf('://') != -1 && mt == 'application/x-mplayer2')\r
+                                       h += '<param name="url" value="' + p[n] + '" />';\r
+                       }\r
+               }\r
+\r
+               h += '<embed type="' + mt + '"';\r
+\r
+               for (n in p) {\r
+                       if (typeof(p[n]) == "function")\r
+                               continue;\r
+\r
+                       // Skip url parameter for embed tag on WMP\r
+                       if (!(n == 'url' && mt == 'application/x-mplayer2'))\r
+                               h += ' ' + n + '="' + p[n] + '"';\r
+               }\r
+\r
+               h += '></embed></object>';\r
+\r
+               return h;\r
+       },\r
+\r
+       _parseAttributes : function(attribute_string) {\r
+               var attributeName = "", endChr = '"';\r
+               var attributeValue = "";\r
+               var withInName;\r
+               var withInValue;\r
+               var attributes = new Array();\r
+               var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');\r
+\r
+               if (attribute_string == null || attribute_string.length < 2)\r
+                       return null;\r
+\r
+               withInName = withInValue = false;\r
+\r
+               for (var i=0; i<attribute_string.length; i++) {\r
+                       var chr = attribute_string.charAt(i);\r
+\r
+                       if ((chr == '"' || chr == "'") && !withInValue) {\r
+                               withInValue = true;\r
+                               endChr = chr;\r
+                       } else if (chr == endChr && withInValue) {\r
+                               withInValue = false;\r
+\r
+                               var pos = attributeName.lastIndexOf(' ');\r
+                               if (pos != -1)\r
+                                       attributeName = attributeName.substring(pos+1);\r
+\r
+                               attributes[attributeName.toLowerCase()] = attributeValue.substring(1);\r
+\r
+                               attributeName = "";\r
+                               attributeValue = "";\r
+                       } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)\r
+                               withInName = true;\r
+\r
+                       if (chr == '=' && withInName)\r
+                               withInName = false;\r
+\r
+                       if (withInName)\r
+                               attributeName += chr;\r
+\r
+                       if (withInValue)\r
+                               attributeValue += chr;\r
+               }\r
+\r
+               return attributes;\r
+       }\r
+};\r
+\r
+tinyMCE.addPlugin("media", TinyMCE_MediaPlugin);\r