mirror of
https://github.com/transmission/transmission
synced 2024-12-25 17:17:31 +00:00
30 lines
No EOL
6.2 KiB
JavaScript
30 lines
No EOL
6.2 KiB
JavaScript
|
|
(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;j<liElems.length;j++){if(getOneChild(getOneChild(getOneChild(liElems[j],'DIV'),'UL'),'LI')){$(liElems[j]).click(mainClick);}}
|
|
$(liElems).hover(mainHoverIn,mainHoverOut).addClass('main').find('>div').addClass('inner');if(transMenuSettings.arrow_char){var arrow_markup=$("<span class='arrow'>"+transMenuSettings.arrow_char+'</span>');if($.browser.mozilla){arrow_markup.css('margin-top','-13px');}
|
|
$('div.inner div.outerbox',this).before(arrow_markup);}
|
|
$(this).wrap('<div class="main_container"></div>').after('<div style="clear: both; visibility: hidden;"></div>');});};$.fn.transMenu.setDefaults=function(o){$.extend(defaults,o);};$.fn.shadowBox=function(){return this.each(function(){var outer=$('<div class="outerbox"></div>').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('<div class="shadowbox1"></div><div class="shadowbox2"></div><div class="shadowbox3"></div>');});};$.fn.selectMenuItem=function(){if(this.find('span.selected').length==0){this.prepend($("<span class='selected'>"+transMenuSettings.selected_char+"</span>"));}
|
|
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); |