diff --git a/bower.json b/bower.json index b9d0374..659f31d 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "select", "main": "select.js", - "version": "0.3.1", + "version": "0.4.0", "homepage": "https://github.com/HubSpot/select", "authors": [ "Zack Bloom ", diff --git a/package.json b/package.json index 79a3c96..0116ecc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "select", - "version": "0.3.1", + "version": "0.4.0", "description": "Styleable select elements built on Tether", "authors": [ "Adam Schwartz ", diff --git a/select.js b/select.js index 1f45add..5eac133 100644 --- a/select.js +++ b/select.js @@ -1,4 +1,4 @@ -/*! select 0.3.1 */ +/*! select 0.4.0 */ /*! tether 0.3.4 */ (function() { var Evented, addClass, extend, getBounds, getOffsetParent, getScrollParent, hasClass, removeClass, diff --git a/select.min.js b/select.min.js index 2280e95..f2cec23 100644 --- a/select.min.js +++ b/select.min.js @@ -1,2 +1,2 @@ -/*! select 0.3.1 */ +/*! select 0.4.0 */ (function(){var t,e,o,i,n,s,r,l,h={}.hasOwnProperty,a=[].slice;null==window.Tether&&(window.Tether={}),s=function(t){var e,o,i,n,s;if(o=getComputedStyle(t).position,"fixed"===o)return t;for(i=void 0,e=t;e=e.parentNode;){if(!(n=getComputedStyle(e)))return e;if(/(auto|scroll)/.test(n.overflow+n["overflow-y"]+n["overflow-x"])&&("absolute"!==o||"relative"===(s=n.position)||"absolute"===s||"fixed"===s))return e}return document.body},i=function(t){var e,i,n;return t===document?(i=document,t=document.documentElement):i=t.ownerDocument,n=i.documentElement,e=o({},t.getBoundingClientRect()),e.top=e.top+window.pageYOffset-n.clientTop,e.left=e.left+window.pageXOffset-n.clientLeft,e.right=i.body.clientWidth-e.width-e.left,e.bottom=i.body.clientHeight-e.height-e.top,e},n=function(t){return t.offsetParent||document.documentElement},o=function(t){var e,o,i,n,s,r,l;for(null==t&&(t={}),e=[],Array.prototype.push.apply(e,arguments),l=e.slice(1),s=0,r=l.length;r>s;s++)if(i=l[s])for(o in i)h.call(i,o)&&(n=i[o],t[o]=n);return t},l=function(t,e){var o,i,n,s,r;if(null!=t.classList){for(s=e.split(" "),r=[],i=0,n=s.length;n>i;i++)o=s[i],r.push(t.classList.remove(o));return r}return t.className=t.className.replace(new RegExp("(^| )"+e.split(" ").join("|")+"( |$)","gi")," ")},e=function(t,e){var o,i,n,s,r;if(null!=t.classList){for(s=e.split(" "),r=[],i=0,n=s.length;n>i;i++)o=s[i],r.push(t.classList.add(o));return r}return l(t,e),t.className+=" "+e},r=function(t,e){return null!=t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className)},t=function(){function t(){}return t.prototype.on=function(t,e,o,i){var n;return null==i&&(i=!1),null==this.bindings&&(this.bindings={}),null==(n=this.bindings)[t]&&(n[t]=[]),this.bindings[t].push({handler:e,ctx:o,once:i})},t.prototype.once=function(t,e,o){return this.on(t,e,o,!0)},t.prototype.off=function(t,e){var o,i,n;if(null!=(null!=(i=this.bindings)?i[t]:void 0)){if(null==e)return delete this.bindings[t];for(o=0,n=[];oe;e++)t=O[e],i.push(t.position());return i},g=null,x=["resize","scroll"],T=0,E=x.length;E>T;T++)h=x[T],window.addEventListener(h,function(){return null==g||new Date-g>16?(g=+new Date,y()):void 0});t={center:"center",left:"right",right:"left"},e={middle:"middle",top:"bottom",bottom:"top"},o={top:0,left:0,middle:"50%",center:"50%",bottom:"100%",right:"100%"},r=function(o,i){var n,s;return n=o.left,s=o.top,"auto"===n&&(n=t[i.left]),"auto"===s&&(s=e[i.top]),{left:n,top:s}},s=function(t){var e,i;return{left:null!=(e=o[t.left])?e:t.left,top:null!=(i=o[t.top])?i:t.top}},n=function(){var t,e,o,i,n,s,r;for(e=1<=arguments.length?L.call(arguments,0):[],o={top:0,left:0},n=0,s=e.length;s>n;n++)r=e[n],i=r.top,t=r.left,"string"==typeof i&&(i=parseFloat(i,10)),"string"==typeof t&&(t=parseFloat(t,10)),o.top+=i,o.left+=t;return o},m=function(t,e){return"string"==typeof t.left&&-1!==t.left.indexOf("%")&&(t.left=parseFloat(t.left,10)/100*e.width),"string"==typeof t.top&&-1!==t.top.indexOf("%")&&(t.top=parseFloat(t.top,10)/100*e.height),t},v=b=function(t){var e,o,i;return i=t.split(" "),o=i[0],e=i[1],{top:o,left:e}},w=function(){function t(t){this.position=H(this.position,this);var e,o,i,n,s;for(O.push(this),this.history=[],this.setOptions(t,!1),n=Tether.modules,o=0,i=n.length;i>o;o++)e=n[o],null!=(s=e.initialize)&&s.call(this);this.position()}return t.modules=[],t.prototype.getClass=function(t){var e,o;return(null!=(e=this.options.classes)?e[t]:void 0)?this.options.classes[t]:(null!=(o=this.options.classes)?o[t]:void 0)!==!1?this.options.classPrefix?""+this.options.classPrefix+"-"+t:t:""},t.prototype.setOptions=function(t,e){var o,n,s,r,l,h;for(this.options=t,null==e&&(e=!0),o={offset:"0 0",targetOffset:"0 0",targetAttachment:"auto auto",classPrefix:"tether"},this.options=a(o,this.options),l=this.options,this.element=l.element,this.target=l.target,this.targetModifier=l.targetModifier,"viewport"===this.target?(this.target=document.body,this.targetModifier="visible"):"scroll-handle"===this.target&&(this.target=document.body,this.targetModifier="scroll-handle"),h=["element","target"],s=0,r=h.length;r>s;s++){if(n=h[s],null==this[n])throw new Error("Tether Error: Both element and target must be defined");null!=this[n].jquery?this[n]=this[n][0]:"string"==typeof this[n]&&(this[n]=document.querySelector(this[n]))}if(i(this.element,this.getClass("element")),i(this.target,this.getClass("target")),!this.options.attachment)throw new Error("Tether Error: You must provide an attachment");return this.targetAttachment=v(this.options.targetAttachment),this.attachment=v(this.options.attachment),this.offset=b(this.options.offset),this.targetOffset=b(this.options.targetOffset),null!=this.scrollParent&&this.disable(),this.scrollParent=f(this.target),this.options.enabled!==!1?this.enable(e):void 0},t.prototype.getTargetBounds=function(){if(null==this.targetModifier)return p(this.target);switch(this.targetModifier){case"visible":return{top:pageYOffset,left:pageXOffset,height:innerHeight,width:innerWidth};case"scroll-handle":return{top:pageYOffset+innerHeight*(pageYOffset/document.body.scrollHeight),left:innerWidth-15,height:.98*innerHeight*(innerHeight/document.body.scrollHeight),width:15}}},t.prototype.clearCache=function(){return this._cache={}},t.prototype.cache=function(t,e){return null==this._cache&&(this._cache={}),null==this._cache[t]&&(this._cache[t]=e.call(this)),this._cache[t]},t.prototype.enable=function(t){return null==t&&(t=!0),this.addClass(this.getClass("enabled")),this.enabled=!0,this.scrollParent.addEventListener("scroll",this.position),t?this.position():void 0},t.prototype.disable=function(){return this.removeClass(this.getClass("enabled")),this.enabled=!1,null!=this.scrollParent?this.scrollParent.removeEventListener("scroll",this.position):void 0},t.prototype.destroy=function(){var t,e,o,i,n;for(this.disable(),n=[],t=o=0,i=O.length;i>o;t=++o){if(e=O[t],e===this){O.splice(t,1);break}n.push(void 0)}return n},t.prototype.updateAttachClasses=function(t,e){var o,i,n,s,r,l;for(null==t&&(t=this.attachment),null==e&&(e=this.targetAttachment),i=["left","top","bottom","right","middle","center"],n=0,r=i.length;r>n;n++)o=i[n],this.removeClass(""+this.getClass("element-attached")+"-"+o);for(t.top&&this.addClass(""+this.getClass("element-attached")+"-"+t.top),t.left&&this.addClass(""+this.getClass("element-attached")+"-"+t.left),s=0,l=i.length;l>s;s++)o=i[s],this.removeClass(""+this.getClass("target-attached")+"-"+o);return e.top&&this.addClass(""+this.getClass("target-attached")+"-"+e.top),e.left?this.addClass(""+this.getClass("target-attached")+"-"+e.left):void 0},t.prototype.addClass=function(t){return i(this.element,t),i(this.target,t)},t.prototype.removeClass=function(t){return C(this.element,t),C(this.target,t)},t.prototype.position=function(){var t,e,o,i,l,h,a,c,f,d,g,v,b,y,C,O,w,T,E,S,x,L,H,A,P,k,B,N,q,D,M=this;if(this.enabled){for(this.clearCache(),T=r(this.targetAttachment,this.attachment),this.updateAttachClasses(this.attachment,T),t=this.cache("element-bounds",function(){return p(M.element)}),H=t.width,e=t.height,x=S=this.cache("target-bounds",function(){return M.getTargetBounds()}),c=m(s(this.attachment),{width:H,height:e}),E=m(s(T),x),i=m(this.offset,{width:H,height:e}),l=m(this.targetOffset,x),c=n(c,i),o=S.left+E.left-c.left,L=S.top+E.top-c.top,N=Tether.modules,A=0,k=N.length;k>A;A++)if(h=N[A],y=h.position.call(this,{left:o,top:L,targetAttachment:T,targetPos:S,elementPos:t,offset:c,targetOffset:E,manualOffset:i,manualTargetOffset:l}),null!=y&&"object"==typeof y){if(y===!1)return!1;L=y.top,o=y.left}if(a={page:{top:L,bottom:document.body.scrollHeight-L-e,left:o,right:document.body.scrollWidth-o-H},viewport:{top:L-pageYOffset,bottom:pageYOffset-L-e+innerHeight,left:o-pageXOffset,right:pageXOffset-o-H+innerWidth}},(null!=(q=this.options.optimizations)?q.moveElement:void 0)!==!1&&null==this.targetModifier){for(d=this.cache("target-offsetparent",function(){return u(M.target)}),b=this.cache("target-offsetparent-bounds",function(){return p(d)}),v=getComputedStyle(d),g=b,f={},D=["top","left","bottom","right"],P=0,B=D.length;B>P;P++)w=D[P],f[w]=parseFloat(v["border-"+w+"-width"]);b.left+=f.left,b.top+=f.top,b.right=document.body.scrollWidth-b.left-g.width,b.bottom=document.body.scrollHeight-b.top-g.height,a.page.top>=b.top&&a.page.bottom>=b.bottom&&a.page.left>=b.left&&a.page.right>=b.right&&(O=d.scrollTop,C=d.scrollLeft,a.offset={top:a.page.top-b.top+O+f.top,left:a.page.left-b.left+C+f.left,right:a.page.right-b.right+d.scrollWidth-C+f.right,bottom:a.page.bottom-b.bottom+d.scrollHeight-O+f.bottom})}return this.move(a),this.history.unshift(a),this.history.length>3&&this.history.pop(),!0}},t.prototype.move=function(t){var e,o,i,n,s,r,l,h,p,c,f,d,g,m,v,b,y,C,O,w,T,E=this;if(null!=this.element.parentNode){p={};for(d in t){p[d]={};for(i in t[d]){for(o=!1,O=this.history,v=0,y=O.length;y>v;v++)if(h=O[v],(null!=(w=h[d])?w[i]:void 0)!==t[d][i]){o=!0;break}o||(p[d][i]=!0)}}if(e={top:"",left:"",right:"",bottom:""},f=function(t,o){return t.top?e.top=""+o.top+"px":e.bottom=""+o.bottom+"px",t.left?e.left=""+o.left+"px":e.right=""+o.right+"px"},n=!1,(p.page.top||p.page.bottom)&&(p.page.left||p.page.right))e.position="absolute",f(p.page,t.page);else if((p.viewport.top||p.viewport.bottom)&&(p.viewport.left||p.viewport.right))e.position="fixed",f(p.viewport,t.viewport);else if(null!=p.offset&&(p.offset.top||p.offset.bottom)&&(p.offset.left||p.offset.right)){for(e.position="absolute",r=this.cache("target-offsetparent",function(){return u(E.target)}),u(this.element)!==r&&(this.element.parentNode.removeChild(this.element),r.appendChild(this.element)),l=getComputedStyle(r),s=a({},t.offset),T=["top","left","bottom","right"],b=0,C=T.length;C>b;b++)c=T[b],s[c]-=parseFloat(l["border-"+c+"-width"]);f(p.offset,s),n=!0}else e.position="absolute",e.top=""+t.page.top+"px",e.left=""+t.page.left+"px";n||"BODY"===this.element.parentNode.tagName||(this.element.parentNode.removeChild(this.element),document.body.appendChild(this.element)),m=!1;for(i in e)if(g=e[i],this.element.style[i]!==g){m=!0;break}return m?a(this.element.style,e):void 0}},t}(),window.Tether=a(w,Tether)}.call(this),function(){var t,e,o,i,n,s,r,l,h=[].indexOf||function(t){for(var e=0,o=this.length;o>e;e++)if(e in this&&this[e]===t)return e;return-1};l=Tether.Utils,s=l.getOuterSize,n=l.getBounds,r=l.getSize,o=l.extend,e={left:"right",right:"left",top:"bottom",bottom:"top",middle:"middle"},t=["left","top","right","bottom"],i=function(e,o){var i,s,r,l,h,a,p;if("scrollParent"===o?o=e.scrollParent:"window"===o&&(o=[pageXOffset,pageYOffset,innerWidth+pageXOffset,innerHeight+pageYOffset]),o===document&&(o=o.documentElement),null!=o.nodeType)for(s=l=n(o),h=getComputedStyle(o),o=[s.left,s.top,l.width+s.left,l.height+s.top],i=a=0,p=t.length;p>a;i=++a)r=t[i],"top"===r||"left"===r?o[i]+=parseFloat(h["border-"+r+"-width"]):o[i]-=parseFloat(h["border-"+r+"-width"]);return o},Tether.modules.push({position:function(e){var s,r,l,a,p,u,c,f,d,g,m,v,b,y,C,O,w,T,E,S,x,L,H,A,P,k,B,N,q,D,M,F,Y,_,W,z,j,X,I,U,R,V,$=this;if(P=e.top,d=e.left,S=e.targetAttachment,!this.options.constraints)return!0;for(O=function(e){var o,i,n,s;for($.removeClass(e),s=[],i=0,n=t.length;n>i;i++)o=t[i],s.push($.removeClass(""+e+"-"+o));return s},j=this.cache("element-bounds",function(){return n($.element)}),f=j.height,k=j.width,L=this.cache("target-bounds",function(){return $.getTargetBounds()}),x=L.height,H=L.width,E={},c={},w=[this.getClass("pinned"),this.getClass("out-of-bounds")],X=this.options.constraints,B=0,M=X.length;M>B;B++)u=X[B],u.outOfBoundsClass&&w.push(u.outOfBoundsClass),u.pinnedClass&&w.push(u.pinnedClass);for(N=0,F=w.length;F>N;N++)p=w[N],O(p);for(E=o({},S),c=o({},this.attachment),I=this.options.constraints,q=0,Y=I.length;Y>q;q++){if(u=I[q],A=u.to,s=u.attachment,b=u.pin,null==s&&(s=""),h.call(s," ")>=0?(U=s.split(" "),a=U[0],l=U[1]):l=a=s,r=i(this,A),("target"===a||"both"===a)&&(Pr[3]&&"bottom"===E.top&&(P-=x,E.top="top")),"together"===a&&(Pr[3]&&"bottom"===E.top&&("top"===c.top?(P-=x,E.top="top",P-=f,c.top="bottom"):"bottom"===c.top&&(P-=x,E.top="top",P+=f,c.top="top"))),("target"===l||"both"===l)&&(dr[2]&&"right"===E.left&&(d-=H,E.left="left")),"together"===l&&(dr[2]&&"right"===E.left&&("left"===c.left?(d-=H,E.left="left",d-=k,c.left="right"):"right"===c.left&&(d-=H,E.left="left",d+=k,c.left="left"))),("element"===a||"both"===a)&&(Pr[3]&&"top"===c.top&&(P-=f,c.top="bottom")),("element"===l||"both"===l)&&(dr[2]&&"left"===c.left&&(d-=k,c.left="right")),"string"==typeof b?b=function(){var t,e,o,i;for(o=b.split(","),i=[],t=0,e=o.length;e>t;t++)v=o[t],i.push(v.trim());return i}():b===!0&&(b=["top","left","right","bottom"]),b||(b=[]),y=[],g=[],P=0?(P=r[1],y.push("top")):g.push("top")),P+f>r[3]&&(h.call(b,"bottom")>=0?(P=r[3]-f,y.push("bottom")):g.push("bottom")),d=0?(d=r[0],y.push("left")):g.push("left")),d+k>r[2]&&(h.call(b,"right")>=0?(d=r[2]-k,y.push("right")):g.push("right")),y.length)for(C=null!=(R=this.options.pinnedClass)?R:this.getClass("pinned"),this.addClass(C),D=0,_=y.length;_>D;D++)T=y[D],this.addClass(""+C+"-"+T);if(g.length)for(m=null!=(V=this.options.outOfBoundsClass)?V:this.getClass("out-of-bounds"),this.addClass(m),z=0,W=g.length;W>z;z++)T=g[z],this.addClass(""+m+"-"+T);(h.call(y,"left")>=0||h.call(y,"right")>=0)&&(c.left=E.left=!1),(h.call(y,"top")>=0||h.call(y,"bottom")>=0)&&(c.top=E.top=!1),(E.top!==S.top||E.left!==S.left||c.top!==this.attachment.top||c.left!==this.attachment.left)&&this.updateAttachClasses(c,E)}return{top:P,left:d}}})}.call(this),function(){var t;t=Tether.Utils.getBounds,Tether.modules.push({position:function(e){var o,i,n,s,r,l,h,a,p,u,c,f,d,g,m,v,b,y,C,O,w,T,E,S=this;if(p=e.top,s=e.left,C=this.cache("element-bounds",function(){return t(S.element)}),n=C.height,u=C.width,a=this.getTargetBounds(),i=p+n,r=s+u,o=[],p<=a.bottom&&i>=a.top)for(O=["left","right"],c=0,m=O.length;m>c;c++)l=O[c],((w=a[l])===s||w===r)&&o.push(l);if(s<=a.right&&r>=a.left)for(T=["top","bottom"],f=0,v=T.length;v>f;f++)l=T[f],((E=a[l])===p||E===i)&&o.push(l);for(h=["left","top","right","bottom"],this.removeClass(this.getClass("abutted")),d=0,b=h.length;b>d;d++)l=h[d],this.removeClass(""+this.getClass("abutted")+"-"+l);for(o.length&&this.addClass(this.getClass("abutted")),g=0,y=o.length;y>g;g++)l=o[g],this.addClass(""+this.getClass("abutted")+"-"+l);return!0}})}.call(this),function(){Tether.modules.push({position:function(t){var e,o,i,n,s,r,l;return r=t.top,e=t.left,this.options.shift?(o=function(t){return"function"==typeof t?t.call(this,{top:r,left:e}):t},i=o(this.options.shift),"string"==typeof i?(i=i.split(" "),i[1]||(i[1]=i[0]),s=i[0],n=i[1],s=parseFloat(s,10),n=parseFloat(n,10)):(l=[i.top,i.left],s=l[0],n=l[1]),r+=s,e+=n,{top:r,left:e}):void 0}})}.call(this),function(){var t,e,o,i,n,s,r,l,h,a,p,u,c,f,d,g,m,v,b,y,C,O={}.hasOwnProperty,w=function(t,e){function o(){this.constructor=t}for(var i in e)O.call(e,i)&&(t[i]=e[i]);return o.prototype=e.prototype,t.prototype=new o,t.__super__=e.prototype,t};C=Tether.Utils,a=C.extend,l=C.addClass,g=C.removeClass,c=C.hasClass,p=C.getBounds,i=C.Evented,e=13,o=27,n=32,r=38,t=40,b="ontouchstart"in document.documentElement,h=b?"touchstart":"click",y=function(){return b&&(640>=innerWidth||640>=innerHeight)},f=function(t){return Array.prototype.reduce.call(t,function(t,e){return t===e?e:!1})},u=function(){var t;return null!=(t=document.querySelector(".select-target-focused"))?t.selectInstance:void 0},m="",v=void 0,d=void 0,document.addEventListener("keypress",function(t){var e,o,i,s;if((i=u())&&0!==t.charCode)return t.keyCode===n&&t.preventDefault(),clearTimeout(v),v=setTimeout(function(){return m=""},500),m+=String.fromCharCode(t.charCode),e=i.findOptionsByPrefix(m),1===e.length?(i.selectOption(e[0]),void 0):m.length>1&&f(m)&&(o=i.findOptionsByPrefix(m[0]),o.length)?(s=o.indexOf(i.getChosen()),s+=1,s%=o.length,i.selectOption(o[s]),void 0):(e.length&&i.selectOption(e[0]),void 0)}),document.addEventListener("keydown",function(i){var s,l,h;if(s=u())if(((l=i.keyCode)===r||l===t||l===o)&&i.preventDefault(),s.isOpen())switch(i.keyCode){case r:case t:return s.moveHighlight(i.keyCode);case e:return s.selectHighlightedOption();case o:return s.close(),s.target.focus()}else if((h=i.keyCode)===r||h===t||h===n)return s.open()}),s=function(t){function e(t){if(this.options=t,this.options=a({},e.defaults,this.options),this.select=this.options.el,null!=this.select.selectInstance)throw new Error("This element has already been turned into a Select");this.setupTarget(),this.renderTarget(),this.setupDrop(),this.renderDrop(),this.setupSelect(),this.setupTether(),this.bindClick(),this.value=this.select.value}return w(e,t),e.defaults={alignToHighlighed:"auto",className:"select-theme-default"},e.prototype.useNative=function(){return this.options.useNative===!0||y()&&this.options.useNative!==!1},e.prototype.setupTarget=function(){var t,e=this;return this.target=document.createElement("a"),this.target.href="javascript:;",l(this.target,"select-target"),t=this.select.getAttribute("tabindex")||0,this.target.setAttribute("tabindex",t),this.options.className&&l(this.target,this.options.className),this.target.selectInstance=this,this.target.addEventListener("click",function(){return e.isOpen()?e.target.blur():e.target.focus()}),this.target.addEventListener("focus",function(){return l(e.target,"select-target-focused")}),this.target.addEventListener("blur",function(t){return e.isOpen()?t.relatedTarget&&!e.drop.contains(t.relatedTarget)?e.close():void 0:g(e.target,"select-target-focused")}),this.select.parentNode.insertBefore(this.target,this.select.nextSibling)},e.prototype.setupDrop=function(){var t=this;return this.drop=document.createElement("div"),l(this.drop,"select"),this.options.className&&l(this.drop,this.options.className),document.body.appendChild(this.drop),this.drop.addEventListener("click",function(e){return c(e.target,"select-option")?t.pickOption(e.target):void 0}),this.drop.addEventListener("mousemove",function(e){return c(e.target,"select-option")?t.highlightOption(e.target):void 0}),this.content=document.createElement("div"),l(this.content,"select-content"),this.drop.appendChild(this.content)},e.prototype.open=function(){var t,e,o=this;return l(this.target,"select-open"),this.useNative()?(this.select.style.display="block",setTimeout(function(){var t;return t=document.createEvent("MouseEvents"),t.initEvent("mousedown",!0,!0),o.select.dispatchEvent(t)}),void 0):(l(this.drop,"select-open"),setTimeout(function(){return o.tether.enable()}),(e=this.drop.querySelector(".select-option-selected"))?(this.highlightOption(e),this.scrollDropContentToOption(e),t=function(){var t,i,n;return c(o.drop,"tether-abutted-left")||c(o.drop,"tether-abutted-bottom")?(t=p(o.drop),n=p(e),i=t.top-(n.top+n.height),o.drop.style.top=(parseFloat(o.drop.style.top)||0)+i+"px"):void 0},("always"===this.options.alignToHighlighted||"auto"===this.options.alignToHighlighted&&this.content.scrollHeight<=this.content.clientHeight)&&setTimeout(t),this.trigger("open")):void 0)},e.prototype.close=function(){return g(this.target,"select-open"),this.useNative()?(this.select.style.display="none",void 0):(this.tether.disable(),g(this.drop,"select-open"),this.trigger("close"))},e.prototype.toggle=function(){return this.isOpen()?this.close():this.open()},e.prototype.isOpen=function(){return c(this.drop,"select-open")},e.prototype.bindClick=function(){var t=this;return this.target.addEventListener(h,function(e){return e.preventDefault(),t.toggle()}),document.addEventListener(h,function(e){return!t.isOpen()||e.target===t.drop||t.drop.contains(e.target)||e.target===t.target||t.target.contains(e.target)?void 0:t.close()})},e.prototype.setupTether=function(){return this.tether=new Tether({element:this.drop,target:this.target,attachment:"top left",targetAttachment:"bottom left",classPrefix:"select",constraints:[{to:"window",pin:!0,attachment:"together"}]})},e.prototype.renderTarget=function(){var t,e,o,i;for(this.target.innerHTML="",i=this.select.querySelectorAll("option"),e=0,o=i.length;o>e;e++)if(t=i[e],t.selected){this.target.innerHTML=t.innerHTML;break}return this.target.appendChild(document.createElement("b"))},e.prototype.renderDrop=function(){var t,e,o,i,n,s;for(o=document.createElement("ul"),l(o,"select-options"),s=this.select.querySelectorAll("option"),i=0,n=s.length;n>i;i++)t=s[i],e=document.createElement("li"),l(e,"select-option"),e.setAttribute("data-value",t.value),e.innerHTML=t.innerHTML,t.selected&&l(e,"select-option-selected"),o.appendChild(e);return this.content.innerHTML="",this.content.appendChild(o)},e.prototype.setupSelect=function(){var t=this;return this.select.selectInstance=this,l(this.select,"select-select"),this.select.addEventListener("change",function(){return t.renderDrop(),t.renderTarget()})},e.prototype.findOptionsByPrefix=function(t){var e;return e=this.drop.querySelectorAll(".select-option"),t=t.toLowerCase(),Array.prototype.filter.call(e,function(e){return e.innerHTML.toLowerCase().substr(0,t.length)===t})},e.prototype.findOptionsByValue=function(t){var e;return e=this.drop.querySelectorAll(".select-option"),Array.prototype.filter.call(e,function(e){return e.getAttribute("data-value")===t})},e.prototype.getChosen=function(){return this.isOpen()?this.drop.querySelector(".select-option-highlight"):this.drop.querySelector(".select-option-selected")},e.prototype.selectOption=function(t){return this.isOpen()?(this.highlightOption(t),this.scrollDropContentToOption(t)):this.pickOption(t,!1)},e.prototype.resetSelection=function(){return this.selectOption(this.drop.querySelector(".select-option"))},e.prototype.highlightOption=function(t){var e;return e=this.drop.querySelector(".select-option-highlight"),null!=e&&g(e,"select-option-highlight"),l(t,"select-option-highlight"),this.trigger("highlight",{option:t})},e.prototype.moveHighlight=function(t){var e,o,i,n;return(e=this.drop.querySelector(".select-option-highlight"))?(n=this.drop.querySelectorAll(".select-option"),o=Array.prototype.indexOf.call(n,e),o>=0&&(t===r?o-=1:o+=1,!(0>o||o>=n.length))?(i=n[o],this.highlightOption(i),this.scrollDropContentToOption(i)):void 0):(this.highlightOption(this.drop.querySelector(".select-option")),void 0)},e.prototype.scrollDropContentToOption=function(t){var e,o;return this.content.scrollHeight>this.content.clientHeight?(e=p(this.content),o=p(t),this.content.scrollTop=o.top-(e.top-this.content.scrollTop)):void 0},e.prototype.selectHighlightedOption=function(){return this.pickOption(this.drop.querySelector(".select-option-highlight"))},e.prototype.pickOption=function(t,e){var o=this;return null==e&&(e=!0),this.value=this.select.value=t.getAttribute("data-value"),this.triggerChange(),e?setTimeout(function(){return o.close(),o.target.focus()}):void 0},e.prototype.triggerChange=function(){var t;return t=document.createEvent("HTMLEvents"),t.initEvent("change",!0,!1),this.select.dispatchEvent(t),this.trigger("change",{value:this.select.value})},e.prototype.change=function(t){var e;if(e=this.findOptionsByValue(t),!e.length)throw new Error('Select Error: An option with the value "'+t+"\" doesn't exist");return this.pickOption(e[0],!1)},e}(i),s.init=function(t){var e,o,i,n,r;if(null==t&&(t={}),"loading"===document.readyState)return document.addEventListener("DOMContentLoaded",function(){return s.init(t)}),void 0;for(null==t.selector&&(t.selector="select"),n=document.querySelectorAll(t.selector),r=[],o=0,i=n.length;i>o;o++)e=n[o],e.selectInstance?r.push(void 0):r.push(new s(a({el:e},t)));return r},window.Select=s}.call(this); \ No newline at end of file