[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/js/tinymce/plugins/insertvideo/ -> editor_plugin.js (source)

   1  /* Import plugin specific language pack */

   2  tinyMCE.importPluginLanguagePack('insertvideo', 'en,fr'); // <- Add a comma separated list of all supported languages

   3  
   4  // Singleton class

   5  var TinyMCE_insertvideoPlugin = {
   6      getInfo : function() {
   7          return {
   8              longname : 'insertvideo plugin',
   9              author : 'The LifeType Project',
  10              authorurl : 'http://www.lifetype.net',
  11              infourl : 'http://www.lifetype.net',
  12              version : "1.1"
  13          };
  14      },
  15  
  16      initInstance : function(inst) {
  17          tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/insertvideo/css/content.css");    
  18      },
  19  
  20      getControlHTML : function(cn) {
  21          switch (cn) {
  22              case "insertvideo":
  23                  return tinyMCE.getButtonHTML(cn, 'lang_insertvideo_desc', '{$pluginurl}/images/youtube.png', 'mceinsertvideo', true);
  24          }
  25  
  26          return "";
  27      },
  28  
  29      /**

  30       * Executes a specific command, this function handles plugin commands.

  31       *

  32       * @param {string} editor_id TinyMCE editor instance id that issued the command.

  33       * @param {HTMLElement} element Body or root element for the editor instance.

  34       * @param {string} command Command name to be executed.

  35       * @param {string} user_interface True/false if a user interface should be presented.

  36       * @param {mixed} value Custom value argument, can be anything.

  37       * @return true/false if the command was executed by this plugin or not.

  38       * @type

  39       */
  40      execCommand : function(editor_id, element, command, user_interface, value) {
  41          // Handle commands        

  42          switch (command) {
  43              // Remember to have the "mce" prefix for commands so they don't intersect with built in ones in the browser.

  44              case "mceinsertvideo":
  45                  // Show UI/Popup

  46                  if (user_interface) {
  47                      // Open a popup window and send in some custom data in a window argument

  48                      var insertvideo = new Array();
  49  
  50                      insertvideo['file'] = '../../plugins/insertvideo/videoinput.html'; // Relative to theme

  51                      insertvideo['width'] = 500;
  52                      insertvideo['height'] = 260;
  53  
  54                      tinyMCE.openWindow(insertvideo, {editor_id : editor_id, resizable : "no", scrollbars : "no", inline : "yes"});
  55                  }
  56                  return true;
  57          }
  58  
  59         // Pass to next handler in chain

  60         return false;
  61      },
  62  
  63      cleanup : function(type, content) {
  64          switch (type) {
  65              case "insert_to_editor_dom":
  66                  // Force relative/absolute

  67                  if (tinyMCE.getParam('convert_urls')) {
  68                      var imgs = content.getElementsByTagName("img");
  69                      for (var i=0; i<imgs.length; i++) {
  70                          //if (tinyMCE.getAttrib(imgs[i], "class")== "ltVideoYouTube") {

  71                          if (tinyMCE.getAttrib(imgs[i], "class").substr(0,6) == "ltVideo") {                            
  72                              var src = tinyMCE.getAttrib(imgs[i], "alt");
  73  
  74                              if (tinyMCE.getParam('convert_urls'))
  75                                  src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
  76  
  77                              imgs[i].setAttribute('alt', src);
  78                              imgs[i].setAttribute('title', src);
  79                          }
  80                      }
  81                  }
  82                  break;
  83  
  84              case "get_from_editor_dom":
  85                  var imgs = content.getElementsByTagName("img");
  86                  for (var i=0; i<imgs.length; i++) {
  87                      if (tinyMCE.getAttrib(imgs[i], "class").substr(0,6) == "ltVideo") {
  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                  break;
  98  
  99              case "insert_to_editor":
 100                  var startPos = 0;
 101                  var embedList = new Array();            
 102  
 103                  // Fix the embed and object elements

 104                  content = content.replace(new RegExp('<[ ]*object','gi'),'<object');
 105                  content = content.replace(new RegExp('<[ ]*/object[ ]*>','gi'),'</object>');            
 106                  
 107                  // Parse all object tags and replace them with images from the embed data

 108                  var index = 0;
 109                  while ((startPos = content.indexOf('<object', startPos)) != -1) {
 110  
 111                      // Find end of object

 112                      endPos = content.indexOf('</object>', startPos);
 113                      endPos += 9;
 114                      
 115                      objectTag = content.substring(startPos,endPos);
 116                      attribs = TinyMCE_insertvideoPlugin._parseAttributes( objectTag );
 117                      
 118                      var cssClass = "";                    
 119                      if( attribs["data"] == undefined ) {
 120                          startPos++;
 121                          continue;
 122                      }
 123                      else {
 124                          var videoType = getVideoType( attribs["data"] );
 125                          if( videoType == 1 ) {
 126                              cssClass = "ltVideoGoogleVideo";
 127                          }
 128                          else if( videoType == 2 ) {
 129                              cssClass = "ltVideoYouTube";
 130                          }
 131                          else if( videoType == 3 ) {
 132                              cssClass = "ltVideoMetacafe";
 133                          }
 134                          else if( videoType == 4 ) {
 135                              cssClass = "ltVideoIfilm";
 136                          }
 137                          else if( videoType == 5 ) {
 138                              cssClass = "ltVideoGoear";
 139                          }
 140                          else if( videoType == 6 ) {
 141                              cssClass = "ltVideoGrouper";
 142                          }
 143                          else if( videoType == 7 ) {
 144                              cssClass = "ltVideoDailymot";
 145                          }
 146                          else {
 147                              // ignore it, it's not a youtube or googlevideo video

 148                              startPos++;
 149                              continue;
 150                          }
 151                      }
 152                      
 153  
 154                      // Insert image

 155                      var contentAfter = content.substring(endPos);
 156                      content = content.substring(0, startPos);
 157                      content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
 158                      content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["data"] + '"';
 159                      content += ' alt="' + attribs["data"] + '" class="'+cssClass+'" />' + content.substring(endPos);
 160                      content += contentAfter;
 161                      index++;
 162  
 163                      startPos++;
 164                  }
 165                  
 166                  break;
 167  
 168              case "get_from_editor":
 169                  // Parse all img tags and replace them with object+embed

 170                  var startPos = -1;
 171  
 172                  while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
 173                      var endPos = content.indexOf('/>', startPos);
 174                      var attribs = TinyMCE_insertvideoPlugin._parseAttributes(content.substring(startPos + 4, endPos));
 175  
 176                      // Is not flash, skip it

 177                      if (attribs['class'] != "ltVideoYouTube" && attribs['class'] != "ltVideoGoogleVideo" && attribs['class'] != "ltVideoMetacafe" && attribs['class'] != "ltVideoIfilm" && attribs['class'] != "ltVideoGoear" && attribs['class'] != "ltVideoGrouper" && attribs['class'] != "ltVideoDailymot")
 178                          continue;
 179  
 180                      type = attribs['class'];
 181  
 182                      endPos += 2;
 183  
 184                      var embedHTML = '';
 185                      var wmode = tinyMCE.getParam("flash_wmode", "transparent");
 186                      var quality = tinyMCE.getParam("flash_quality", "high");
 187                      var menu = tinyMCE.getParam("flash_menu", "false");
 188                      
 189                      embedHTML = getVideoFlashHTML( attribs["title"], attribs["width"], attribs["height"] , type );
 190  
 191                      // Insert embed/object chunk

 192                      chunkBefore = content.substring(0, startPos);
 193                      chunkAfter = content.substring(endPos);
 194                      content = chunkBefore + embedHTML + chunkAfter;
 195                  }
 196                  break;
 197          }
 198  
 199          // Pass through to next handler in chain

 200          return content;
 201      },
 202  
 203      handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
 204          if (node == null)
 205              return;
 206  
 207          do {
 208              if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('ltVideo') == 0) {
 209                  tinyMCE.switchClass(editor_id + '_flash', 'mceButtonSelected');
 210                  return true;
 211              }
 212          } while ((node = node.parentNode));
 213  
 214          tinyMCE.switchClass(editor_id + '_flash', 'mceButtonNormal');
 215  
 216          return true;
 217      },
 218  
 219      // Private plugin internal functions

 220  
 221      _parseAttributes : function(attribute_string) {
 222          var attributeName = "";
 223          var attributeValue = "";
 224          var withInName;
 225          var withInValue;
 226          var attributes = new Array();
 227          var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
 228  
 229          if (attribute_string == null || attribute_string.length < 2)
 230              return null;
 231  
 232          withInName = withInValue = false;
 233  
 234          for (var i=0; i<attribute_string.length; i++) {
 235              var chr = attribute_string.charAt(i);
 236  
 237              if ((chr == '"' || chr == "'") && !withInValue)
 238                  withInValue = true;
 239              else if ((chr == '"' || chr == "'") && withInValue) {
 240                  withInValue = false;
 241  
 242                  var pos = attributeName.lastIndexOf(' ');
 243                  if (pos != -1)
 244                      attributeName = attributeName.substring(pos+1);
 245  
 246                  attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
 247  
 248                  attributeName = "";
 249                  attributeValue = "";
 250              } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
 251                  withInName = true;
 252  
 253              if (chr == '=' && withInName)
 254                  withInName = false;
 255  
 256              if (withInName)
 257                  attributeName += chr;
 258  
 259              if (withInValue)
 260                  attributeValue += chr;
 261          }
 262  
 263          return attributes;
 264      }
 265  };
 266  
 267  function getVideoFlashHTML( url, width, height , type )
 268  {
 269      html = "<object type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\" data=\""+url+"\" id=\""+type+"\">"+
 270          "<param name=\"movie\" value=\""+url+"\" />"+
 271          "<param name=\"wmode\" value=\"transparent\" />"+
 272          "<param name=\"allowScriptAcess\" value=\"sameDomain\" />"+
 273          "<param name=\"quality\" value=\"best\" />"+
 274          "<param name=\"bgcolor\" value=\"#FFFFFF\" />";
 275  //        "<param name=\"scale\" value=\"noScale\" />";

 276    if (type=='ltVideoGoear') {
 277          html= html + "<param name=\"FlashVars\" value=\""+url.substring( 43, url.length ) + "\" />";
 278      }    else {
 279         html = html + "<param name=\"FlashVars\" value=\"playerMode=embedded\" />";
 280      }
 281      
 282      html = html + "</object>";
 283      
 284      return( html );
 285  }
 286  
 287  function getVideoType( url )
 288  {
 289      /**

 290       * this method now uses regular expressions for more precise matching, please

 291       * remember to escape strings properly for their usage as regular expressions

 292       * when attempting to add new sites

 293       */
 294      var sites = {
 295          1: /^http:\/\/video\.google\.com\//,
 296          2: /^http:\/\/.{2,3}\.youtube\.com\//,
 297          3: /^http:\/\/www\.metacafe\.com\//,
 298          4: /^http:\/\/www\.ifilm\.com\//,
 299          5: /^http:\/\/www\.goear.com\//,
 300          6: /^http:\/\/www\.grouper\.com\//,
 301          7: /^http:\/\/www\.dailymotion\.com\//
 302      };
 303  
 304      var found = false;
 305      var siteId = 0;
 306      for( var id in sites ) {
 307          if( url.match( sites[id] )) {
 308              found = true;
 309              siteId = id;
 310              break;
 311          }
 312      }
 313      
 314      return( siteId );
 315  }
 316  
 317  tinyMCE.addPlugin("insertvideo", TinyMCE_insertvideoPlugin );


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics