view NCBI Blast reference example_files/jquery.js @ 32:ce8f29efc0a1

fix tests
author Jan Kanis <jan.code@jankanis.nl>
date Thu, 15 May 2014 17:22:02 +0200
parents 344cd76f6fd2
children
line wrap: on
line source

jQuery.widget("ui.ncbimenu",{options:{isSubMenuLimited:false,delayTimeout:500,useHoverEvents:true},_create:function(){this._addClasses();this._addAria();this._createMenus();this._addListeners();this._addEvents();this._addAjaxEvents()},rescan:function(){this._destroyListeners();this._destroyEvents();this._addAria();this._createMenus();this._addListeners();this._addEvents()},destroy:function(){this._destroyEvents();this._destroyClasses();this._destroyAria();this._destroyListeners();this._destroyMenus()},
_addClasses:function(){this.element.addClass("ui-ncbimenu")},_destroyClasses:function(){this.element.removeClass("ui-ncbimenu")},_addAria:function(){this.element.attr("role","menubar").find("li").filter(":has(ul)").find("a").attr("aria-haspopup","true").end().find("ul").attr("aria-hidden","true")},_destroyAria:function(){this.element.removeAttr("role").find("li").removeAttr("role").filter(":has(ul)").find("a").removeAttr("aria-haspopup").removeAttr("role").end().find("ul").removeAttr("aria-hidden").removeAttr("role")},
_createMenus:function(){this.element.ncbibasicmenu({orientation:"horizontal"});var a=this.element.find(">li:has(>ul)");a.find(">a").addClass("expandDown");a.find(">ul").ncbibasicmenu({nested:true});if(!this.options.isSubMenuLimited){a.find(">ul ul").ncbibasicmenu({nested:true});a.find(">ul ul").parent().find(">a").addClass("expandRight")}},_destroyMenus:function(){this.element.removeClass("jig-ncbimenu cf ui-ncbibasicmenu orientation_hort").find("ul").andSelf().show().ncbibasicmenu("destroy")},_addEvents:function(){var a=
this;this._windowClickFnc=function(b){b=b.target||b.srcElement;a.element[0]===b||a.element.find(b).length===1||a.closeSub(a.element.find("ul"))};jQuery(window).on("click",this._windowClickFnc);this._unselectEverythingFnc=function(){a._unselectEverything()};this.element.find("li").not(":has(ul)").find("a").on("click",this._unselectEverythingFnc);this._blurFnc=function(){a._checkFocus()};this.element.on("blur","a",this._blurFnc);if(this.options.useHoverEvents){var d={timeout:this.options.delayTimeout,
over:function(){if(a._isActive){var b=jQuery(this),c=b.parent();if(c.has("ul").length===0){c=c.siblings("li.selected").removeClass("selected");a.closeSub(c);b.focus()}else c.hasClass("selected")||b.focus().click()}},out:function(){}};this.element.find(">li:not(:has(ul))>a,li:has(ul)>a").hoverIntent(d)}},_destroyEvents:function(){jQuery(window).off("click",this._windowClickFnc);this._windowClickFnc=null;this.element.off("blur","a",this._blurFnc);this._blurFnc=null;this.element.find(">li:not(:has(ul))>a,li:has(ul)>a").unbind("mouseover mouseoff");
this.element.find("li").not(":has(ul)").find("a").off("click",this._unselectEverythingFnc)},_addAjaxEvents:function(){if(this.element.find(">li:has(a.expandDown)").not(":has(ul)").length>0){var a=this;this._ajaxEnterFnc=function(){a._loadAjaxContent()};this.element.on("mouseenter",this._ajaxEnterFnc)}},_loadAjaxContent:function(){var a=this;this.element.off("mouseenter",this._ajaxEnterFnc);this._ajaxEnterFnc=null;var d=this.element.find("a.expandDown"),b=d.eq(0).prop("href").split("#");jQuery("<div/>").load(b[0],
function(){a._handleAjaxLoadCallback(this,d)})},_handleAjaxLoadCallback:function(a,d){var b=jQuery(a);d.each(function(){var c=jQuery(this),e=c.prop("href").split("#")[1];e=b.find("#"+e);if(e[0].tagName.toLowerCase()==="li")e=e.find(">ul");c.parent().append(e)});this._createMenus();this._addEvents()},_checkFocus:function(){function a(){d.element.find("a:focus").length===0&&d._unselectEverything()}var d=this;window.setTimeout(a,10)},_addListeners:function(){var a=this;this.element.find(">ul").andSelf().on("ncbibasicmenuunselected",
function(d,b,c,e){e==="click"&&a.closeSub(c)}).on("ncbibasicmenuselected",function(d,b,c,e){if(e==="click")a.openSub(c);else{d=c.siblings().find("ul:visible");if(d.length>0){d.each(function(){a.closeSub(jQuery(this))});c.parent("ul").hasClass("ui-ncbimenu")&&a.openSub(c)}}}).on("ncbibasicmenuactiondown ncbibasicmenuactionright",function(d,b){b=jQuery(b);var c=b.find(">ul");if(b.hasClass("selected"))c.length===1&&c.not(":visible")&&a.openSub(b);else b.find(">a").click();c.length===1&&window.setTimeout(function(){c.ncbibasicmenu("selectFirstItem")},
10)}).on("ncbibasicmenuactionup ncbibasicmenuactionleft ncbibasicmenuescape",function(d,b){b=jQuery(b);d=b.find(">ul");if(d.length>0&&d.is(":visible"))a.closeSub(jQuery(b));else{b=b.parent("ul").parent("li");b.find(">a").focus();a.closeSub(b)}})},_destroyListeners:function(){this.element.find("ul").andSelf().off("ncbibasicmenuunselected").off("ncbibasicmenuselected")},openSub:function(a){var d=a.find(">ul");if(d.length===1){this._isActive=true;var b=a.parent().find("li:has(ul:visible)");b.length>
0&&this.closeSub(b);if(a.parent().hasClass("orientation_hort")){b="left bottom";var c="fit flip"}else{b="right center";c="flip fit"}d.show().position({of:a,my:"left top",at:b,collision:c}).attr("aria-hidden","false")}},closeSub:function(a){(a.is("li")?a.find("ul"):a).find("ul").andSelf().not(".ui-ncbimenu").hide().attr("aria-hidden","true").end().ncbibasicmenu("removeAllSelections").find("li.selected").removeClass("selected")},_unselectEverything:function(){this.closeSub(this.element.find("ul:visible").andSelf());
this._isActive=false}});