[ Index ]
 

Code source de Seagull 0.6.1

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tinyfck/plugins/contextmenu/ -> editor_plugin_src.js (source)

   1  /**

   2   * $RCSfile: editor_plugin_src.js,v $

   3   * $Revision: 1.31 $

   4   * $Date: 2006/05/03 10:46:41 $

   5   *

   6   * @author Moxiecode

   7   * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.

   8   */
   9  
  10  /* Import plugin specific language pack */

  11  //tinyMCE.importPluginLanguagePack('contextmenu', 'en,tr,zh_cn,cs,fa,fr_ca,fr,de,nb');

  12  if (!tinyMCE.settings['contextmenu_skip_plugin_css']) {
  13      tinyMCE.loadCSS(tinyMCE.baseURL + "/plugins/contextmenu/css/contextmenu.css");
  14  }
  15  
  16  var TinyMCE_ContextMenuPlugin = {
  17      // Private fields

  18      _contextMenu : null,
  19  
  20      getInfo : function() {
  21          return {
  22              longname : 'Context menus',
  23              author : 'Moxiecode Systems',
  24              authorurl : 'http://tinymce.moxiecode.com',
  25              infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_contextmenu.html',
  26              version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
  27          };
  28      },
  29  
  30      initInstance : function(inst) {
  31          // Is not working on MSIE 5.0 or Opera no contextmenu event

  32          if (tinyMCE.isMSIE5_0 && tinyMCE.isOpera)
  33              return;
  34  
  35          TinyMCE_ContextMenuPlugin._contextMenu = new TinyMCE_ContextMenu({
  36              commandhandler : "TinyMCE_ContextMenuPlugin._commandHandler",
  37              spacer_image : tinyMCE.baseURL + "/plugins/contextmenu/images/spacer.gif"
  38          });
  39  
  40          // Add hide event handles

  41          tinyMCE.addEvent(inst.getDoc(), "click", TinyMCE_ContextMenuPlugin._hideContextMenu);
  42          tinyMCE.addEvent(inst.getDoc(), "keypress", TinyMCE_ContextMenuPlugin._hideContextMenu);
  43          tinyMCE.addEvent(inst.getDoc(), "keydown", TinyMCE_ContextMenuPlugin._hideContextMenu);
  44          tinyMCE.addEvent(document, "click", TinyMCE_ContextMenuPlugin._hideContextMenu);
  45          tinyMCE.addEvent(document, "keypress", TinyMCE_ContextMenuPlugin._hideContextMenu);
  46          tinyMCE.addEvent(document, "keydown", TinyMCE_ContextMenuPlugin._hideContextMenu);
  47  
  48          // Attach contextmenu event

  49          if (tinyMCE.isGecko) {
  50              tinyMCE.addEvent(inst.getDoc(), "contextmenu", function(e) {TinyMCE_ContextMenuPlugin._showContextMenu(tinyMCE.isMSIE ? inst.contentWindow.event : e, inst);});
  51          } else
  52              tinyMCE.addEvent(inst.getDoc(), "contextmenu", TinyMCE_ContextMenuPlugin._onContextMenu);
  53      },
  54  
  55      // Private plugin internal methods

  56  
  57      _onContextMenu : function(e) {
  58          var elm = tinyMCE.isMSIE ? e.srcElement : e.target;
  59          var targetInst, body;
  60  
  61          // Find instance

  62          if ((body = tinyMCE.getParentElement(elm, "body")) != null) {
  63              for (var n in tinyMCE.instances) {
  64                  var inst = tinyMCE.instances[n];
  65                  if (!tinyMCE.isInstance(inst))
  66                      continue;
  67  
  68                  if (body == inst.getBody()) {
  69                      targetInst = inst;
  70                      break;
  71                  }
  72              }
  73  
  74              return TinyMCE_ContextMenuPlugin._showContextMenu(tinyMCE.isMSIE ? targetInst.contentWindow.event : e, targetInst);
  75          }
  76      },
  77  
  78      _showContextMenu : function(e, inst) {
  79  		function getAttrib(elm, name) {
  80              return elm.getAttribute(name) ? elm.getAttribute(name) : "";
  81          }
  82  
  83          var x, y, elm, contextMenu;
  84          var pos = tinyMCE.getAbsPosition(inst.iframeElement);
  85  
  86          x = tinyMCE.isMSIE ? e.screenX : pos.absLeft + (e.pageX - inst.getBody().scrollLeft);
  87          y = tinyMCE.isMSIE ? e.screenY : pos.absTop + (e.pageY - inst.getBody().scrollTop);
  88          elm = tinyMCE.isMSIE ? e.srcElement : e.target;
  89  
  90          contextMenu = this._contextMenu;
  91          contextMenu.inst = inst;
  92  
  93          // Mozilla needs some time

  94          window.setTimeout(function () {
  95              var theme = tinyMCE.getParam("theme");
  96  
  97              contextMenu.clearAll();
  98              var sel = inst.selection.getSelectedText().length != 0 || elm.nodeName == "IMG";
  99  
 100              // Default items

 101              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_cut_desc", "Cut", "", !sel);
 102              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_copy_desc", "Copy", "", !sel);
 103              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_paste_desc", "Paste", "", false);
 104  
 105              if (sel || (elm ? (elm.nodeName == 'A') || (elm.nodeName == 'IMG') : false)) {
 106                  contextMenu.addSeparator();
 107                  contextMenu.addItem(tinyMCE.baseURL + "/themes/advanced/images/link.gif", "$lang_link_desc", inst.hasPlugin("advlink") ? "mceAdvLink" : "mceLink");
 108                  contextMenu.addItem(tinyMCE.baseURL + "/themes/advanced/images/unlink.gif", "$lang_unlink_desc", "unlink", "", (elm ? (elm.nodeName != 'A') && (elm.nodeName != 'IMG') : true));
 109              }
 110  
 111              // Get element

 112              elm = tinyMCE.getParentElement(elm, "img,table,td" + (inst.hasPlugin("advhr") ? ',hr' : ''));
 113              if (elm) {
 114                  switch (elm.nodeName) {
 115                      case "IMG":
 116                          contextMenu.addSeparator();
 117  
 118                          // If flash

 119                          if (tinyMCE.getAttrib(elm, 'class').indexOf('mceItemFlash') != -1)
 120                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/flash/images/flash.gif", "$lang_flash_props", "mceFlash");
 121                          else
 122                              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/image.gif", "$lang_image_props_desc", inst.hasPlugin("advimage") ? "mceAdvImage" : "mceImage");
 123                          break;
 124  
 125                      case "HR":
 126                          contextMenu.addSeparator();
 127                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/advhr/images/advhr.gif", "$lang_insert_advhr_desc", "mceAdvancedHr");
 128                          break;
 129  
 130                      case "TABLE":
 131                      case "TD":
 132                          // Is table plugin loaded

 133                          if (inst.hasPlugin("table")) {
 134                              var colspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "colspan");
 135                              var rowspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "rowspan");
 136  
 137                              colspan = colspan == "" ? "1" : colspan;
 138                              rowspan = rowspan == "" ? "1" : rowspan;
 139  
 140                              contextMenu.addSeparator();
 141                              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_table_cut_row_desc", "mceTableCutRow");
 142                              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_table_copy_row_desc", "mceTableCopyRow");
 143                              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_before_desc", "mceTablePasteRowBefore", "", inst.tableRowClipboard == null);
 144                              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_after_desc", "mceTablePasteRowAfter", "", inst.tableRowClipboard == null);
 145  
 146      /*                        contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyleft.gif", "$lang_justifyleft_desc", "JustifyLeft", "", false);

 147                              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifycenter.gif", "$lang_justifycenter_desc", "JustifyCenter", "", false);

 148                              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyright.gif", "$lang_justifyright_desc", "JustifyRight", "", false);

 149                              contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyfull.gif", "$lang_justifyfull_desc", "JustifyFull", "", false);*/
 150                              contextMenu.addSeparator();
 151                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_desc", "mceInsertTable", "insert");
 152                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_props_desc", "mceInsertTable");
 153                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_cell_props.gif", "$lang_table_cell_desc", "mceTableCellProps");
 154                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete.gif", "$lang_table_del", "mceTableDelete");
 155                              contextMenu.addSeparator();
 156                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_row_props.gif", "$lang_table_row_desc", "mceTableRowProps");
 157                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_before.gif", "$lang_table_row_before_desc", "mceTableInsertRowBefore");
 158                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_after.gif", "$lang_table_row_after_desc", "mceTableInsertRowAfter");
 159                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_row.gif", "$lang_table_delete_row_desc", "mceTableDeleteRow");
 160                              contextMenu.addSeparator();
 161                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_before.gif", "$lang_table_col_before_desc", "mceTableInsertColBefore");
 162                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_after.gif", "$lang_table_col_after_desc", "mceTableInsertColAfter");
 163                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_col.gif", "$lang_table_delete_col_desc", "mceTableDeleteCol");
 164                              contextMenu.addSeparator();
 165                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_split_cells.gif", "$lang_table_split_cells_desc", "mceTableSplitCells", "", (colspan == "1" && rowspan == "1"));
 166                              contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_merge_cells.gif", "$lang_table_merge_cells_desc", "mceTableMergeCells", "", false);
 167                          }
 168                          break;
 169                  }
 170              }  else {
 171                  // Add table specific

 172                  if (inst.hasPlugin("table")) {
 173                      contextMenu.addSeparator();
 174                      contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_desc", "mceInsertTable", "insert");
 175                  }
 176              }
 177  
 178              contextMenu.show(x, y);
 179          }, 10);
 180  
 181          // Cancel default handeling

 182          tinyMCE.cancelEvent(e);
 183          return false;
 184      },
 185  
 186      _hideContextMenu : function() {
 187          if (TinyMCE_ContextMenuPlugin._contextMenu)
 188              TinyMCE_ContextMenuPlugin._contextMenu.hide();
 189      },
 190  
 191      _commandHandler : function(command, value) {
 192          var cm = TinyMCE_ContextMenuPlugin._contextMenu;
 193  
 194          cm.hide();
 195  
 196          // UI must be true on these

 197          var ui = false;
 198          if (command == "mceInsertTable" || command == "mceTableCellProps" || command == "mceTableRowProps" || command == "mceTableMergeCells")
 199              ui = true;
 200  
 201          if (command == "Paste")
 202              value = null;
 203  
 204          if (tinyMCE.getParam("dialog_type") == "modal" && tinyMCE.isMSIE) {
 205              // Cell properties will generate access denied error is this isn't done?!

 206              window.setTimeout(function() {
 207                  cm.inst.execCommand(command, ui, value);
 208              }, 100);
 209          } else
 210              cm.inst.execCommand(command, ui, value);
 211      }
 212  };
 213  
 214  tinyMCE.addPlugin("contextmenu", TinyMCE_ContextMenuPlugin);
 215  
 216  // Context menu class

 217  
 218  function TinyMCE_ContextMenu(settings) {
 219      // Default value function

 220  	function defParam(key, def_val) {
 221          settings[key] = typeof(settings[key]) != "undefined" ? settings[key] : def_val;
 222      }
 223  
 224      var self = this;
 225  
 226      this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
 227  
 228      // Setup contextmenu div

 229      this.contextMenuDiv = document.createElement("div");
 230      this.contextMenuDiv.className = "contextMenu";
 231      this.contextMenuDiv.setAttribute("class", "contextMenu");
 232      this.contextMenuDiv.style.display = "none";
 233      this.contextMenuDiv.style.position = 'absolute';
 234      this.contextMenuDiv.style.zindex = 1000;
 235      this.contextMenuDiv.style.left = '0';
 236      this.contextMenuDiv.style.top = '0';
 237      this.contextMenuDiv.unselectable = "on";
 238  
 239      document.body.appendChild(this.contextMenuDiv);
 240  
 241      // Setup default values

 242      defParam("commandhandler", "");
 243      defParam("spacer_image", "images/spacer.gif");
 244  
 245      this.items = new Array();
 246      this.settings = settings;
 247      this.html = "";
 248  
 249      // IE Popup

 250      if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera) {
 251          this.pop = window.createPopup();
 252          doc = this.pop.document;
 253          doc.open();
 254          doc.write('<html><head><link href="' + tinyMCE.baseURL + '/plugins/contextmenu/css/contextmenu.css" rel="stylesheet" type="text/css" /></head><body unselectable="yes" class="contextMenuIEPopup"></body></html>');
 255          doc.close();
 256      }
 257  };
 258  
 259  TinyMCE_ContextMenu.prototype = {
 260      clearAll : function() {
 261          this.html = "";
 262          this.contextMenuDiv.innerHTML = "";
 263      },
 264  
 265      addSeparator : function() {
 266          this.html += '<tr class="contextMenuItem"><td class="contextMenuIcon"><img src="' + this.settings['spacer_image'] + '" width="20" height="1" class="contextMenuImage" /></td><td><img class="contextMenuSeparator" width="1" height="1" src="' + this.settings['spacer_image'] + '" /></td></tr>';
 267      },
 268  
 269      addItem : function(icon, title, command, value, disabled) {
 270          if (title.charAt(0) == '$')
 271              title = tinyMCE.getLang(title.substring(1));
 272  
 273          var onMouseDown = '';
 274          var html = '';
 275  
 276          if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0)
 277              onMouseDown = 'contextMenu.execCommand(\'' + command + '\', \'' + value + '\');return false;';
 278          else
 279              onMouseDown = this.settings['commandhandler'] + '(\'' + command + '\', \'' + value + '\');return false;';
 280  
 281          if (icon == "")
 282              icon = this.settings['spacer_image'];
 283  
 284          if (!disabled)
 285              html += '<tr class="contextMenuItem">';
 286          else
 287              html += '<tr class="contextMenuItemDisabled">';
 288  
 289          html += '<td class="contextMenuIcon"><img src="' + icon + '" width="20" height="20" class="contextMenuImage" /></td>';
 290          html += '<td><div class="contextMenuText">';
 291          html += '<a href="javascript:void(0);" onclick="' + onMouseDown + '" onmousedown="return false;">&#160;';
 292  
 293          // Add text

 294          html += title;
 295  
 296          html += '&#160;</a>';
 297          html += '</div></td>';
 298          html += '</tr>';
 299  
 300          // Add to main

 301          this.html += html;
 302      },
 303  
 304      show : function(x, y) {
 305          var vp, width, height;
 306  
 307          if (this.html == "")
 308              return;
 309  
 310          var html = '';
 311  
 312          html += '<a href="#"></a><table border="0" cellpadding="0" cellspacing="0">';
 313          html += this.html;
 314          html += '</table>';
 315  
 316          this.contextMenuDiv.innerHTML = html;
 317  
 318          // Get dimensions

 319          this.contextMenuDiv.style.display = "block";
 320          width = this.contextMenuDiv.offsetWidth;
 321          height = this.contextMenuDiv.offsetHeight;
 322          this.contextMenuDiv.style.display = "none";
 323  
 324          if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera) {
 325              // Setup popup and show

 326              this.pop.document.body.innerHTML = '<div class="contextMenu">' + html + "</div>";
 327              this.pop.document.tinyMCE = tinyMCE;
 328              this.pop.document.contextMenu = this;
 329              this.pop.show(x, y, width, height);
 330          } else {
 331              vp = this.getViewPort();
 332  
 333              this.contextMenuDiv.style.left = (x > vp.width - width ? vp.width - width : x) + 'px';
 334              this.contextMenuDiv.style.top = (y > vp.height - height ? vp.height - height : y) + 'px';
 335              this.contextMenuDiv.style.display = "block";
 336          }
 337      },
 338  
 339      getViewPort : function() {
 340          return {
 341              width : document.documentElement.offsetWidth || document.body.offsetWidth,
 342              height : self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
 343          };
 344      },
 345  
 346      hide : function() {
 347          if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera)
 348              this.pop.hide();
 349          else
 350              this.contextMenuDiv.style.display = "none";
 351      },
 352  
 353      execCommand : function(command, value) {
 354          eval(this.settings['commandhandler'] + "(command, value);");
 355      }
 356  };


Généré le : Fri Mar 30 01:27:52 2007 par Balluche grâce à PHPXref 0.7