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

1 line
4.9 KiB
JavaScript

(function(a){var b={onClick:function(){a(this).find(">a").each(function(){this.href&&(window.location=this.href)})},arrow_char:"&#x25BA;",selected_char:"&#x2713;",subDelay:300,direction:"down",mainDelay:10},c;a.fn.transMenu=function(d){var e=!1,f=2;c=a.extend({},b,d);var g=function(b,d){if(b.timer&&!b.isVisible)clearTimeout(b.timer);else if(b.timer)return;b.isVisible&&(b.timer=setTimeout(function(){a(b).find("ul li").unbind("mouseover",k).unbind("mouseout",m).unbind("click",c.onClick),a(b).hide(),b.isVisible=!1,b.timer=null},d))},h=function(b,d){b.timer&&clearTimeout(b.timer),b.isVisible||(b.timer=setTimeout(function(){if(!a(b).parent().is(".hover"))return;a(b).find("ul li").mouseover(k).mouseout(m).click(c.onClick),a(b).parent().is(".main")||a(b).css("left",a(b).parent().parent().width()-f),c.direction=="up"&&a(b).css("top",a(b).height()*-1+a(b).parent().parent().height()),b.isVisible=!0,a(b).show(),b.timer=null},d))},i=function(a){var b=(a.type=="mouseover"?a.fromElement:a.toElement)||a.relatedTarget;while(b&&b!=this)try{b=b.parentNode}catch(a){b=this}return b==this?!1:!0},j=function(b){a(this).addClass("hover").siblings("li.hover").removeClass("hover"),e&&l(this,c.mainDelay)},k=function(a){if(!i(a))return!1;if(a.target!=this&&!s(this,a.target))return;l(this,c.subDelay)},l=function(b,c){var d=b.parentNode.firstChild;for(;d;d=d.nextSibling)if(d.nodeType==1&&d.nodeName.toUpperCase()=="LI"){var e=r(d,"DIV");e&&e.timer&&!e.isVisible&&(clearTimeout(e.timer),e.timer=null)}var f=b.parentNode;for(;f;f=f.parentNode)f.nodeType==1&&f.nodeName.toUpperCase()=="DIV"&&f.timer&&(clearTimeout(f.timer),f.timer=null,a(f.parentNode).addClass("hover"));a(b).addClass("hover");var i=a(b).children("div");i=i.length?i[0]:null;if(i&&i.isVisible)if(i.timer)clearTimeout(i.timer),i.timer=null;else return;a(b.parentNode.getElementsByTagName("DIV")).each(function(){this!=i&&this.isVisible&&(g(this,c),a(this.parentNode).removeClass("hover"))}),i&&h(i,c)},m=function(b){if(!i(b))return!1;if(b.target!=this&&!s(this,b.target))return;var c=r(this,"DIV");c?c.isVisible||a(this).removeClass("hover"):a(this).removeClass("hover")},n=function(b){var c=r(this,"DIV"),d=b.relatedTarget||b.toElement,f;e?!c&&d?(f=a(b.target).parents("UL.trans_menu"),f.contains(d)&&a(this).removeClass("hover")):d&&(f=a(b.target).parents("UL.trans_menu"),!c.isVisible&&f.contains(d)&&a(this).removeClass("hover")):a(this).removeClass("hover")},o=function(){var b=r(this,"DIV");b&&b.isVisible?(q(),a(this).addClass("hover")):(l(this,c.mainDelay),e=!0,a("ul.trans_menu li").addClass("active"),a(document).bind("mousedown",p))},p=function(b){var c=!1;a(b.target).parents("UL.trans_menu").find("div").each(function(){this.isVisible&&(c=!0)}),c||q()},q=function(){a("ul.trans_menu div.outerbox").each(function(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.isVisible&&(a(this).hide(),this.isVisible=!1)}),a("ul.trans_menu li").removeClass("hover"),a("ul.trans_menu>li li").unbind("mouseover",k).unbind("mouseout",m).unbind("click",c.onClick),a(document).unbind("mousedown",p),e=!1,a("ul.trans_menu li").removeClass("active")},r=function(a,b){if(!a)return null;var c=a.firstChild;for(;c;c=c.nextSibling)if(c.nodeType==1&&c.nodeName.toUpperCase()==b)return c;return null},s=function(a,b){var c=a.firstChild;for(;c;c=c.nextSibling)if(c==b)return!0;return!1};return this.each(function(){window.Node&&Node.prototype&&!Node.prototype.contains&&(Node.prototype.contains=function(a){return!!(this.compareDocumentPosition(a)&16)}),a(this).is(".trans_menu")||a(this).addClass("trans_menu"),a("ul",this).shadowBox(),a(this).bind("closemenu",function(){q()});var b=a(this).children("li");for(var d=0;d<b.length;d++)r(r(r(b[d],"DIV"),"UL"),"LI")&&a(b[d]).click(o);a(b).hover(j,n).addClass("main").find(">div").addClass("inner");if(c.arrow_char){var e=a("<span class='arrow'>"+c.arrow_char+"</span>");a.browser.mozilla&&+a.browser.version.replace(/\./g,"").slice(0,3)<191&&e.css("margin-top","-13px"),a("div.inner div.outerbox",this).before(e)}a(this).wrap('<div class="main_container"></div>').after('<div style="clear: both; visibility: hidden;"></div>')})},a.fn.transMenu.setDefaults=function(c){a.extend(b,c)},a.fn.shadowBox=function(){return this.each(function(){var b=a('<div class="outerbox"></div>').get(0);a(this).css("position")=="absolute"?a(b).css({position:"relative",width:this.offsetWidth,height:this.offsetHeight}):a(b).css("position","absolute"),a(this).addClass("innerBox").wrap(b).before('<div class="shadowbox1"></div><div class="shadowbox2"></div><div class="shadowbox3"></div>')})},a.fn.selectMenuItem=function(){return this.find("span.selected").length==0&&this.prepend(a("<span class='selected'>"+c.selected_char+"</span>")),this},a.fn.deselectMenuItem=function(){return this.find("span.selected").remove()},a.fn.menuItemIsSelected=function(){return this.find("span.selected").length>0},a.fn.deselectMenuSiblings=function(){return this.parent().find("span.selected").remove(),this.selectMenuItem(),this}})(jQuery)