[ Index ]
 

Code source de Typo3 4.1.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/typo3/sysext/rtehtmlarea/htmlarea/plugins/ContextMenu/ -> context-menu-compressed.js (source)

   1  
   2  ContextMenu=function(editor){
   3  this.editor=editor;
   4  this.currentMenu=null;
   5  this.keys=[];
   6  this.eventHandlers={};
   7  };
   8  ContextMenu.I18N=ContextMenu_langArray;
   9  ContextMenu._pluginInfo={
  10  name:"ContextMenu",
  11  version:"1.8",
  12  developer:"Mihai Bazon & Stanislas Rolland",
  13  developer_url:"http://www.fructifor.ca/",
  14  c_owner:"dynarch.com & Stanislas Rolland",
  15  sponsor:"American Bible Society & Fructifor Inc.",
  16  sponsor_url:"http://www.fructifor.ca/",
  17  license:"GPL"
  18  };
  19  ContextMenu.prototype.onGenerate=function(){
  20  if(!HTMLArea.is_opera){
  21  this.editor.eventHandlers["contextMenu"]=ContextMenu.contextMenuHandler(this);
  22  HTMLArea._addEvent((HTMLArea.is_ie?this.editor._doc.body:this.editor._doc),"contextmenu",this.editor.eventHandlers["contextMenu"]);
  23  }else{
  24  this.editor.eventHandlers["mousedown"]=ContextMenu.contextMenuHandler(this);
  25  HTMLArea._addEvent(this.editor._doc,"mousedown",this.editor.eventHandlers["mousedown"]);
  26  }
  27  };
  28  ContextMenu.contextMenuHandler=function(instance){
  29  return(function(ev){
  30  if(!HTMLArea.is_opera||(HTMLArea.is_opera&&ev.button>=2))instance.popupMenu(ev);
  31  else return false;
  32  });
  33  };
  34  ContextMenu.tableOperationsHandler=function(editor,tbo,opcode){
  35  return(function(){
  36  tbo.buttonPress(editor,opcode);
  37  });
  38  };
  39  ContextMenu.imageHandler=function(editor,img){
  40  return(function(){
  41  editor._insertImage(img);
  42  });
  43  };
  44  ContextMenu.linkHandler=function(editor,link,opcode){
  45  switch(opcode){
  46  case "MakeLink":
  47  case "ModifyLink":
  48  return(function(){
  49  editor.execCommand("CreateLink",true);
  50  });
  51  case "CheckLink":
  52  return(function(){
  53  window.open(link.href);
  54  });
  55  case "RemoveLink":
  56  return(function(){
  57  if(confirm(ContextMenu.I18N["Please confirm unlink"]+"\n"+
  58  ContextMenu.I18N["Link points to:"]+" "+link.href)){
  59  if(typeof(editor.plugins["TYPO3Browsers"])!="undefined"){
  60  editor.renderPopup_unLink();
  61  }else{
  62  while(link.firstChild)link.parentNode.insertBefore(link.firstChild,link);
  63  link.parentNode.removeChild(link);
  64  }
  65  }
  66  });
  67  }
  68  };
  69  ContextMenu.execCommandHandler=function(editor,opcode){
  70  return(function(){
  71  editor.execCommand(opcode);
  72  });
  73  };
  74  ContextMenu.insertParagraphHandler=function(editor,currentTarget,after){
  75  return(function(){
  76  var el=currentTarget;
  77  var par=el.parentNode;
  78  var p=editor._doc.createElement("p");
  79  p.appendChild(editor._doc.createElement("br"));
  80  par.insertBefore(p,after?el.nextSibling:el);
  81  var sel=editor._getSelection();
  82  var range=editor._createRange(sel);
  83  if(HTMLArea.is_gecko){
  84  range.selectNodeContents(p);
  85  range.collapse(true);
  86  if(HTMLArea.is_safari){
  87  sel.empty();
  88  sel.setBaseAndExtent(range.startContainer,range.startOffset,range.endContainer,range.endOffset);
  89  }else{
  90  sel.removeAllRanges();
  91  sel.addRange(range);
  92  }
  93  }else{
  94  range.moveToElementText(p);
  95  range.collapse(true);
  96  range.select();
  97  }
  98  });
  99  };
 100  ContextMenu.deleteElementHandler=function(editor,tmp,table){
 101  return(function(){
 102  if(confirm(ContextMenu.I18N["Please confirm remove"]+" "+tmp.tagName.toLowerCase())){
 103  var el=tmp;
 104  var p=el.parentNode;
 105  p.removeChild(el);
 106  if(HTMLArea.is_gecko){
 107  if(p.tagName.toLowerCase()=="td"&&!p.hasChildNodes())p.appendChild(editor._doc.createElement("br"));
 108  editor.forceRedraw();
 109  editor.focusEditor();
 110  editor.updateToolbar();
 111  if(table){
 112  var save_collapse=table.style.borderCollapse;
 113  table.style.borderCollapse="collapse";
 114  table.style.borderCollapse="separate";
 115  table.style.borderCollapse=save_collapse;
 116  }
 117  }
 118  }
 119  });
 120  };
 121  ContextMenu.prototype.pushOperations=function(opcodes,elmenus,tbo){
 122  var editor=this.editor;
 123  var toolbarObjects=editor._toolbarObjects;
 124  var i18n=ContextMenu.I18N;
 125  var btnList=editor.config.btnList;
 126  var enabled=false,opcode,opEnabled=[],i=opcodes.length;
 127  for(i;i>0;){
 128  opcode=opcodes[--i];
 129  opEnabled[opcode]=toolbarObjects[opcode]&&toolbarObjects[opcode].enabled;
 130  enabled=enabled||opEnabled[opcode];
 131  }
 132  if(enabled&&elmenus.length)elmenus.push(null);
 133  for(i=opcodes.length;i>0;){
 134  opcode=opcodes[--i];
 135  if(opEnabled[opcode])elmenus.push([i18n[opcode+"-title"],
 136  (tbo?ContextMenu.tableOperationsHandler(editor,tbo,opcode):ContextMenu.execCommandHandler(editor,opcode)),
 137  i18n[opcode+"-tooltip"],
 138  btnList[opcode][1],opcode]);
 139  }
 140  };
 141  ContextMenu.prototype.getContextMenu=function(target){
 142  var editor=this.editor;
 143  var toolbarObjects=editor._toolbarObjects;
 144  var i18n=ContextMenu.I18N;
 145  var config=editor.config;
 146  var btnList=config.btnList;
 147  var menu=[],opcode;
 148  var tbo=this.editor.plugins["TableOperations"];
 149  if(tbo)tbo=tbo.instance;
 150  var selection=editor.hasSelectedText();
 151  if(selection){
 152  if(toolbarObjects['Cut']&&toolbarObjects['Cut'].enabled){
 153  opcode="Cut";
 154  menu.push([i18n[opcode],ContextMenu.execCommandHandler(editor,opcode),null,btnList[opcode][1],opcode]);
 155  }
 156  if(toolbarObjects['Copy']&&toolbarObjects['Copy'].enabled){
 157  opcode="Copy";
 158  menu.push([i18n[opcode],ContextMenu.execCommandHandler(editor,opcode),null,btnList[opcode][1],opcode]);
 159  }
 160  }
 161  if(toolbarObjects['Paste']&&toolbarObjects['Paste'].enabled){
 162  opcode="Paste";
 163  menu.push([i18n[opcode],ContextMenu.execCommandHandler(editor,opcode),null,btnList[opcode][1],opcode]);
 164  }
 165  var currentTarget=target,
 166  tmp,tag,link=false,
 167  table=null,tr=null,td=null,img=null,list=null,div=null;
 168  for(;target;target=target.parentNode){
 169  tag=target.tagName;
 170  if(!tag)continue;
 171  tag=tag.toLowerCase();
 172  switch(tag){
 173  case "img":
 174  img=target;
 175  if(toolbarObjects["InsertImage"]&&toolbarObjects["InsertImage"].enabled){
 176  if(menu.length)menu.push(null);
 177  menu.push(
 178  [i18n["Image Properties"],
 179  ContextMenu.imageHandler(editor,img),
 180  i18n["Show the image properties dialog"],
 181  btnList["InsertImage"][1],"InsertImage"]
 182  );
 183  }
 184  break;
 185  case "a":
 186  link=target;
 187  if(toolbarObjects["CreateLink"]){
 188  if(menu.length)menu.push(null);
 189  menu.push(
 190  [i18n["Modify Link"],
 191  ContextMenu.linkHandler(editor,link,"ModifyLink"),
 192  i18n["Current URL is"]+': '+link.href,
 193  btnList["CreateLink"][1],"CreateLink"],
 194  [i18n["Check Link"],
 195  ContextMenu.linkHandler(editor,link,"CheckLink"),
 196  i18n["Opens this link in a new window"],
 197  null,null],
 198  [i18n["Remove Link"],
 199  ContextMenu.linkHandler(editor,link,"RemoveLink"),
 200  i18n["Unlink the current element"],
 201  editor.imgURL("ed_unlink.gif"),"UnLink"]
 202  );
 203  }
 204  break;
 205  case "td":
 206  case "th":
 207  td=target;
 208  if(!tbo)break;
 209  this.pushOperations(["TO-cell-split","TO-cell-delete","TO-cell-insert-after","TO-cell-insert-before","TO-cell-prop"],menu,tbo);
 210  break;
 211  case "tr":
 212  tr=target;
 213  if(!tbo)break;
 214  opcode="TO-cell-merge";
 215  if(toolbarObjects[opcode]&&toolbarObjects[opcode].enabled)
 216  menu.push([i18n[opcode+"-title"],
 217  ContextMenu.tableOperationsHandler(editor,tbo,opcode),
 218  i18n[opcode+"-tooltip"],
 219  btnList[opcode][1],opcode]);
 220  this.pushOperations(["TO-row-split","TO-row-delete","TO-row-insert-under","TO-row-insert-above","TO-row-prop"],menu,tbo);
 221  break;
 222  case "table":
 223  table=target;
 224  if(!tbo)break;
 225  this.pushOperations(["TO-toggle-borders","TO-table-prop","TO-col-split","TO-col-delete","TO-col-insert-after","TO-col-insert-before"],menu,tbo);
 226  break;
 227  case "ol":
 228  case "ul":
 229  case "dl":
 230  list=target;
 231  break;
 232  case "div":
 233  div=target;
 234  break;
 235  case "body":
 236  this.pushOperations(["JustifyFull","JustifyRight","JustifyCenter","JustifyLeft"],menu,null);
 237  break;
 238  }
 239  }
 240  if(selection&&!link){
 241  if(menu.length)menu.push(null);
 242  menu.push([i18n["Make link"],
 243  ContextMenu.linkHandler(editor,link,"MakeLink"),
 244  i18n["Create a link"],
 245  btnList["CreateLink"][1],"CreateLink"]);
 246  }
 247  if(!/html|body/i.test(currentTarget.tagName)){
 248  if(/table|thead|tbody|tr|td|th|tfoot/i.test(currentTarget.tagName)){
 249  tmp=table;
 250  table=null;
 251  }else if(list){
 252  tmp=list;
 253  list=null;
 254  }else{
 255  tmp=currentTarget;
 256  }
 257  if(menu.length)menu.push(null);
 258  menu.push(
 259  [i18n["Remove the"]+" <"+tmp.tagName.toLowerCase()+"> "+i18n["Element"],
 260  ContextMenu.deleteElementHandler(editor,tmp,table),i18n["Remove this node from the document"]],
 261  [i18n["Insert paragraph before"],
 262  ContextMenu.insertParagraphHandler(editor,tmp,false),i18n["Insert a paragraph before the current node"]],
 263  [i18n["Insert paragraph after"],
 264  ContextMenu.insertParagraphHandler(editor,tmp,true),i18n["Insert a paragraph after the current node"]]
 265  );
 266  }
 267  return menu;
 268  };
 269  ContextMenu.mouseOverHandler=function(editor,item){
 270  return(function(){
 271  item.className+=" hover";
 272  editor._statusBarTree.innerHTML=item.__msh.tooltip||' ';
 273  });
 274  };
 275  ContextMenu.mouseOutHandler=function(item){
 276  return(function(){
 277  item.className=item.className.replace(/hover/,"");
 278  });
 279  };
 280  ContextMenu.itemContextMenuHandler=function(item){
 281  return(function(ev){
 282  item.__msh.activate();
 283  if(!HTMLArea.is_ie)HTMLArea._stopEvent(ev);
 284  return false;
 285  });
 286  };
 287  ContextMenu.mouseDownHandler=function(item){
 288  return(function(ev){
 289  HTMLArea._stopEvent(ev);
 290  return false;
 291  });
 292  };
 293  ContextMenu.mouseUpHandler=function(item,instance){
 294  return(function(ev){
 295  var timeStamp=(new Date()).getTime();
 296  if(timeStamp-instance.timeStamp>500)item.__msh.activate();
 297  if(!HTMLArea.is_ie)HTMLArea._stopEvent(ev);
 298  instance.editor.updateToolbar();
 299  return false;
 300  });
 301  };
 302  ContextMenu.activateHandler=function(item,instance){
 303  return(function(){
 304  item.__msh.action();
 305  instance.closeMenu();
 306  });
 307  };
 308  ContextMenu.documentClickHandler=function(instance){
 309  return(function(ev){
 310  if(!ev)var ev=window.event;
 311  if(!instance.currentMenu){
 312  alert(ContextMenu.I18N["How did you get here? (Please report!)"]);
 313  return false;
 314  }
 315  var el=(ev.target)?ev.target:ev.srcElement;
 316  for(;el!=null&&el!=instance.currentMenu;el=el.parentNode);
 317  if(el==null){
 318  instance.closeMenu();
 319  instance.editor.updateToolbar();
 320  }
 321  });
 322  };
 323  ContextMenu.keyPressHandler=function(instance){
 324  return(function(ev){
 325  if(!ev)var ev=window.event;
 326  if(ev.keyCode==27){
 327  instance.closeMenu();
 328  return false;
 329  }
 330  if(ev.altKey&&!ev.ctrlKey){
 331  var key=String.fromCharCode(HTMLArea.is_ie?ev.keyCode:ev.charCode).toLowerCase();
 332  var keys=instance.keys;
 333  for(var i=keys.length;--i>=0;){
 334  var k=keys[i];
 335  if(k[0].toLowerCase()==key)k[1].__msh.activate();
 336  }
 337  HTMLArea._stopEvent(ev);
 338  return false;
 339  }
 340  });
 341  };
 342  ContextMenu.prototype.closeMenu=function(){
 343  HTMLArea._removeEvent((HTMLArea.is_ie?document.body:document),"mousedown",this.eventHandlers["documentClick"]);
 344  HTMLArea._removeEvent((HTMLArea.is_ie?this.editor._doc.body:this.editor._doc),"mousedown",this.eventHandlers["documentClick"]);
 345  if(this.keys.length>0)HTMLArea._removeEvent((HTMLArea.is_ie?this.editor._doc.body:this.editor._doc),"keypress",this.eventHandlers["keyPress"]);
 346  for(var handler in this.eventHandlers)this.eventHandlers[handler]=null;
 347  var e,items=document.getElementsByTagName("li");
 348  if(HTMLArea.is_ie)items=this.iePopup.document.getElementsByTagName("li");;
 349  for(var i=items.length;--i>=0;){
 350  e=items[i];
 351  if(e.__msh){
 352  HTMLArea._removeEvent(e,"mouseover",e.__msh.mouseover);
 353  e.__msh.mouseover=null;
 354  HTMLArea._removeEvent(e,"mouseout",e.__msh.mouseout);
 355  e.__msh.mouseout=null;
 356  HTMLArea._removeEvent(e,"contextmenu",e.__msh.contextmenu);
 357  e.__msh.contextmenu=null;
 358  if(!HTMLArea.is_ie)HTMLArea._removeEvent(e,"mousedown",e.__msh.mousedown);
 359  e.__msh.mousedown=null;
 360  HTMLArea._removeEvent(e,"mouseup",e.__msh.mouseup);
 361  e.__msh.mouseup=null;
 362  e.__msh.action=null;
 363  e.__msh.activate=null;
 364  e.__msh=null;
 365  }
 366  }
 367  this.currentMenu.parentNode.removeChild(this.currentMenu);
 368  this.currentMenu=null;
 369  this.keys=[];
 370  if(HTMLArea.is_ie)this.iePopup.hide();
 371  };
 372  ContextMenu.getPos=function(el){
 373  var r={x:el.offsetLeft,y:el.offsetTop};
 374  if(el.offsetParent){
 375  var tmp=ContextMenu.getPos(el.offsetParent);
 376  r.x+=tmp.x;
 377  r.y+=tmp.y;
 378  }
 379  return r;
 380  };
 381  ContextMenu.prototype.popupMenu=function(ev,target){
 382  var editor=this.editor;
 383  if(!ev)var ev=window.event;
 384  if(!target)var target=(ev.target)?ev.target:ev.srcElement;
 385  if(this.currentMenu)this.currentMenu.parentNode.removeChild(this.currentMenu);
 386  this.keys=[];
 387  var ifpos=ContextMenu.getPos(this.editor._iframe);
 388  var x=ev.clientX+ifpos.x;
 389  var y=ev.clientY+ifpos.y;
 390  var doc,list,separator=false;
 391  if(!HTMLArea.is_ie){
 392  doc=document;
 393  }else{
 394  var popup=this.iePopup=window.createPopup();
 395  doc=popup.document;
 396  var head=doc.getElementsByTagName("head")[0];
 397  var link=doc.createElement("link");
 398  link.rel="stylesheet";
 399  link.type="text/css";
 400  if(_editor_CSS.indexOf("http")==-1)link.href=_typo3_host_url+_editor_CSS;
 401  else link.href=_editor_CSS;
 402  head.appendChild(link);
 403  }
 404  list=doc.createElement("ul");
 405  list.className="htmlarea-context-menu";
 406  doc.body.appendChild(list);
 407  var options=this.getContextMenu(target);
 408  var n=options.length;
 409  for(var i=0;i<n;++i){
 410  var option=options[i];
 411  if(!option){
 412  separator=true;
 413  }else{
 414  var item=doc.createElement("li");
 415  list.appendChild(item);
 416  var label=option[0];
 417  if(separator){
 418  item.className+=" separator";
 419  separator=false;
 420  }
 421  item.__msh={
 422  item:item,
 423  label:label,
 424  action:option[1],
 425  tooltip:option[2]||null,
 426  icon:option[3]||null,
 427  activate:ContextMenu.activateHandler(item,this),
 428  cmd:option[4]||null
 429  };
 430  label=label.replace(/_([a-zA-Z0-9])/,"<u>$1</u>");
 431  if(label!=option[0])this.keys.push([RegExp.$1,item]);
 432  label=label.replace(/__/,"_");
 433  var button=doc.createElement("button");
 434  button.className="button";
 435  if(item.__msh.cmd){
 436  button.className+=" "+item.__msh.cmd;
 437  if(typeof(editor.plugins["TYPO3Browsers"])!="undefined"&&(item.__msh.cmd=="CreateLink"||item.__msh.cmd=="UnLink"||item.__msh.cmd=="InsertImage"))button.className+="-TYPO3Browsers";
 438  button.innerHTML=label;
 439  }else if(item.__msh.icon){
 440  button.innerHTML="<img src='"+item.__msh.icon+"' />"+label;
 441  }else{
 442  button.innerHTML=label;
 443  }
 444  item.appendChild(button);
 445  item.__msh.mouseover=ContextMenu.mouseOverHandler(editor,item);
 446  HTMLArea._addEvent(item,"mouseover",item.__msh.mouseover);
 447  item.__msh.mouseout=ContextMenu.mouseOutHandler(item);
 448  HTMLArea._addEvent(item,"mouseout",item.__msh.mouseout);
 449  item.__msh.contextmenu=ContextMenu.itemContextMenuHandler(item);
 450  HTMLArea._addEvent(item,"contextmenu",item.__msh.contextmenu);
 451  if(!HTMLArea.is_ie){
 452  item.__msh.mousedown=ContextMenu.mouseDownHandler(item);
 453  HTMLArea._addEvent(item,"mousedown",item.__msh.mousedown);
 454  }
 455  item.__msh.mouseup=ContextMenu.mouseUpHandler(item,this);
 456  HTMLArea._addEvent(item,"mouseup",item.__msh.mouseup);
 457  }
 458  }
 459  if(n){
 460  if(!HTMLArea.is_ie){
 461  var dx=x+list.offsetWidth-window.innerWidth-window.pageXOffset+4;
 462  var dy=y+list.offsetHeight-window.innerHeight-window.pageYOffset+4;
 463  if(dx>0)x-=dx;
 464  if(dy>0)y-=dy;
 465  list.style.left=x+"px";
 466  list.style.top=y+"px";
 467  }else{
 468  list.style.left="0px";
 469  list.style.top="0px";
 470  var foobar=document.createElement("ul");
 471  foobar.className="htmlarea-context-menu";
 472  foobar.innerHTML=list.innerHTML;
 473  editor._iframe.contentWindow.parent.document.body.appendChild(foobar);
 474  this.iePopup.show(ev.screenX,ev.screenY,foobar.clientWidth+2,foobar.clientHeight+2);
 475  editor._iframe.contentWindow.parent.document.body.removeChild(foobar);
 476  }
 477  this.currentMenu=list;
 478  this.timeStamp=(new Date()).getTime();
 479  this.eventHandlers["documentClick"]=ContextMenu.documentClickHandler(this);
 480  HTMLArea._addEvent((HTMLArea.is_ie?document.body:document),"mousedown",this.eventHandlers["documentClick"]);
 481  HTMLArea._addEvent((HTMLArea.is_ie?editor._doc.body:editor._doc),"mousedown",this.eventHandlers["documentClick"]);
 482  if(this.keys.length>0){
 483  this.eventHandlers["keyPress"]=ContextMenu.keyPressHandler(this);
 484  HTMLArea._addEvents((HTMLArea.is_ie?editor._doc.body:editor._doc),["keypress","keydown"],this.eventHandlers["keyPress"]);
 485  }
 486  }
 487  HTMLArea._stopEvent(ev);
 488  return false;
 489  };
 490  


Généré le : Sun Nov 25 17:13:16 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics