PageSourceSearch

https://www.8682.cc/js/md.hzl.contextmenu.js

js 8682.cc collected 2026-10-07 22:45:20 UTC 5,337 bytes, 177 lines download raw bytes

1(function($){
2	var menu, shadow, hash;
3	$.fn.extend({
4         /** 
5         * 样式类切换
6         */          
7        hoverClass: function(className) {
8            var _className = className || "hover";
9            return this.each(function() {
10                $(this).hover(function() {
11                    if (!$(this).data("focus")) {
12                        $(this).addClass(_className);
13                    }
14                }, function() {
15                    if (!$(this).data("focus")) $(this).removeClass(_className);
16                });
17            });
18        },
19		contextMenu: function(id, options){
20			var op = $.extend({
21				    shadow : true,
22				    bindings:{},
23					ctrSub:null,
24					mouseEvent:"contextmenu"
25				}, options
26			);
27			
28			if (!menu) {
29				menu = $('<div id="contextmenu"></div>').appendTo('body').hide();
30			}
31			if (!shadow) {
32				shadow = $('<div id="contextmenuShadow"></div>').appendTo('body').hide();
33			}
34			
35			hash = hash || [];
36			hash.push({
37				id : "contextmenu_"+id,
38				shadow: op.shadow,
39				bindings: op.bindings || {},
40				ctrSub: op.ctrSub,
41				content:$("#"+id).html(),
42				menudata:op.menudata
43			});
44
45			var index = hash.length - 1;
46			var action=op.mouseEvent ? op.mouseEvent : "contextmenu";
47			if(action=="hover"){
48                $(this).hover(function(e) {
49                    display(index, this, e, op);
50                }, function(e) {
51                    //hide();
52                });
53			}else{
54		        $(this).bind(action, function(e) {
55			        display(index, this, e, op);
56			        return false;
57		        });
58		    }
59		    
60			return this;
61		},
62		ShowMenu:function(options){ // 图集分类菜单
63		    return this.each(function() {
64		        var $this = $(this);
65		        var id=$this.attr("menu-id") || "";
66		        var data= $this.attr("menu-data") || "";
67		        if(!id || $("#"+id).size()==0) return;
68		        if(!options) options={};
69			    var op = $.extend({
70				        shadow : true,
71				        bindings:{},
72					    ctrSub:null,
73					    menudata:data
74				    }, options
75			    );
76		        $this.contextMenu(id, op);
77		    })
78		}
79//	    menu_gallery_class:function(){ // navTab右键菜单
80//		    var $this = $(this);
81//		    var id=$this.attr("for") || "";
82//		    if(!id) return;
83//		    $this.contextMenu('navTabCM', {
84//			    bindings:{
85//				    reload:function(t,m){
86//					    $this._reload(t, true);
87//				    },
88//				    closeCurrent:function(t,m){
89//					    var tabId = t.attr("tabid");
90//					    if (tabId) $this.closeTab(tabId);
91//					    else $this.closeCurrentTab();
92//				    },
93//				    closeOther:function(t,m){
94//					    var index = $this._indexTabId(t.attr("tabid"));
95//					    $this._closeOtherTab(index > 0 ? index : $this._currentIndex);
96//				    },
97//				    closeAll:function(t,m){
98//					    $this.closeAllTab();
99//				    }
100//			    },
101//			    ctrSub:function(t,m){
102//				    var mReload = m.find("[rel='reload']");
103//				    var mCur = m.find("[rel='closeCurrent']");
104//				    var mOther = m.find("[rel='closeOther']");
105//				    var mAll = m.find("[rel='closeAll']");
106//				    var $tabLi = $this._getTabs();
107//				    if ($tabLi.size() < 2) {
108//					    mCur.addClass("disabled");
109//					    mOther.addClass("disabled");
110//					    mAll.addClass("disabled");
111//				    }
112//				    if ($this._currentIndex == 0 || t.attr("tabid") == $this._op.mainTabId) {
113//					    mCur.addClass("disabled");
114//					    mReload.addClass("disabled");
115//				    } else if ($tabLi.size() == 2) {
116//					    mOther.addClass("disabled");
117//				    }
118//    				
119//			    }
120//		    });
121//	    }
122	});
123	
124	function display(index, trigger, e, options) {
125		var cur = hash[index];
126
127		var content = $(cur.content);
128		content.find('li').hoverClass();
129		content.attr("id",cur.id).attr("menu-data",cur.menudata);
130		// Send the content to the menu
131		menu.html(content);
132	
133		$.each(cur.bindings, function(id, func) {
134			$("[rel='"+id+"']", menu).bind('click', function(e) {
135				hide();
136				func($(trigger), $("#"+cur.id));
137			});
138		});
139		
140	    if ($.isFunction(cur.ctrSub)) {cur.ctrSub($(trigger), $("#"+cur.id));}
141			
142		var posX = e.pageX;
143		var posY = e.pageY;
144		if(options.mouseEvent=="contextmenu"){
145		    if ($(window).width() < posX + menu.width()) posX -= menu.width();
146		    if ($(window).height() < posY + menu.height()) posY -= menu.height();
147		}else{
148		    var $target = $(e.target);
149		    var ew=$target[0].offsetWidth;
150		    var eh=$target[0].offsetHeight;
151		    var et=$target.offset().top
152		    var el=$target.offset().left;
153		    posX=el;
154		    posY=et+eh;
155		    if ($(window).width() < posX + menu.width()) posX -= ew;
156		    if ($(window).height() < posY + menu.height()) posY -= (menu.height()+eh);
157		}
158
159		menu.css({'left':posX,'top':posY}).show();
160		if (cur.shadow) shadow.css({width:menu.width(),height:menu.height(),left:posX+3,top:posY+3}).show();
161		$(document).one('click', hide);
162		
163		content.find('li').each(function(i){
164		    var jq=$(this);
165		    if(jq.hasClass("disabled")){
166		        jq.unbind("click");
167		        jq.removeAttr("onclick")
168		    }
169		})
170	}
171	
172	function hide() {
173		menu.hide();
174		shadow.hide();
175	}
176})(jQuery);
177

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.