jquery.cxtmenu.min.js 5.4 KB

123456789101112131415161718192021222324252627282930
  1. /* jquery.cxtmenu.min.js */
  2. /**
  3. * This file is part of cytoscape.js 2.0.2.
  4. *
  5. * Cytoscape.js is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU Lesser General Public License as published by the Free
  7. * Software Foundation, either version 3 of the License, or (at your option) any
  8. * later version.
  9. *
  10. * Cytoscape.js is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License along with
  16. * cytoscape.js. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. (function(a){var b={menuRadius:100,cytoscape:true,selector:undefined,commands:[],fillColor:"rgba(0, 0, 0, 0.75)",activeFillColor:"rgba(92, 194, 237, 0.75)",activePadding:20,indicatorSize:30,indicatorColor:"black",separatorWidth:3,spotlightPadding:4,itemColor:"white",itemTextShadowColor:"black"};a.fn.cxtmenu=function(g){var c=a.extend(true,{},b,g);var d=g;var f=a(this);var h;f.cytoscape(function(i){h=this});var e={destroy:function(){},init:function(){var D=a('<div class="cxtmenu"></div>');var w=a("<canvas></canvas>");
  19. var F=w[0].getContext("2d");var A=c.menuRadius;var u=f.offset();var H=(A+c.activePadding)*2;var y=undefined;f.append(D);D.append(w);D.css({width:H+"px",height:H+"px",position:"fixed",zIndex:999999,marginLeft:u.left-c.activePadding+"px",marginTop:u.top-c.activePadding+"px"}).hide();w[0].width=H;w[0].height=H;var v=c.commands;var z=2*Math.PI/(v.length);var E=v.length%2!==0?Math.PI/2:0;var C=E+z;var o=[];for(var J=0;J<v.length;J++){var p=v[J];var I=(E+C)/2;var K=0.66*A*Math.cos(I);var t=0.66*A*Math.sin(I);
  20. var j=a('<div class="cxtmenu-item"></div>');j.css({color:c.itemColor,cursor:"default",display:"table","text-align":"center",position:"absolute","text-shadow":"-1px -1px "+c.itemTextShadowColor+", 1px -1px "+c.itemTextShadowColor+", -1px 1px "+c.itemTextShadowColor+", 1px 1px "+c.itemTextShadowColor,left:"50%",top:"50%","min-height":A*0.66,width:A*0.66,height:A*0.66,marginLeft:K-A*0.33,marginTop:-t-A*0.33});var s=a('<div class="cxtmenu-content">'+p.content+"</div>");s.css({width:A*0.66,height:A*0.66,"vertical-align":"middle",display:"table-cell"});
  21. D.append(j);j.append(s);E+=z;C+=z}function k(S){S=S!==undefined?S:x;F.globalCompositeOperation="source-over";F.clearRect(0,0,H,H);F.fillStyle=c.fillColor;F.beginPath();F.arc(A+c.activePadding,A+c.activePadding,A,0,Math.PI*2,true);F.closePath();F.fill();F.globalCompositeOperation="destination-out";F.strokeStyle="white";F.lineWidth=c.separatorWidth;var r=c.commands;var T=2*Math.PI/(r.length);var Q=r.length%2!==0?Math.PI/2:0;var P=Q+T;for(var O=0;O<r.length;O++){var N=r[O];var U=A*Math.cos(Q);var R=A*Math.sin(Q);
  22. F.beginPath();F.moveTo(A+c.activePadding,A+c.activePadding);F.lineTo(A+c.activePadding+U,A+c.activePadding-R);F.closePath();F.stroke();Q+=T;P+=T}F.fillStyle="white";F.globalCompositeOperation="destination-out";F.beginPath();F.arc(A+c.activePadding,A+c.activePadding,S+c.spotlightPadding,0,Math.PI*2,true);F.closePath();F.fill();F.globalCompositeOperation="source-over"}var q=0;var M=1000/30;var G;var L=true;function m(r){var N=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame;
  23. var i=+new Date;clearTimeout(G);if(L||i>=q+M){N(r);q=i;L=false}else{G=setTimeout(function(){N(r);q=i},M*2)}}var n,l,x;var B;h.on("cxttapstart",c.selector,function(P){var N=this;var r=N.renderedPosition();var R=N.renderedWidth();var i=N.renderedHeight();var Q=a(window).scrollLeft();var O=a(window).scrollTop();n=r.x;l=r.y;D.show().css({left:r.x-A-Q,top:r.y-A-O});x=Math.max(R,i);x=32;k();y=undefined}).on("cxtdrag",c.selector,function(i){m(function(){var Z=i.originalEvent.pageX-f.offset().left-n;var Y=i.originalEvent.pageY-f.offset().top-l;
  24. if(Z===0){Z=0.01}var W=Math.sqrt(Z*Z+Y*Y);var V=(Y*Y-W*W-Z*Z)/(-2*W*Z);var O=Math.acos(V);y=undefined;if(W<x+c.spotlightPadding){k();return}k();var N=Z*A/W;var r=Y*A/W;if(Y>0){O=Math.PI+Math.abs(O-Math.PI)}var P=c.commands;var X=2*Math.PI/(P.length);var U=P.length%2!==0?Math.PI/2:0;var T=U+X;for(var S=0;S<P.length;S++){var R=P[S];var Q=U<=O&&O<=T||U<=O+2*Math.PI&&O+2*Math.PI<=T;if(Q){F.fillStyle=c.activeFillColor;F.strokeStyle="black";F.lineWidth=1;F.beginPath();F.moveTo(A+c.activePadding,A+c.activePadding);
  25. F.arc(A+c.activePadding,A+c.activePadding,A+c.activePadding,2*Math.PI-U,2*Math.PI-T,true);F.closePath();F.fill();y=S;break}U+=X;T+=X}F.fillStyle="white";F.globalCompositeOperation="destination-out";F.beginPath();F.translate(A+c.activePadding+N/A*(x+c.spotlightPadding-c.indicatorSize/4),A+c.activePadding+r/A*(x+c.spotlightPadding-c.indicatorSize/4));F.rotate(Math.PI/4-O);F.fillRect(-c.indicatorSize/2,-c.indicatorSize/2,c.indicatorSize,c.indicatorSize);F.closePath();F.fill();F.setTransform(1,0,0,1,0,0);
  26. F.beginPath();F.arc(A+c.activePadding,A+c.activePadding,x+c.spotlightPadding,0,Math.PI*2,true);F.closePath();F.fill();F.globalCompositeOperation="source-over"})}).on("cxttapend",c.selector,function(N){var r=this;D.hide();if(y!==undefined){var i=c.commands[y].select;if(i){i.apply(r)}}}).on("cxttapend",function(i){D.hide()})}};if(e[d]){return e[d].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof d=="object"||!d){return e.init.apply(this,arguments)}else{a.error("No such function `"+d+"` for jquery.cxtmenu")
  27. }}return a(this)}})(jQuery);