transmission/web/javascript/jquery/jquery.contextmenu.min.js

1 line
2.2 KiB
JavaScript
Raw Normal View History

(function(f){var a,j,c,h,e,b;var d={menuStyle:{listStyle:"none",padding:"1px",margin:"0px",backgroundColor:"#fff",border:"1px solid #999",width:"100px"},itemStyle:{margin:"0px",color:"#000",display:"block",cursor:"default",padding:"3px",border:"1px solid #fff",backgroundColor:"transparent"},itemHoverStyle:{border:"1px solid #0a246a",backgroundColor:"#b6bdd2"},eventPosX:"pageX",eventPosY:"pageY",shadow:true,onContextMenu:null,onShowMenu:null};f.fn.contextMenu=function(m,l){if(!a){a=f('<div id="jqContextMenu"></div>').hide().css({position:"absolute",zIndex:"500"}).appendTo("body").bind("click",function(n){n.stopPropagation()})}if(!j){j=f("<div></div>").css({backgroundColor:"#000",position:"absolute",opacity:0.2,zIndex:499}).appendTo("body").hide()}e=e||[];e.push({id:m,menuStyle:f.extend({},d.menuStyle,l.menuStyle||{}),itemStyle:f.extend({},d.itemStyle,l.itemStyle||{}),itemHoverStyle:f.extend({},d.itemHoverStyle,l.itemHoverStyle||{}),bindings:l.bindings||{},shadow:l.shadow||l.shadow===false?l.shadow:d.shadow,onContextMenu:l.onContextMenu||d.onContextMenu,onShowMenu:l.onShowMenu||d.onShowMenu,eventPosX:l.eventPosX||d.eventPosX,eventPosY:l.eventPosY||d.eventPosY});var k=e.length-1;f(this).bind("contextmenu",function(o){var n=(!!e[k].onContextMenu)?e[k].onContextMenu(o):true;if(n){i(k,this,o,l)}return false});return this};function i(m,l,p,k){var q=e[m];var o=p[q.eventPosY];var n=p[q.eventPosX];h=f("#"+q.id).find("ul:first").clone(true);h.css(q.menuStyle).find("li").css(q.itemStyle).hover(function(){f(this).css(q.itemHoverStyle)},function(){f(this).css(q.itemStyle)}).find("img").css({verticalAlign:"middle",paddingRight:"2px"});a.html(h);if(!!q.onShowMenu){a=q.onShowMenu(p,a)}f.each(q.bindings,function(s,r){f("#"+s,a).bind("click",function(t){g();r(l,b)})});if(o+a.height()>f(window).height()){o=o-a.height()}if(n+a.width()>f(window).width()){n=n-a.width()}a.css({left:n,top:o}).show();if(q.shadow){j.css({width:a.width(),height:a.height(),left:p.pageX+2,top:p.pageY+2}).show()}setTimeout(function(){f(document).click(function(){a.unbind("click");g();return false})},0)}function g(){a.hide();j.hide()}f.contextMenu={defaults:function(k){f.each(k,function(l,m){if(typeof m=="object"&&d[l]){f.extend(d[l],m)}else{d[l]=m}})}}})(jQuery);$(function(){$("div.contextMenu").hide()});