[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/phpgwapi/js/tinymce/jscripts/tiny_mce/plugins/contextmenu/ -> editor_plugin_src.js (source)

   1  /* Import plugin specific language pack */
   2  //tinyMCE.importPluginLanguagePack('contextmenu', 'en,zh_cn,cs,fa,fr_ca,fr,de');
   3  if (!tinyMCE.settings['contextmenu_skip_plugin_css'])
   4      tinyMCE.loadCSS(tinyMCE.baseURL + "/plugins/contextmenu/contextmenu.css");
   5  
   6  // Global contextmenu class instance
   7  var TinyMCE_contextmenu_contextMenu = null;
   8  
   9  function TinyMCE_contextmenu_initInstance(inst) {
  10      // Is not working on MSIE 5.0
  11      if (tinyMCE.isMSIE5_0)
  12          return;
  13  
  14      // Add hide event handles
  15      tinyMCE.addEvent(inst.getDoc(), "click", TinyMCE_contextmenu_hideContextMenu);
  16      tinyMCE.addEvent(inst.getDoc(), "keypress", TinyMCE_contextmenu_hideContextMenu);
  17      tinyMCE.addEvent(inst.getDoc(), "keydown", TinyMCE_contextmenu_hideContextMenu);
  18      tinyMCE.addEvent(document, "click", TinyMCE_contextmenu_hideContextMenu);
  19      tinyMCE.addEvent(document, "keypress", TinyMCE_contextmenu_hideContextMenu);
  20      tinyMCE.addEvent(document, "keydown", TinyMCE_contextmenu_hideContextMenu);
  21  
  22      var contextMenu = new ContextMenu({
  23          commandhandler : "TinyMCE_contextmenu_commandHandler",
  24          spacer_image : tinyMCE.baseURL + "/plugins/contextmenu/images/spacer.gif"
  25      });
  26  
  27      // Register global reference
  28      TinyMCE_contextmenu_contextMenu = contextMenu;
  29  
  30      // Attach contextmenu event
  31      if (tinyMCE.isGecko) {
  32          tinyMCE.addEvent(inst.getDoc(), "contextmenu", function(e) {TinyMCE_contextmenu_showContextMenu(tinyMCE.isMSIE ? inst.contentWindow.event : e, inst);});
  33      } else
  34          tinyMCE.addEvent(inst.getDoc(), "contextmenu", TinyMCE_contextmenu_onContextMenu);
  35  }
  36  
  37  function TinyMCE_contextmenu_onContextMenu(e) {
  38      var elm = tinyMCE.isMSIE ? e.srcElement : e.target;
  39      var targetInst, body;
  40  
  41      // Find instance
  42      if ((body = tinyMCE.getParentElement(elm, "body")) != null) {
  43          for (var n in tinyMCE.instances) {
  44              var inst = tinyMCE.instances[n];
  45  
  46              if (body == inst.getBody()) {
  47                  targetInst = inst;
  48                  break;
  49              }
  50          }
  51  
  52          return TinyMCE_contextmenu_showContextMenu(tinyMCE.isMSIE ? targetInst.contentWindow.event : e, targetInst);
  53      }
  54  }
  55  
  56  function TinyMCE_contextmenu_showContextMenu(e, inst) {
  57  	function getAttrib(elm, name) {
  58          return elm.getAttribute(name) ? elm.getAttribute(name) : "";
  59      }
  60  
  61      var x, y, elm, contextMenu;
  62      var pos = tinyMCE.getAbsPosition(inst.iframeElement);
  63  
  64      x = tinyMCE.isMSIE ? e.screenX : pos.absLeft + (e.pageX - inst.getBody().scrollLeft);
  65      y = tinyMCE.isMSIE ? e.screenY : pos.absTop + (e.pageY - inst.getBody().scrollTop);
  66      elm = tinyMCE.isMSIE ? e.srcElement : e.target;
  67      contextMenu = TinyMCE_contextmenu_contextMenu;
  68      contextMenu.inst = inst;
  69  
  70      // Mozilla needs some time
  71      window.setTimeout(function () {
  72          var theme = tinyMCE.getParam("theme");
  73  
  74          contextMenu.clearAll();
  75          var sel = inst.getSelectedText().length != 0 || elm.nodeName == "IMG";
  76  
  77          // Default items
  78          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_cut_desc", "Cut", "", !sel);
  79          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_copy_desc", "Copy", "", !sel);
  80          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_paste_desc", "Paste", "", false);
  81  
  82          // Get element
  83          elm = tinyMCE.getParentElement(elm, "img,table,td");
  84          if (elm) {
  85              switch (elm.nodeName) {
  86                  case "IMG":
  87                      contextMenu.addSeparator();
  88  
  89                      // If flash
  90                      if (tinyMCE.getAttrib(elm, 'name', '').indexOf('mce_plugin_flash') == 0)
  91                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/flash/images/flash.gif", "$lang_flash_props", "mceFlash");
  92                      else
  93                          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/image.gif", "$lang_image_props_desc", "mceImage");
  94                      break;
  95  
  96                  case "TABLE":
  97                  case "TD":
  98                      // Is table plugin loaded
  99                      if (typeof(TinyMCE_table_getControlHTML) != "undefined") {
 100                          var colspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "colspan");
 101                          var rowspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "rowspan");
 102  
 103                          colspan = colspan == "" ? "1" : colspan;
 104                          rowspan = rowspan == "" ? "1" : rowspan;
 105  
 106                          contextMenu.addSeparator();
 107                          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_table_cut_row_desc", "mceTableCutRow");
 108                          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_table_copy_row_desc", "mceTableCopyRow");
 109                          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_before_desc", "mceTablePasteRowBefore", "", inst.tableRowClipboard == null);
 110                          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_after_desc", "mceTablePasteRowAfter", "", inst.tableRowClipboard == null);
 111  
 112  /*                        contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/left.gif", "$lang_justifyleft_desc", "JustifyLeft", "", false);
 113                          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/center.gif", "$lang_justifycenter_desc", "JustifyCenter", "", false);
 114                          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/right.gif", "$lang_justifyright_desc", "JustifyRight", "", false);
 115                          contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/full.gif", "$lang_justifyfull_desc", "JustifyFull", "", false);*/
 116                          contextMenu.addSeparator();
 117                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_props_desc", "mceInsertTable");
 118                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_cell_props.gif", "$lang_table_cell_desc", "mceTableCellProps");
 119                          contextMenu.addSeparator();
 120                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_row_props.gif", "$lang_table_row_desc", "mceTableRowProps");
 121                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_before.gif", "$lang_table_insert_row_before_desc", "mceTableInsertRowBefore");
 122                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_after.gif", "$lang_table_insert_row_after_desc", "mceTableInsertRowAfter");
 123                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_row.gif", "$lang_table_delete_row_desc", "mceTableDeleteRow");
 124                          contextMenu.addSeparator();
 125                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_before.gif", "$lang_table_insert_col_before_desc", "mceTableInsertColBefore");
 126                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_after.gif", "$lang_table_insert_col_after_desc", "mceTableInsertColAfter");
 127                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_col.gif", "$lang_table_delete_col_desc", "mceTableDeleteCol");
 128                          contextMenu.addSeparator();
 129                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_split_cells.gif", "$lang_table_split_cells_desc", "mceTableSplitCells", "", (colspan == "1" && rowspan == "1"));
 130                          contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_merge_cells.gif", "$lang_table_merge_cells_desc", "mceTableMergeCells", "", false);
 131                      }
 132                      break;
 133              }
 134          }
 135  
 136          contextMenu.show(x, y);
 137      }, 10);
 138  
 139      // Cancel default handeling
 140      tinyMCE.cancelEvent(e);
 141      return false;
 142  }
 143  
 144  function TinyMCE_contextmenu_hideContextMenu() {
 145      TinyMCE_contextmenu_contextMenu.hide();
 146  
 147      return true;
 148  }
 149  
 150  function TinyMCE_contextmenu_commandHandler(command, value) {
 151      TinyMCE_contextmenu_contextMenu.hide();
 152  
 153      // UI must be true on these
 154      var ui = false;
 155      if (command == "mceInsertTable" || command == "mceTableCellProps" || command == "mceTableRowProps" || command == "mceTableMergeCells")
 156          ui = true;
 157  
 158      TinyMCE_contextmenu_contextMenu.inst.execCommand(command, ui);
 159  }
 160  
 161  // Context menu class
 162  
 163  function ContextMenu(settings) {
 164      // Default value function
 165  	function defParam(key, def_val) {
 166          settings[key] = typeof(settings[key]) != "undefined" ? settings[key] : def_val;
 167      }
 168  
 169      var self = this;
 170  
 171      this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
 172  
 173      // Setup contextmenu div
 174      this.contextMenuDiv = document.createElement("div");
 175      this.contextMenuDiv.className = "contextMenu";
 176      this.contextMenuDiv.setAttribute("class", "contextMenu");
 177      this.contextMenuDiv.style.display = "none";
 178      this.contextMenuDiv.style.position = 'absolute';
 179      this.contextMenuDiv.style.zindex = 1000;
 180      this.contextMenuDiv.style.left = '0px';
 181      this.contextMenuDiv.style.top = '0px';
 182      this.contextMenuDiv.unselectable = "on";
 183  
 184      document.body.appendChild(this.contextMenuDiv);
 185  
 186      // Setup default values
 187      defParam("commandhandler", "");
 188      defParam("spacer_image", "images/spacer.gif");
 189  
 190      this.items = new Array();
 191      this.settings = settings;
 192      this.html = "";
 193  
 194      // IE Popup
 195      if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0) {
 196          this.pop = window.createPopup();
 197          doc = this.pop.document;
 198          doc.open();
 199          doc.write('<html><head><link href="' + tinyMCE.baseURL + '/plugins/contextmenu/contextmenu.css" rel="stylesheet" type="text/css" /></head><body unselectable="yes" class="contextMenuIEPopup"></body></html>');
 200          doc.close();
 201      }
 202  };
 203  
 204  ContextMenu.prototype.clearAll = function() {
 205      this.html = "";
 206      this.contextMenuDiv.innerHTML = "";
 207  };
 208  
 209  ContextMenu.prototype.addSeparator = function() {
 210      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>';
 211  };
 212  
 213  ContextMenu.prototype.addItem = function(icon, title, command, value, disabled) {
 214      if (title.charAt(0) == '$')
 215          title = tinyMCE.getLang(title.substring(1));
 216  
 217      var onMouseDown = '';
 218      var html = '';
 219  
 220      if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0)
 221          onMouseDown = 'contextMenu.execCommand(\'' + command + '\', \'' + value + '\');return false;';
 222      else
 223          onMouseDown = this.settings['commandhandler'] + '(\'' + command + '\', \'' + value + '\');return false;';
 224  
 225      if (icon == "")
 226          icon = this.settings['spacer_image'];
 227  
 228      if (!disabled)
 229          html += '<tr class="contextMenuItem" onmousedown="' + onMouseDown + '" onmouseover="tinyMCE.switchClass(this,\'contextMenuItemOver\');" onmouseout="tinyMCE.switchClass(this,\'contextMenuItem\');">';
 230      else
 231          html += '<tr class="contextMenuItemDisabled">';
 232  
 233      html += '<td class="contextMenuIcon"><img src="' + icon + '" width="20" height="20" class="contextMenuImage" /></td>';
 234      html += '<td><div class="contextMenuText">';
 235  
 236      // Add text
 237      html += title;
 238  
 239      html += '</div></td>';
 240      html += '</tr>';
 241  
 242      // Add to main
 243      this.html += html;
 244  };
 245  
 246  ContextMenu.prototype.show = function(x, y) {
 247      if (this.html == "")
 248          return;
 249  
 250      var html = '';
 251  
 252      html += '<table border="0" cellpadding="0" cellspacing="0">';
 253      html += this.html;
 254      html += '</table>';
 255  
 256      this.contextMenuDiv.innerHTML = html;
 257  
 258      if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0) {
 259          var width, height;
 260  
 261          // Get dimensions
 262          this.contextMenuDiv.style.display = "block";
 263          width = this.contextMenuDiv.offsetWidth;
 264          height = this.contextMenuDiv.offsetHeight;
 265          this.contextMenuDiv.style.display = "none";
 266  
 267          // Setup popup and show
 268          this.pop.document.body.innerHTML = '<div class="contextMenu">' + html + "</div>";
 269          this.pop.document.tinyMCE = tinyMCE;
 270          this.pop.document.contextMenu = this;
 271          this.pop.show(x, y, width, height);
 272      } else {
 273          this.contextMenuDiv.style.left = x + 'px';
 274          this.contextMenuDiv.style.top = y + 'px';
 275          this.contextMenuDiv.style.display = "block";
 276      }
 277  };
 278  
 279  ContextMenu.prototype.hide = function() {
 280      if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0)
 281          this.pop.hide();
 282      else
 283          this.contextMenuDiv.style.display = "none";
 284  };
 285  
 286  ContextMenu.prototype.execCommand = function(command, value) {
 287      eval(this.settings['commandhandler'] + "(command, value);");
 288  };


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7