[ 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/insertaudio/ -> editor_plugin.js (source)

   1  /* Import plugin specific language pack */
   2  tinyMCE.importPluginLanguagePack('insertaudio', 'en,fr'); // <- Add a comma separated list of all supported languages
   3  
   4  // Singleton class
   5  var TinyMCE_insertaudioPlugin = {
   6      getInfo : function() {
   7          return {
   8              longname : 'insertaudio plugin',
   9              author : 'Gabriel ROUSSEAU',
  10              authorurl : 'http://grvg.free.fr',
  11              infourl : 'http://grvg.free.fr',
  12              version : "0.3"
  13          };
  14      },
  15  
  16      initInstance : function(inst) {
  17          tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/insertaudio/css/content.css");    
  18      },
  19  
  20      getControlHTML : function(cn) {
  21          switch (cn) {
  22              case "insertaudio":
  23                  return tinyMCE.getButtonHTML(cn, 'lang_insertaudio_desc', '{$pluginurl}/images/insertaudio.png', 'mceinsertaudio', 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 "mceinsertaudio":
  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 insertaudio = new Array();
  49  
  50                      insertaudio['file'] = '../../plugins/insertaudio/audioinput.html'; // Relative to theme
  51                      insertaudio['width'] = 500;
  52                      insertaudio['height'] = 120;
  53  
  54                      tinyMCE.openWindow(insertaudio, {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) == "ltFlashPlayer") {                            
  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) == "ltAudio") {
  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_insertaudioPlugin._parseAttributes( objectTag );
 117                      
 118                      var cssClass = "";                    
 119                      if( attribs["data"] == undefined )
 120                      {
 121                          startPos++;
 122                          continue;
 123                      } else {
 124                          cssClass = "ltPlayer";
 125                      }
 126                      
 127                      // Insert image
 128                      var contentAfter = content.substring(endPos);
 129                      content = content.substring(0, startPos);
 130                      content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
 131                      content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + attribs["data"] + '"';
 132                      content += ' alt="' + attribs["data"] + '" class="'+cssClass+'" />' + content.substring(endPos);
 133                      content += contentAfter;
 134                      index++;
 135  
 136                      startPos++;
 137                  }
 138                  
 139                  break;
 140  
 141              case "get_from_editor":
 142                  // Parse all img tags and replace them with object+embed
 143                  var startPos = -1;
 144  
 145                  while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
 146                      var endPos = content.indexOf('/>', startPos);
 147                      var attribs = TinyMCE_insertaudioPlugin._parseAttributes(content.substring(startPos + 4, endPos));
 148  
 149                      // Is not flash, skip it
 150                      if (attribs['class'] != "ltFlashPlayer")
 151                          continue;
 152  
 153                      type = attribs['class'];
 154  
 155                      endPos += 2;
 156  
 157                      var embedHTML = '';
 158                      
 159                      embedHTML = getAudioFlashHTML( attribs["title"] );
 160  
 161                      // Insert embed/object chunk
 162                      chunkBefore = content.substring(0, startPos);
 163                      chunkAfter = content.substring(endPos);
 164                      content = chunkBefore + embedHTML + chunkAfter;
 165                  }
 166                  break;
 167          }
 168  
 169          // Pass through to next handler in chain
 170          return content;
 171      },
 172  
 173      handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
 174          if (node == null)
 175              return;
 176  
 177          do {
 178              if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('ltFlashPlayer') == 0) {
 179                  tinyMCE.switchClass(editor_id + '_flash', 'mceButtonSelected');
 180                  return true;
 181              }
 182          } while ((node = node.parentNode));
 183  
 184          tinyMCE.switchClass(editor_id + '_flash', 'mceButtonNormal');
 185  
 186          return true;
 187      },
 188  
 189      // Private plugin internal functions
 190  
 191      _parseAttributes : function(attribute_string) {
 192          var attributeName = "";
 193          var attributeValue = "";
 194          var withInName;
 195          var withInValue;
 196          var attributes = new Array();
 197          var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
 198  
 199          if (attribute_string == null || attribute_string.length < 2)
 200              return null;
 201  
 202          withInName = withInValue = false;
 203  
 204          for (var i=0; i<attribute_string.length; i++) {
 205              var chr = attribute_string.charAt(i);
 206  
 207              if ((chr == '"' || chr == "'") && !withInValue)
 208                  withInValue = true;
 209              else if ((chr == '"' || chr == "'") && withInValue) {
 210                  withInValue = false;
 211  
 212                  var pos = attributeName.lastIndexOf(' ');
 213                  if (pos != -1)
 214                      attributeName = attributeName.substring(pos+1);
 215  
 216                  attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
 217  
 218                  attributeName = "";
 219                  attributeValue = "";
 220              } else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue)
 221                  withInName = true;
 222  
 223              if (chr == '=' && withInName)
 224                  withInName = false;
 225  
 226              if (withInName)
 227                  attributeName += chr;
 228  
 229              if (withInValue)
 230                  attributeValue += chr;
 231          }
 232  
 233          return attributes;
 234      }
 235  };
 236  
 237  function getAudioFlashHTML( url )
 238  {        
 239      var baseUrl = TinyMCE.baseURL.substring(0, TinyMCE.baseURL.indexOf("/js/tinymce",0));
 240      var playerUrl = baseUrl + "/flash/mp3player/mp3player.swf";
 241          
 242      var html =    '<object data="'+playerUrl+'" type="application/x-shockwave-flash" width="320" height="20" class="ltPlayer">'+
 243              '<param name="quality" value="best" />'+
 244              '<param name="bgcolor" value="#FFFFFF" />'+
 245              '<param name="movie" value="' + playerUrl + '" />' +
 246              '<param name="FlashVars" value="&amp;file='+url+'&amp;height=20&amp;width=320" />'+
 247              '</object>';
 248      
 249      return( html );
 250  }
 251  
 252  tinyMCE.addPlugin("insertaudio", TinyMCE_insertaudioPlugin );


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