home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / tinymce-advanced / mce / media / editor_plugin.js next >
Encoding:
Text File  |  2008-02-20  |  13.6 KB  |  438 lines

  1. /**
  2.  * $Id: editor_plugin_src.js 275 2007-05-01 15:35:08Z spocke $
  3.  *
  4.  * @author Moxiecode
  5.  * @copyright Copyright ⌐ 2004-2007, Moxiecode Systems AB, All rights reserved.
  6.  */
  7.  
  8. /* Import plugin specific language pack */
  9. tinyMCE.importPluginLanguagePack('media');
  10.  
  11. var TinyMCE_MediaPlugin = {
  12.     getInfo : function() {
  13.         return {
  14.             longname : 'Media',
  15.             author : 'Moxiecode Systems AB',
  16.             authorurl : 'http://tinymce.moxiecode.com',
  17.             infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/media',
  18.             version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
  19.         };
  20.     },
  21.  
  22.     initInstance : function(inst) {
  23.         // Warn if user has flash plugin and media plugin at the same time
  24.         if (inst.hasPlugin('flash') && !tinyMCE.flashWarn) {
  25.             alert('Flash plugin is deprecated and should not be used together with the media plugin.');
  26.             tinyMCE.flashWarn = true;
  27.         }
  28.  
  29.         if (!tinyMCE.settings['media_skip_plugin_css'])
  30.             tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/../../../wp-content/plugins/tinymce-advanced/mce/media/css/content.css");
  31.     },
  32.  
  33.     getControlHTML : function(cn) {
  34.         switch (cn) {
  35.             case "media":
  36.                 return tinyMCE.getButtonHTML(cn, 'lang_media_desc', '{$pluginurl}/images/media.gif', 'mceMedia');
  37.         }
  38.  
  39.         return "";
  40.     },
  41.  
  42.     execCommand : function(editor_id, element, command, user_interface, value) {
  43.         // Handle commands
  44.         switch (command) {
  45.             case "mceMedia":
  46.                 tinyMCE.openWindow({
  47.                         file : tinyMCE.baseURL + '/../../../wp-content/plugins/tinymce-advanced/mce/media/media.htm',
  48.                         width : 430 + tinyMCE.getLang('lang_media_delta_width', 0),
  49.                         height : 470 + tinyMCE.getLang('lang_media_delta_height', 0)
  50.                     }, {
  51.                         editor_id : editor_id,
  52.                         inline : "yes"
  53.                 });
  54.  
  55.                 return true;
  56.        }
  57.  
  58.        // Pass to next handler in chain
  59.        return false;
  60.     },
  61.  
  62.     cleanup : function(type, content, inst) {
  63.         var nl, img, i, ne, d, s, ci;
  64.  
  65.         switch (type) {
  66.             case "insert_to_editor":
  67.                 img = tinyMCE.getParam("theme_href") + '/images/spacer.gif';
  68.                 content = content.replace(/<script[^>]*>\s*write(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)\(\{([^\)]*)\}\);\s*<\/script>/gi, '<img class="mceItem$1" title="$2" src="' + img + '" />');
  69.                 content = content.replace(/<object([^>]*)>/gi, '<div class="mceItemObject" $1>');
  70.                 content = content.replace(/<embed([^>]*)>/gi, '<div class="mceItemObjectEmbed" $1>');
  71.                 content = content.replace(/<\/(object|embed)([^>]*)>/gi, '</div>');
  72.                 content = content.replace(/<param([^>]*)>/gi, '<div $1 class="mceItemParam"></div>');
  73.                 content = content.replace(new RegExp('\\/ class="mceItemParam"><\\/div>', 'gi'), 'class="mceItemParam"></div>');
  74.  
  75.                 break;
  76.                 
  77.             case "insert_to_editor_dom":
  78.                 d = inst.getDoc();
  79.                 nl = content.getElementsByTagName("img");
  80.                 for (i=0; i<nl.length; i++) {
  81.                     if (/mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(nl[i].className)) {
  82.                         nl[i].width = nl[i].title.replace(/.*width:[^0-9]?([0-9]+)%?.*/g, '$1');
  83.                         nl[i].height = nl[i].title.replace(/.*height:[^0-9]?([0-9]+)%?.*/g, '$1');
  84.                         //nl[i].align = nl[i].title.replace(/.*align:([a-z]+).*/gi, '$1');
  85.                     }
  86.                 }
  87.  
  88.                 nl = tinyMCE.selectElements(content, 'DIV', function (n) {return tinyMCE.hasCSSClass(n, 'mceItemObject');});
  89.                 for (i=0; i<nl.length; i++) {
  90.                     ci = tinyMCE.getAttrib(nl[i], "classid").toLowerCase().replace(/\s+/g, '');
  91.  
  92.                     switch (ci) {
  93.                         case 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000':
  94.                             nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemFlash', d, nl[i]), nl[i]);
  95.                             break;
  96.  
  97.                         case 'clsid:166b1bca-3f9c-11cf-8075-444553540000':
  98.                             nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemShockWave', d, nl[i]), nl[i]);
  99.                             break;
  100.  
  101.                         case 'clsid:6bf52a52-394a-11d3-b153-00c04f79faa6':
  102.                         case 'clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95':
  103.                         case 'clsid:05589fa1-c356-11ce-bf01-00aa0055595a':
  104.                             nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemWindowsMedia', d, nl[i]), nl[i]);
  105.                             break;
  106.  
  107.                         case 'clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b':
  108.                             nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemQuickTime', d, nl[i]), nl[i]);
  109.                             break;
  110.  
  111.                         case 'clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa':
  112.                             nl[i].parentNode.replaceChild(TinyMCE_MediaPlugin._createImg('mceItemRealMedia', d, nl[i]), nl[i]);
  113.                             break;
  114.                     }
  115.                 }
  116.                 
  117.                 // Handle embed (if any)
  118.                 nl = tinyMCE.selectNodes(content, function (n) {return n.className == 'mceItemObjectEmbed';});
  119.                 for (i=0; i<nl.length; i++) {
  120.                     switch (tinyMCE.getAttrib(nl[i], 'type')) {
  121.                         case 'application/x-shockwave-flash':
  122.                             TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemFlash');
  123.                             break;
  124.  
  125.                         case 'application/x-director':
  126.                             TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemShockWave');
  127.                             break;
  128.  
  129.                         case 'application/x-mplayer2':
  130.                             TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemWindowsMedia');
  131.                             break;
  132.  
  133.                         case 'video/quicktime':
  134.                             TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemQuickTime');
  135.                             break;
  136.  
  137.                         case 'audio/x-pn-realaudio-plugin':
  138.                             TinyMCE_MediaPlugin._createImgFromEmbed(nl[i], d, 'mceItemRealMedia');
  139.                             break;
  140.                     }
  141.                 }
  142.                 break;
  143.                 
  144.             case "get_from_editor":
  145.                 var startPos = -1, endPos, attribs, chunkBefore, chunkAfter, embedHTML, at, pl, cb, mt, ex;
  146.  
  147.                 while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
  148.                     endPos = content.indexOf('/>', startPos);
  149.                     attribs = TinyMCE_MediaPlugin._parseAttributes(content.substring(startPos + 4, endPos));
  150.  
  151.                     // Is not flash, skip it
  152.                     if (!/mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(attribs['class']))
  153.                         continue;
  154.  
  155.                     endPos += 2;
  156.  
  157.                     // Parse attributes
  158.                     at = attribs['title'];
  159.                     if (at) {
  160.                         at = at.replace(/&(#39|apos);/g, "'");
  161.                         at = at.replace(/&#quot;/g, '"');
  162.  
  163.                         try {
  164.                             pl = eval('x={' + at + '};');
  165.                         } catch (ex) {
  166.                             pl = {};
  167.                         }
  168.                     }
  169.  
  170.                     // Use object/embed
  171.                     if (!tinyMCE.getParam('media_use_script', false)) {
  172.                         switch (attribs['class']) {
  173.                             case 'mceItemFlash':
  174.                                 ci = 'd27cdb6e-ae6d-11cf-96b8-444553540000';
  175.                                 cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
  176.                                 mt = 'application/x-shockwave-flash';
  177.                                 break;
  178.  
  179.                             case 'mceItemShockWave':
  180.                                 ci = '166B1BCA-3F9C-11CF-8075-444553540000';
  181.                                 cb = 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0';
  182.                                 mt = 'application/x-director';
  183.                                 break;
  184.  
  185.                             case 'mceItemWindowsMedia':
  186.                                 ci = tinyMCE.getParam('media_wmp6_compatible') ? '05589FA1-C356-11CE-BF01-00AA0055595A' : '6BF52A52-394A-11D3-B153-00C04F79FAA6';
  187.                                 cb = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701';
  188.                                 mt = 'application/x-mplayer2';
  189.                                 break;
  190.  
  191.                             case 'mceItemQuickTime':
  192.                                 ci = '02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
  193.                                 cb = 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0';
  194.                                 mt = 'video/quicktime';
  195.                                 break;
  196.  
  197.                             case 'mceItemRealMedia':
  198.                                 ci = 'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA';
  199.                                 cb = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0';
  200.                                 mt = 'audio/x-pn-realaudio-plugin';
  201.                                 break;
  202.                         }
  203.  
  204.                         // Force absolute URL
  205.                         if (!tinyMCE.getParam("relative_urls"))
  206.                             pl.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], pl.src);
  207.  
  208.                         embedHTML = TinyMCE_MediaPlugin._getEmbed(ci, cb, mt, pl, attribs);
  209.                     } else {
  210.                         // Use script version
  211.                         switch (attribs['class']) {
  212.                             case 'mceItemFlash':
  213.                                 s = 'writeFlash';
  214.                                 break;
  215.  
  216.                             case 'mceItemShockWave':
  217.                                 s = 'writeShockWave';
  218.                                 break;
  219.  
  220.                             case 'mceItemWindowsMedia':
  221.                                 s = 'writeWindowsMedia';
  222.                                 break;
  223.  
  224.                             case 'mceItemQuickTime':
  225.                                 s = 'writeQuickTime';
  226.                                 break;
  227.  
  228.                             case 'mceItemRealMedia':
  229.                                 s = 'writeRealMedia';
  230.                                 break;
  231.                         }
  232.  
  233.                         if (attribs.width)
  234.                             at = at.replace(/width:[^0-9]?[0-9]+%?[^0-9]?/g, "width:'" + attribs.width + "'");
  235.  
  236.                         if (attribs.height)
  237.                             at = at.replace(/height:[^0-9]?[0-9]+%?[^0-9]?/g, "height:'" + attribs.height + "'");
  238.  
  239.                         // Force absolute URL
  240.                         if (!tinyMCE.getParam("relative_urls")) {
  241.                             pl.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], pl.src);
  242.                             at = at.replace(new RegExp("src:'[^']*'", "g"), "src:'" + pl.src + "'");
  243.                         }
  244.  
  245.                         embedHTML = '<script type="text/javascript">' + s + '({' + at + '});</script>';
  246.                     }
  247.  
  248.                     // Insert embed/object chunk
  249.                     chunkBefore = content.substring(0, startPos);
  250.                     chunkAfter = content.substring(endPos);
  251.                     content = chunkBefore + embedHTML + chunkAfter;
  252.                 }
  253.                 break;
  254.         }
  255.  
  256.         return content;
  257.     },
  258.  
  259.     handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
  260.         if (node == null)
  261.             return;
  262.  
  263.         do {
  264.             if (node.nodeName == "IMG" && /mceItem(Flash|ShockWave|WindowsMedia|QuickTime|RealMedia)/.test(tinyMCE.getAttrib(node, 'class'))) {
  265.                 tinyMCE.switchClass(editor_id + '_media', 'mceButtonSelected');
  266.                 return true;
  267.             }
  268.         } while ((node = node.parentNode));
  269.  
  270.         tinyMCE.switchClass(editor_id + '_media', 'mceButtonNormal');
  271.  
  272.         return true;
  273.     },
  274.  
  275.     _createImgFromEmbed : function(n, d, cl) {
  276.         var ne, at, i, ti = '', an;
  277.  
  278.         ne = d.createElement('img');
  279.         ne.src = tinyMCE.getParam("theme_href") + '/images/spacer.gif';
  280.         ne.width = tinyMCE.getAttrib(n, 'width');
  281.         ne.height = tinyMCE.getAttrib(n, 'height');
  282.         ne.className = cl;
  283.  
  284.         at = n.attributes;
  285.         for (i=0; i<at.length; i++) {
  286.             if (at[i].specified && at[i].nodeValue) {
  287.                 an = at[i].nodeName.toLowerCase();
  288.  
  289.                 if (an == 'src')
  290.                     continue;
  291.  
  292.                 if (an == 'mce_src')
  293.                     an = 'src';
  294.  
  295.                 if (an.indexOf('mce_') == -1 && !new RegExp('^(class|type)$').test(an))
  296.                     ti += an.toLowerCase() + ':\'' + at[i].nodeValue + "',";
  297.             }
  298.         }
  299.  
  300.         ti = ti.length > 0 ? ti.substring(0, ti.length - 1) : ti;
  301.         ne.title = ti;
  302.  
  303.         n.parentNode.replaceChild(ne, n);
  304.     },
  305.  
  306.     _createImg : function(cl, d, n) {
  307.         var i, nl, ti = "", an, av, al = new Array();
  308.  
  309.         ne = d.createElement('img');
  310.         ne.src = tinyMCE.getParam("theme_href") + '/images/spacer.gif';
  311.         ne.width = tinyMCE.getAttrib(n, 'width');
  312.         ne.height = tinyMCE.getAttrib(n, 'height');
  313.         ne.className = cl;
  314.  
  315.         al.id = tinyMCE.getAttrib(n, 'id');
  316.         al.name = tinyMCE.getAttrib(n, 'name');
  317.         al.width = tinyMCE.getAttrib(n, 'width');
  318.         al.height = tinyMCE.getAttrib(n, 'height');
  319.         al.bgcolor = tinyMCE.getAttrib(n, 'bgcolor');
  320.         al.align = tinyMCE.getAttrib(n, 'align');
  321.         al.class_name = tinyMCE.getAttrib(n, 'mce_class');
  322.  
  323.         nl = n.getElementsByTagName('div');
  324.         for (i=0; i<nl.length; i++) {
  325.             av = tinyMCE.getAttrib(nl[i], 'value');
  326.             av = av.replace(new RegExp('\\\\', 'g'), '\\\\');
  327.             av = av.replace(new RegExp('"', 'g'), '\\"');
  328.             av = av.replace(new RegExp("'", 'g'), "\\'");
  329.             an = tinyMCE.getAttrib(nl[i], 'name');
  330.             al[an] = av;
  331.         }
  332.  
  333.         if (al.movie) {
  334.             al.src = al.movie;
  335.             al.movie = null;
  336.         }
  337.  
  338.         for (an in al) {
  339.             if (al[an] != null && typeof(al[an]) != "function" && al[an] != '')
  340.                 ti += an.toLowerCase() + ':\'' + al[an] + "',";
  341.         }
  342.  
  343.         ti = ti.length > 0 ? ti.substring(0, ti.length - 1) : ti;
  344.         ne.title = ti;
  345.  
  346.         return ne;
  347.     },
  348.  
  349.     _getEmbed : function(cls, cb, mt, p, at) {
  350.         var h = '', n;
  351.  
  352.         p.width = at.width ? at.width : p.width;
  353.         p.height = at.height ? at.height : p.height;
  354.  
  355.         h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
  356.         h += typeof(p.id) != "undefined" ? ' id="' + p.id + '"' : '';
  357.         h += typeof(p.name) != "undefined" ? ' name="' + p.name + '"' : '';
  358.         h += typeof(p.width) != "undefined" ? ' width="' + p.width + '"' : '';
  359.         h += typeof(p.height) != "undefined" ? ' height="' + p.height + '"' : '';
  360.         h += typeof(p.align) != "undefined" ? ' align="' + p.align + '"' : '';
  361.         h += '>';
  362.  
  363.         for (n in p) {
  364.             if (typeof(p[n]) != "undefined" && typeof(p[n]) != "function") {
  365.                 h += '<param name="' + n + '" value="' + p[n] + '" />';
  366.  
  367.                 // Add extra url parameter if it's an absolute URL on WMP
  368.                 if (n == 'src' && p[n].indexOf('://') != -1 && mt == 'application/x-mplayer2')
  369.                     h += '<param name="url" value="' + p[n] + '" />';
  370.             }
  371.         }
  372.  
  373.         h += '<embed type="' + mt + '"';
  374.  
  375.         for (n in p) {
  376.             if (typeof(p[n]) == "function")
  377.                 continue;
  378.  
  379.             // Skip url parameter for embed tag on WMP
  380.             if (!(n == 'url' && mt == 'application/x-mplayer2'))
  381.                 h += ' ' + n + '="' + p[n] + '"';
  382.         }
  383.  
  384.         h += '></embed></object><br /><br />';
  385. //        h += "\n\n";
  386.  
  387.         return h;
  388.     },
  389.  
  390.     _parseAttributes : function(attribute_string) {
  391.         var attributeName = "", endChr = '"';
  392.         var attributeValue = "";
  393.         var withInName;
  394.         var withInValue;
  395.         var attributes = new Array();
  396.         var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
  397.  
  398.         if (attribute_string == null || attribute_string.length < 2)
  399.             return null;
  400.  
  401.         withInName = withInValue = false;
  402.  
  403.         for (var i=0; i<attribute_string.length; i++) {
  404.             var chr = attribute_string.charAt(i);
  405.  
  406.             if ((chr == '"' || chr == "'") && !withInValue) {
  407.                 withInValue = true;
  408.                 endChr = chr;
  409.             } else if (chr == endChr && withInValue) {
  410.                 withInValue = false;
  411.  
  412.                 var pos = attributeName.lastIndexOf(' ');
  413.                 if (pos != -1)
  414.                     attributeName = attributeName.substring(pos+1);
  415.  
  416.                 attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
  417.  
  418.                 attributeName = "";
  419.                 attributeValue = "";
  420.             } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
  421.                 withInName = true;
  422.  
  423.             if (chr == '=' && withInName)
  424.                 withInName = false;
  425.  
  426.             if (withInName)
  427.                 attributeName += chr;
  428.  
  429.             if (withInValue)
  430.                 attributeValue += chr;
  431.         }
  432.  
  433.         return attributes;
  434.     }
  435. };
  436.  
  437. tinyMCE.addPlugin("media", TinyMCE_MediaPlugin);
  438.