From 2b65db86ba2c1c5c93d4fcfca4d3e6ce488d2433 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Wed, 31 Aug 2011 14:22:28 +0000 Subject: [PATCH] fix a bug in jquery.transmenu that caused popping the menu up to be very slow if there are a lot of torrents in torrent_list. --- web/javascript/jquery/jquery.transmenu.js | 2 +- web/javascript/jquery/jquery.transmenu.min.js | 31 +------------------ 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/web/javascript/jquery/jquery.transmenu.js b/web/javascript/jquery/jquery.transmenu.js index 45dea2639..e05e91d4b 100644 --- a/web/javascript/jquery/jquery.transmenu.js +++ b/web/javascript/jquery/jquery.transmenu.js @@ -56,7 +56,7 @@ if ( !div.isVisible ) { div.timer = setTimeout( function() { //check if the mouse is still over the parent item - if not dont show the submenu - if (! $('div').parent().is('.hover')) { + if (! $(div).parent().is('.hover')) { return; } //assign events to all div>ul>li-elements diff --git a/web/javascript/jquery/jquery.transmenu.min.js b/web/javascript/jquery/jquery.transmenu.min.js index 8eb058aca..60d3664fc 100644 --- a/web/javascript/jquery/jquery.transmenu.min.js +++ b/web/javascript/jquery/jquery.transmenu.min.js @@ -1,30 +1 @@ - -(function($) -{var defaults={onClick:function(){$(this).find('>a').each(function(){if(this.href) -{window.location=this.href;}});},arrow_char:'►',selected_char:'✓',subDelay:300,direction:'down',mainDelay:10};var transMenuSettings;$.fn.transMenu=function(options) -{var shown=false;var liOffset=2;transMenuSettings=$.extend({},defaults,options);var hideDIV=function(div,delay){if(div.timer&&!div.isVisible){clearTimeout(div.timer);}else if(div.timer){return;} -if(div.isVisible){div.timer=setTimeout(function(){$(div).find('ul li').unbind('mouseover',liHoverIn).unbind('mouseout',liHoverOut).unbind('click',transMenuSettings.onClick);$(div).hide();div.isVisible=false;div.timer=null;},delay);}};var showDIV=function(div,delay){if(div.timer){clearTimeout(div.timer);} -if(!div.isVisible){div.timer=setTimeout(function(){if(!$('div').parent().is('.hover')){return;} -$(div).find('ul li').mouseover(liHoverIn).mouseout(liHoverOut).click(transMenuSettings.onClick);if(!$(div).parent().is('.main')){$(div).css('left',$(div).parent().parent().width()-liOffset);} -if(transMenuSettings.direction=='up'){$(div).css('top',($(div).height()*-1)+$(div).parent().parent().height());} -div.isVisible=true;$(div).show();div.timer=null;},delay);}};var testHandleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}} -if(p==this){return false;} -return true;};var mainHoverIn=function(e){$(this).addClass('hover').siblings('li.hover').removeClass('hover');if(shown){hoverIn(this,transMenuSettings.mainDelay);}};var liHoverIn=function(e){if(!testHandleHover(e)){return false;} -if(e.target!=this){if(!isChild(this,e.target)){return;}} -hoverIn(this,transMenuSettings.subDelay);};var hoverIn=function(li,delay){var n=li.parentNode.firstChild;for(;n;n=n.nextSibling){if(n.nodeType==1&&n.nodeName.toUpperCase()=='LI'){var div=getOneChild(n,'DIV');if(div&&div.timer&&!div.isVisible){clearTimeout(div.timer);div.timer=null;}}} -var pNode=li.parentNode;for(;pNode;pNode=pNode.parentNode){if(pNode.nodeType==1&&pNode.nodeName.toUpperCase()=='DIV'){if(pNode.timer){clearTimeout(pNode.timer);pNode.timer=null;$(pNode.parentNode).addClass('hover');}}} -$(li).addClass('hover');var innerDiv=$(li).children('div');innerDiv=innerDiv.length?innerDiv[0]:null;if(innerDiv&&innerDiv.isVisible){if(innerDiv.timer){clearTimeout(innerDiv.timer);innerDiv.timer=null;}else{return;}} -$(li.parentNode.getElementsByTagName('DIV')).each(function(){if(this!=innerDiv&&this.isVisible){hideDIV(this,delay);$(this.parentNode).removeClass('hover');}});if(innerDiv){showDIV(innerDiv,delay);}};var liHoverOut=function(e){if(!testHandleHover(e)){return false;} -if(e.target!=this){if(!isChild(this,e.target)){return;}} -var div=getOneChild(this,'DIV');if(!div){$(this).removeClass('hover');}else{if(!div.isVisible){$(this).removeClass('hover');}}};var mainHoverOut=function(e){var div=getOneChild(this,'DIV');var relTarget=e.relatedTarget||e.toElement;var p;if(!shown){$(this).removeClass('hover');}else if(!div&&relTarget){p=$(e.target).parents('UL.trans_menu');if(p.contains(relTarget)){$(this).removeClass('hover');}}else if(relTarget){p=$(e.target).parents('UL.trans_menu');if(!div.isVisible&&(p.contains(relTarget))){$(this).removeClass('hover');}}};var mainClick=function(){var div=getOneChild(this,'DIV');if(div&&div.isVisible){clean();$(this).addClass('hover');}else{hoverIn(this,transMenuSettings.mainDelay);shown=true;$('ul.trans_menu li').addClass('active');$(document).bind('mousedown',checkMouse);}};var checkMouse=function(e){var vis=false;$(e.target).parents('UL.trans_menu').find('div').each(function(){if(this.isVisible){vis=true;}});if(!vis){clean();}};var clean=function(){$('ul.trans_menu div.outerbox').each(function(){if(this.timer){clearTimeout(this.timer);this.timer=null;} -if(this.isVisible){$(this).hide();this.isVisible=false;}});$('ul.trans_menu li').removeClass('hover');$('ul.trans_menu>li li').unbind('mouseover',liHoverIn).unbind('mouseout',liHoverOut).unbind('click',transMenuSettings.onClick);$(document).unbind('mousedown',checkMouse);shown=false;$('ul.trans_menu li').removeClass('active');};var getOneChild=function(elem,name){if(!elem){return null;} -var n=elem.firstChild;for(;n;n=n.nextSibling){if(n.nodeType==1&&n.nodeName.toUpperCase()==name){return n;}} -return null;};var isChild=function(elem,childElem){var n=elem.firstChild;for(;n;n=n.nextSibling){if(n==childElem){return true;}} -return false;};return this.each(function(){if(window.Node&&Node.prototype&&!Node.prototype.contains){Node.prototype.contains=function(arg){return!!(this.compareDocumentPosition(arg)&16);};} -if(!$(this).is('.trans_menu')){$(this).addClass('trans_menu');} -$('ul',this).shadowBox();$(this).bind('closemenu',function(){clean();});var liElems=$(this).children('li');for(var j=0;jdiv').addClass('inner');if(transMenuSettings.arrow_char){var arrow_markup=$(""+transMenuSettings.arrow_char+'');if($.browser.mozilla&&+$.browser.version.replace(/\./g,'').slice(0,3)<191){arrow_markup.css('margin-top','-13px');} -$('div.inner div.outerbox',this).before(arrow_markup);} -});};$.fn.transMenu.setDefaults=function(o){$.extend(defaults,o);};$.fn.shadowBox=function(){return this.each(function(){var outer=$('
').get(0);if($(this).css('position')=='absolute'){$(outer).css({position:'relative',width:this.offsetWidth,height:this.offsetHeight});}else{$(outer).css('position','absolute');} -$(this).addClass('innerBox').wrap(outer).before('
');});};$.fn.selectMenuItem=function(){if(this.find('span.selected').length==0){this.prepend($(""+transMenuSettings.selected_char+""));} -return this;};$.fn.deselectMenuItem=function(){return this.find('span.selected').remove();};$.fn.menuItemIsSelected=function(){return(this.find('span.selected').length>0);};$.fn.deselectMenuSiblings=function(){this.parent().find('span.selected').remove();this.selectMenuItem();return this;};})(jQuery); +(function(b){var c={onClick:function(){b(this).find(">a").each(function(){if(this.href){window.location=this.href}})},arrow_char:"►",selected_char:"✓",subDelay:300,direction:"down",mainDelay:10};var a;b.fn.transMenu=function(s){var q=false;var j=2;a=b.extend({},c,s);var k=function(u,t){if(u.timer&&!u.isVisible){clearTimeout(u.timer)}else{if(u.timer){return}}if(u.isVisible){u.timer=setTimeout(function(){b(u).find("ul li").unbind("mouseover",r).unbind("mouseout",h).unbind("click",a.onClick);b(u).hide();u.isVisible=false;u.timer=null},t)}};var g=function(u,t){if(u.timer){clearTimeout(u.timer)}if(!u.isVisible){u.timer=setTimeout(function(){if(!b(u).parent().is(".hover")){return}b(u).find("ul li").mouseover(r).mouseout(h).click(a.onClick);if(!b(u).parent().is(".main")){b(u).css("left",b(u).parent().parent().width()-j)}if(a.direction=="up"){b(u).css("top",(b(u).height()*-1)+b(u).parent().parent().height())}u.isVisible=true;b(u).show();u.timer=null},t)}};var n=function(u){var t=(u.type=="mouseover"?u.fromElement:u.toElement)||u.relatedTarget;while(t&&t!=this){try{t=t.parentNode}catch(u){t=this}}if(t==this){return false}return true};var i=function(t){b(this).addClass("hover").siblings("li.hover").removeClass("hover");if(q){o(this,a.mainDelay)}};var r=function(t){if(!n(t)){return false}if(t.target!=this){if(!e(this,t.target)){return}}o(this,a.subDelay)};var o=function(t,u){var y=t.parentNode.firstChild;for(;y;y=y.nextSibling){if(y.nodeType==1&&y.nodeName.toUpperCase()=="LI"){var x=d(y,"DIV");if(x&&x.timer&&!x.isVisible){clearTimeout(x.timer);x.timer=null}}}var v=t.parentNode;for(;v;v=v.parentNode){if(v.nodeType==1&&v.nodeName.toUpperCase()=="DIV"){if(v.timer){clearTimeout(v.timer);v.timer=null;b(v.parentNode).addClass("hover")}}}b(t).addClass("hover");var w=b(t).children("div");w=w.length?w[0]:null;if(w&&w.isVisible){if(w.timer){clearTimeout(w.timer);w.timer=null}else{return}}b(t.parentNode.getElementsByTagName("DIV")).each(function(){if(this!=w&&this.isVisible){k(this,u);b(this.parentNode).removeClass("hover")}});if(w){g(w,u)}};var h=function(t){if(!n(t)){return false}if(t.target!=this){if(!e(this,t.target)){return}}var u=d(this,"DIV");if(!u){b(this).removeClass("hover")}else{if(!u.isVisible){b(this).removeClass("hover")}}};var l=function(v){var w=d(this,"DIV");var u=v.relatedTarget||v.toElement;var t;if(!q){b(this).removeClass("hover")}else{if(!w&&u){t=b(v.target).parents("UL.trans_menu");if(t.contains(u)){b(this).removeClass("hover")}}else{if(u){t=b(v.target).parents("UL.trans_menu");if(!w.isVisible&&(t.contains(u))){b(this).removeClass("hover")}}}}};var f=function(){var t=d(this,"DIV");if(t&&t.isVisible){p();b(this).addClass("hover")}else{o(this,a.mainDelay);q=true;b("ul.trans_menu li").addClass("active");b(document).bind("mousedown",m)}};var m=function(u){var t=false;b(u.target).parents("UL.trans_menu").find("div").each(function(){if(this.isVisible){t=true}});if(!t){p()}};var p=function(){b("ul.trans_menu div.outerbox").each(function(){if(this.timer){clearTimeout(this.timer);this.timer=null}if(this.isVisible){b(this).hide();this.isVisible=false}});b("ul.trans_menu li").removeClass("hover");b("ul.trans_menu>li li").unbind("mouseover",r).unbind("mouseout",h).unbind("click",a.onClick);b(document).unbind("mousedown",m);q=false;b("ul.trans_menu li").removeClass("active")};var d=function(u,t){if(!u){return null}var v=u.firstChild;for(;v;v=v.nextSibling){if(v.nodeType==1&&v.nodeName.toUpperCase()==t){return v}}return null};var e=function(u,t){var v=u.firstChild;for(;v;v=v.nextSibling){if(v==t){return true}}return false};return this.each(function(){if(window.Node&&Node.prototype&&!Node.prototype.contains){Node.prototype.contains=function(w){return !!(this.compareDocumentPosition(w)&16)}}if(!b(this).is(".trans_menu")){b(this).addClass("trans_menu")}b("ul",this).shadowBox();b(this).bind("closemenu",function(){p()});var t=b(this).children("li");for(var u=0;udiv").addClass("inner");if(a.arrow_char){var v=b(""+a.arrow_char+"");if(b.browser.mozilla&&+b.browser.version.replace(/\./g,"").slice(0,3)<191){v.css("margin-top","-13px")}b("div.inner div.outerbox",this).before(v)}b(this).wrap('
').after('
')})};b.fn.transMenu.setDefaults=function(d){b.extend(c,d)};b.fn.shadowBox=function(){return this.each(function(){var d=b('
').get(0);if(b(this).css("position")=="absolute"){b(d).css({position:"relative",width:this.offsetWidth,height:this.offsetHeight})}else{b(d).css("position","absolute")}b(this).addClass("innerBox").wrap(d).before('
')})};b.fn.selectMenuItem=function(){if(this.find("span.selected").length==0){this.prepend(b(""+a.selected_char+""))}return this};b.fn.deselectMenuItem=function(){return this.find("span.selected").remove()};b.fn.menuItemIsSelected=function(){return(this.find("span.selected").length>0)};b.fn.deselectMenuSiblings=function(){this.parent().find("span.selected").remove();this.selectMenuItem();return this}})(jQuery); \ No newline at end of file