/*! Menu - v0.1.4 - 2017-03-18 * https://github.com/filamentgroup/menu * Copyright (c) 2017 Scott Jehl; Licensed MIT */ window.jQuery=window.jQuery||window.shoestring,function(a,b){"use strict";var c="Menu",d={ariaHidden:"aria-hidden"},e="menu-selected",f="a,input,[tabindex]",g=function(b){if(!b)throw new Error("Element required to initialize object");this.element=b,this.$element=a(b),this.opened=!0};g.prototype.fill=function(b,c){var d="";a.each(b,function(a,b){d+=""+b+""}),this.$element.find("ol,ul").html(d)},g.prototype.moveSelected=function(c,d){var g,h=this.$element.find("li"),i=h.filter("."+e);if(i.length&&"start"!==c?"next"===c?(g=i.next(),g.length||(g=h.eq(0))):(g=i.prev(),g.length||(g=h.eq(h.length-1))):g=h.eq(0),i.removeClass(e),g.addClass(e),d||a(b.document.activeElement).closest(i).length)if(g.is(f))g[0].focus();else{var j=g.find(f);j.length&&j[0].focus()}},g.prototype.getSelectedElement=function(){return this.$element.find("li."+e)},g.prototype.selectActive=function(){var b=this.$element.data(c+"-trigger"),d=this.getSelectedElement();return b&&a(b).is("input")&&(b.value=d.text()),d.trigger(c+":select"),this.close(),d.text()},g.prototype.keycodes={38:function(a){this.moveSelected("prev"),a.preventDefault()},40:function(a){this.moveSelected("next"),a.preventDefault()},13:function(){return this.selectActive()},9:function(a){this.moveSelected(a.shiftKey?"prev":"next"),a.preventDefault()},27:function(){this.close()}},g.prototype.keyDown=function(a){var b=this.keycodes[a.keyCode]||function(){};return b.call(this,a)},g.prototype._bindKeyHandling=function(){var b=this;this.$element.bind("keydown",function(a){b.keyDown(a)}).bind("mouseover",function(c){b.$element.find("."+e).removeClass(e),a(c.target).closest("li").addClass(e)}).bind("mouseleave",function(b){a(b.target).closest("li").removeClass(e)}).bind("click",function(){b.selectActive()})},g.prototype.open=function(a,b){this.opened||(this.$element.attr(d.ariaHidden,!1),this.$element.data(c+"-trigger",a),this.opened=!0,this.moveSelected("start",b),this.$element.trigger(c+":open"))},g.prototype.close=function(){if(this.opened){this.$element.attr(d.ariaHidden,!0),this.opened=!1;var a=this.$element.data(c+"-trigger");a&&a.focus(),this.$element.trigger(c+":close")}},g.prototype.toggle=function(a,b){this[this.opened?"close":"open"](a,b)},g.prototype.init=function(){if(!this.$element.data(c)){this.$element.data(c,this),this.$element.attr("role","menu"),this.close();var b=this;a(document).bind("mouseup",function(c){a(c.target).closest(b.$element[0]).length||b.close()}),this._bindKeyHandling(),this.$element.trigger(c+":init")}},g.prototype.isOpen=function(){return this.opened},(b.componentNamespace=b.componentNamespace||b)[c]=g}(jQuery,this);