!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.tether=e()}(this,function(t,e,o){"use strict";function n(t,e){if(!(t instanceof e))throw new typeerror("cannot call a class as a function")}function i(t){var e=t.getboundingclientrect(),o={};for(var n in e)o[n]=e[n];if(t.ownerdocument!==document){var r=t.ownerdocument.defaultview.frameelement;if(r){var s=i(r);o.top+=s.top,o.bottom+=s.top,o.left+=s.left,o.right+=s.left}}return o}function r(t){var e=getcomputedstyle(t)||{},o=e.position,n=[];if("fixed"===o)return[t];for(var i=t;(i=i.parentnode)&&i&&1===i.nodetype;){var r=void 0;try{r=getcomputedstyle(i)}catch(s){}if("undefined"==typeof r||null===r)return n.push(i),n;var a=r,f=a.overflow,l=a.overflowx,h=a.overflowy;/(auto|scroll)/.test(f+h+l)&&("absolute"!==o||["relative","absolute","fixed"].indexof(r.position)>=0)&&n.push(i)}return n.push(t.ownerdocument.body),t.ownerdocument!==document&&n.push(t.ownerdocument.defaultview),n}function s(){a&&document.body.removechild(a),a=null}function a(t){var e=void 0;t===document?(e=document,t=document.documentelement):e=t.ownerdocument;var o=e.documentelement,n=i(t),r=p();return n.top-=r.top,n.left-=r.left,"undefined"==typeof n.width&&(n.width=document.body.scrollwidth-n.left-n.right),"undefined"==typeof n.height&&(n.height=document.body.scrollheight-n.top-n.bottom),n.top=n.top-o.clienttop,n.left=n.left-o.clientleft,n.right=e.body.clientwidth-n.width-n.left,n.bottom=e.body.clientheight-n.height-n.top,n}function f(t){return t.offsetparent||document.documentelement}function l(){var t=document.createelement("div");t.style.width="100%",t.style.height="200px";var e=document.createelement("div");h(e.style,{position:"absolute",top:0,left:0,pointerevents:"none",visibility:"hidden",width:"200px",height:"150px",overflow:"hidden"}),e.appendchild(t),document.body.appendchild(e);var o=t.offsetwidth;e.style.overflow="scroll";var n=t.offsetwidth;o===n&&(n=e.clientwidth),document.body.removechild(e);var i=o-n;return{width:i,height:i}}function h(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=[];return array.prototype.push.apply(e,arguments),e.slice(1).foreach(function(e){if(e)for(var o in e)({}).hasownproperty.call(e,o)&&(t[o]=e[o])}),t}function u(t,e){if("undefined"!=typeof t.classlist)e.split(" ").foreach(function(e){e.trim()&&t.classlist.remove(e)});else{var o=new regexp("(^| )"+e.split(" ").join("|")+"( |$)","gi"),n=c(t).replace(o," ");g(t,n)}}function d(t,e){if("undefined"!=typeof t.classlist)e.split(" ").foreach(function(e){e.trim()&&t.classlist.add(e)});else{u(t,e);var o=c(t)+(" "+e);g(t,o)}}function p(t,e){if("undefined"!=typeof t.classlist)return t.classlist.contains(e);var o=c(t);return new regexp("(^| )"+e+"( |$)","gi").test(o)}function c(t){return t.classname instanceof t.ownerdocument.defaultview.svganimatedstring?t.classname.baseval:t.classname}function g(t,e){t.setattribute("class",e)}function m(t,e,o){o.foreach(function(o){-1===e.indexof(o)&&p(t,o)&&u(t,o)}),e.foreach(function(e){p(t,e)||d(t,e)})}function n(t,e){if(!(t instanceof e))throw new typeerror("cannot call a class as a function")}function v(t,e){if("function"!=typeof e&&null!==e)throw new typeerror("super expression must either be null or a function, not "+typeof e);t.prototype=object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(object.setprototypeof?object.setprototypeof(t,e):t.__proto__=e)}function y(t,e){var o=arguments.length<=2||void 0===arguments[2]?1:arguments[2];return t+o>=e&&e>=t-o}function b(){return"undefined"!=typeof performance&&"undefined"!=typeof performance.now?performance.now():+new date}function w(){for(var t={top:0,left:0},e=arguments.length,o=array(e),n=0;e>n;n++)o[n]=arguments[n];return o.foreach(function(e){var o=e.top,n=e.left;"string"==typeof o&&(o=parsefloat(o,10)),"string"==typeof n&&(n=parsefloat(n,10)),t.top+=o,t.left+=n}),t}function c(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}function o(t,e){return"scrollparent"===e?e=t.scrollparents[0]:"window"===e&&(e=[pagexoffset,pageyoffset,innerwidth+pagexoffset,innerheight+pageyoffset]),e===document&&(e=e.documentelement),"undefined"!=typeof e.nodetype&&!function(){var t=e,o=a(e),n=o,i=getcomputedstyle(e);if(e=[n.left,n.top,o.width+n.left,o.height+n.top],t.ownerdocument!==document){var r=t.ownerdocument.defaultview;e[0]+=r.pagexoffset,e[1]+=r.pageyoffset,e[2]+=r.pagexoffset,e[3]+=r.pageyoffset}$.foreach(function(t,o){t=t[0].touppercase()+t.substr(1),"top"===t||"left"===t?e[o]+=parsefloat(i["border"+t+"width"]):e[o]-=parsefloat(i["border"+t+"width"])})}(),e}var e=function(){function t(t,e){for(var o=0;o1?o-1:0),i=1;o>i;i++)n[i-1]=arguments[i];for(;e16?(e=math.min(e-16,250),void(o=settimeout(i,250))):void("undefined"!=typeof t&&b()-t<10||(null!=o&&(cleartimeout(o),o=null),t=b(),d(),e=b()-t))};"undefined"!=typeof window&&"undefined"!=typeof window.addeventlistener&&["resize","scroll","touchmove"].foreach(function(t){window.addeventlistener(t,n)})}();var x={center:"center",left:"right",right:"left"},f={middle:"middle",top:"bottom",bottom:"top"},h={top:0,left:0,middle:"50%",center:"50%",bottom:"100%",right:"100%"},n=function(t,e){var o=t.left,n=t.top;return"auto"===o&&(o=x[e.left]),"auto"===n&&(n=f[e.top]),{left:o,top:n}},u=function(t){var e=t.left,o=t.top;return"undefined"!=typeof h[t.left]&&(e=h[t.left]),"undefined"!=typeof h[t.top]&&(o=h[t.top]),{left:e,top:o}},v=function(t){var e=t.split(" "),o=b(e,2),n=o[0],i=o[1];return{top:n,left:i}},r=v,q=function(t){function e(t){var o=this;n(this,e),z(object.getprototypeof(e.prototype),"constructor",this).call(this),this.position=this.position.bind(this),l.push(this),this.history=[],this.setoptions(t,!1),x.modules.foreach(function(t){"undefined"!=typeof t.initialize&&t.initialize.call(o)}),this.position()}return v(e,t),e(e,[{key:"getclass",value:function(){var t=arguments.length<=0||void 0===arguments[0]?"":arguments[0],e=this.options.classes;return"undefined"!=typeof e&&e[t]?this.options.classes[t]:this.options.classprefix?this.options.classprefix+"-"+t:t}},{key:"setoptions",value:function(t){var e=this,o=arguments.length<=1||void 0===arguments[1]?!0:arguments[1],n={offset:"0 0",targetoffset:"0 0",targetattachment:"auto auto",classprefix:"tether"};this.options=h(n,t);var i=this.options,s=i.element,a=i.target,f=i.targetmodifier;if(this.element=s,this.target=a,this.targetmodifier=f,"viewport"===this.target?(this.target=document.body,this.targetmodifier="visible"):"scroll-handle"===this.target&&(this.target=document.body,this.targetmodifier="scroll-handle"),["element","target"].foreach(function(t){if("undefined"==typeof e[t])throw new error("tether error: both element and target must be defined");"undefined"!=typeof e[t].jquery?e[t]=e[t][0]:"string"==typeof e[t]&&(e[t]=document.queryselector(e[t]))}),d(this.element,this.getclass("element")),this.options.addtargetclasses!==!1&&d(this.target,this.getclass("target")),!this.options.attachment)throw new error("tether error: you must provide an attachment");this.targetattachment=r(this.options.targetattachment),this.attachment=r(this.options.attachment),this.offset=v(this.options.offset),this.targetoffset=v(this.options.targetoffset),"undefined"!=typeof this.scrollparents&&this.disable(),"scroll-handle"===this.targetmodifier?this.scrollparents=[this.target]:this.scrollparents=r(this.target),this.options.enabled!==!1&&this.enable(o)}},{key:"gettargetbounds",value:function(){if("undefined"==typeof this.targetmodifier)return a(this.target);if("visible"===this.targetmodifier){if(this.target===document.body)return{top:pageyoffset,left:pagexoffset,height:innerheight,width:innerwidth};var t=a(this.target),e={height:t.height,width:t.width,top:t.top,left:t.left};return e.height=math.min(e.height,t.height-(pageyoffset-t.top)),e.height=math.min(e.height,t.height-(t.top+t.height-(pageyoffset+innerheight))),e.height=math.min(innerheight,e.height),e.height-=2,e.width=math.min(e.width,t.width-(pagexoffset-t.left)),e.width=math.min(e.width,t.width-(t.left+t.width-(pagexoffset+innerwidth))),e.width=math.min(innerwidth,e.width),e.width-=2,e.topo.clientwidth||[n.overflow,n.overflowx].indexof("scroll")>=0||this.target!==document.body,r=0;i&&(r=15);var s=t.height-parsefloat(n.bordertopwidth)-parsefloat(n.borderbottomwidth)-r,e={width:15,height:.975*s*(s/o.scrollheight),left:t.left+t.width-parsefloat(n.borderleftwidth)-15},f=0;408>s&&this.target===document.body&&(f=-11e-5*math.pow(s,2)-.00727*s+22.58),this.target!==document.body&&(e.height=math.max(e.height,24));var l=this.target.scrolltop/(o.scrollheight-s);return e.top=l*(s-e.height-f)+t.top+parsefloat(n.bordertopwidth),this.target===document.body&&(e.height=math.max(e.height,24)),e}}},{key:"clearcache",value:function(){this._cache={}}},{key:"cache",value:function(t,e){return"undefined"==typeof this._cache&&(this._cache={}),"undefined"==typeof this._cache[t]&&(this._cache[t]=e.call(this)),this._cache[t]}},{key:"enable",value:function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];this.options.addtargetclasses!==!1&&d(this.target,this.getclass("enabled")),d(this.element,this.getclass("enabled")),this.enabled=!0,this.scrollparents.foreach(function(e){e!==t.target.ownerdocument&&e.addeventlistener("scroll",t.position)}),e&&this.position()}},{key:"disable",value:function(){var t=this;u(this.target,this.getclass("enabled")),u(this.element,this.getclass("enabled")),this.enabled=!1,"undefined"!=typeof this.scrollparents&&this.scrollparents.foreach(function(e){e.removeeventlistener("scroll",t.position)})}},{key:"destroy",value:function(){var t=this;this.disable(),l.foreach(function(e,o){e===t&&l.splice(o,1)}),0===l.length&&s()}},{key:"updateattachclasses",value:function(t,e){var o=this;t=t||this.attachment,e=e||this.targetattachment;var n=["left","top","bottom","right","middle","center"];"undefined"!=typeof this._addattachclasses&&this._addattachclasses.length&&this._addattachclasses.splice(0,this._addattachclasses.length),"undefined"==typeof this._addattachclasses&&(this._addattachclasses=[]);var i=this._addattachclasses;t.top&&i.push(this.getclass("element-attached")+"-"+t.top),t.left&&i.push(this.getclass("element-attached")+"-"+t.left),e.top&&i.push(this.getclass("target-attached")+"-"+e.top),e.left&&i.push(this.getclass("target-attached")+"-"+e.left);var r=[];n.foreach(function(t){r.push(o.getclass("element-attached")+"-"+t),r.push(o.getclass("target-attached")+"-"+t)}),m(function(){"undefined"!=typeof o._addattachclasses&&(m(o.element,o._addattachclasses,r),o.options.addtargetclasses!==!1&&m(o.target,o._addattachclasses,r),delete o._addattachclasses)})}},{key:"position",value:function(){var t=this,e=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];if(this.enabled){this.clearcache();var o=n(this.targetattachment,this.attachment);this.updateattachclasses(this.attachment,o);var n=this.cache("element-bounds",function(){return a(t.element)}),i=n.width,r=n.height;if(0===i&&0===r&&"undefined"!=typeof this.lastsize){var s=this.lastsize;i=s.width,r=s.height}else this.lastsize={width:i,height:r};var h=this.cache("target-bounds",function(){return t.gettargetbounds()}),u=h,d=c(u(this.attachment),{width:i,height:r}),p=c(u(o),u),c=c(this.offset,{width:i,height:r}),g=c(this.targetoffset,u);d=w(d,c),p=w(p,g);for(var m=h.left+p.left-d.left,v=h.top+p.top-d.top,y=0;yt.innerwidth&&(s=this.cache("scrollbar-size",l),e.viewport.bottom-=s.height),a.body.scrollheight>t.innerheight&&(s=this.cache("scrollbar-size",l),e.viewport.right-=s.width),(-1===["","static"].indexof(a.body.style.position)||-1===["","static"].indexof(a.body.parentelement.style.position))&&(e.page.bottom=a.body.scrollheight-v-r,e.page.right=a.body.scrollwidth-m-i),"undefined"!=typeof this.options.optimizations&&this.options.optimizations.moveelement!==!1&&"undefined"==typeof this.targetmodifier&&!function(){var e=t.cache("target-offsetparent",function(){return f(t.target)}),o=t.cache("target-offsetparent-bounds",function(){return a(e)}),n=getcomputedstyle(e),i=o,r={};if(["top","left","bottom","right"].foreach(function(t){r[t.tolowercase()]=parsefloat(n["border"+t+"width"])}),o.right=a.body.scrollwidth-o.left-i.width+r.right,o.bottom=a.body.scrollheight-o.top-i.height+r.bottom,e.page.top>=o.top+r.top&&e.page.bottom>=o.bottom&&e.page.left>=o.left+r.left&&e.page.right>=o.right){var s=e.scrolltop,l=e.scrollleft;e.offset={top:e.page.top-o.top+s-r.top,left:e.page.left-o.left+l-r.left}}}(),this.move(e),this.history.unshift(e),this.history.length>3&&this.history.pop(),e&&_(),!0}}},{key:"move",value:function(t){var e=this;if("undefined"!=typeof this.element.parentnode){var o={};for(var n in t){o[n]={};for(var i in t[n]){for(var r=!1,s=0;s=0){var c=a.split(" "),m=b(c,2);u=m[0],h=m[1]}else h=u=a;var b=o(e,r);("target"===u||"both"===u)&&(ob[3]&&"bottom"===v.top&&(o-=d,v.top="top")),"together"===u&&("top"===v.top&&("bottom"===y.top&&ob[3]&&o-(s-d)>=b[1]&&(o-=s-d,v.top="bottom",y.top="bottom")),"bottom"===v.top&&("top"===y.top&&o+s>b[3]?(o-=d,v.top="top",o-=s,y.top="bottom"):"bottom"===y.top&&ob[3]&&"top"===y.top?(o-=s,y.top="bottom"):ob[2]&&"right"===v.left&&(n-=p,v.left="left")),"together"===h&&(nb[2]&&"right"===v.left?"left"===y.left?(n-=p,v.left="left",n-=f,y.left="right"):"right"===y.left&&(n-=p,v.left="left",n+=f,y.left="left"):"center"===v.left&&(n+f>b[2]&&"left"===y.left?(n-=f,y.left="right"):nb[3]&&"top"===y.top&&(o-=s,y.top="bottom")),("element"===h||"both"===h)&&(nb[2]&&("left"===y.left?(n-=f,y.left="right"):"center"===y.left&&(n-=f/2,y.left="right"))),"string"==typeof l?l=l.split(",").map(function(t){return t.trim()}):l===!0&&(l=["top","left","right","bottom"]),l=l||[];var w=[],c=[];o=0?(o=b[1],w.push("top")):c.push("top")),o+s>b[3]&&(l.indexof("bottom")>=0?(o=b[3]-s,w.push("bottom")):c.push("bottom")),n=0?(n=b[0],w.push("left")):c.push("left")),n+f>b[2]&&(l.indexof("right")>=0?(n=b[2]-f,w.push("right")):c.push("right")),w.length&&!function(){var t=void 0;t="undefined"!=typeof e.options.pinnedclass?e.options.pinnedclass:e.getclass("pinned"),g.push(t),w.foreach(function(e){g.push(t+"-"+e)})}(),c.length&&!function(){var t=void 0;t="undefined"!=typeof e.options.outofboundsclass?e.options.outofboundsclass:e.getclass("out-of-bounds"),g.push(t),c.foreach(function(e){g.push(t+"-"+e)})}(),(w.indexof("left")>=0||w.indexof("right")>=0)&&(y.left=v.left=!1),(w.indexof("top")>=0||w.indexof("bottom")>=0)&&(y.top=v.top=!1),(v.top!==i.top||v.left!==i.left||y.top!==e.attachment.top||y.left!==e.attachment.left)&&(e.updateattachclasses(y,v),e.trigger("update",{attachment:y,targetattachment:v}))}),m(function(){e.options.addtargetclasses!==!1&&m(e.target,g,c),m(e.element,g,c)}),{top:o,left:n}}});var j=x.utils,a=j.getbounds,m=j.updateclasses,m=j.defer;x.modules.push({position:function(t){var e=this,o=t.top,n=t.left,i=this.cache("element-bounds",function(){return a(e.element)}),r=i.height,s=i.width,f=this.gettargetbounds(),l=o+r,h=n+s,u=[];o<=f.bottom&&l>=f.top&&["left","right"].foreach(function(t){var e=f[t];(e===n||e===h)&&u.push(t)}),n<=f.right&&h>=f.left&&["top","bottom"].foreach(function(t){var e=f[t];(e===o||e===l)&&u.push(t)});var d=[],p=[],c=["left","top","right","bottom"];return d.push(this.getclass("abutted")),c.foreach(function(t){d.push(e.getclass("abutted")+"-"+t)}),u.length&&p.push(this.getclass("abutted")),u.foreach(function(t){p.push(e.getclass("abutted")+"-"+t)}),m(function(){e.options.addtargetclasses!==!1&&m(e.target,p,d),m(e.element,p,d)}),!0}});var b=function(){function t(t,e){var o=[],n=!0,i=!1,r=void 0;try{for(var s,a=t[symbol.iterator]();!(n=(s=a.next()).done)&&(o.push(s.value),!e||o.length!==e);n=!0);}catch(f){i=!0,r=f}finally{try{!n&&a["return"]&&a["return"]()}finally{if(i)throw r}}return o}return function(e,o){if(array.isarray(e))return e;if(symbol.iterator in object(e))return t(e,o);throw new typeerror("invalid attempt to destructure non-iterable instance")}}();return x.modules.push({position:function(t){var e=t.top,o=t.left;if(this.options.shift){var n=this.options.shift;"function"==typeof this.options.shift&&(n=this.options.shift.call(this,{top:e,left:o}));var i=void 0,r=void 0;if("string"==typeof n){n=n.split(" "),n[1]=n[1]||n[0];var s=n,a=b(s,2);i=a[0],r=a[1],i=parsefloat(i,10),r=parsefloat(r,10)}else i=n.top,r=n.left;return e+=i,o+=r,{top:e,left:o}}}}),i});