tether-drop
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "tether-drop", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"homepage": "https://github.com/HubSpot/drop", | ||
@@ -28,4 +28,4 @@ "authors": [ | ||
"dependencies": { | ||
"tether": "^1.0.0" | ||
"tether": "^1.0.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
/*! tether-drop 1.1.1 */ | ||
/*! tether-drop 1.1.2 */ | ||
@@ -175,2 +175,3 @@ (function(root, factory) { | ||
this._boundEvents = []; | ||
this.bindMethods(); | ||
this.setupElements(); | ||
@@ -190,2 +191,7 @@ this.setupEvents(); | ||
}, { | ||
key: 'bindMethods', | ||
value: function bindMethods() { | ||
this.transitionEndHandler = this._transitionEndHandler.bind(this); | ||
} | ||
}, { | ||
key: 'setupElements', | ||
@@ -414,6 +420,12 @@ value: function setupElements() { | ||
}, { | ||
key: '_transitionEndHandler', | ||
value: function _transitionEndHandler() { | ||
if (!hasClass(this.drop, '' + drop.classPrefix + '-open')) { | ||
removeClass(this.drop, '' + drop.classPrefix + '-open-transitionend'); | ||
} | ||
this.drop.removeEventListener(transitionEndEvent, this.transitionEndHandler); | ||
} | ||
}, { | ||
key: 'close', | ||
value: function close() { | ||
var _this4 = this; | ||
if (!this.isOpened()) { | ||
@@ -426,11 +438,4 @@ return; | ||
var handler = function handler() { | ||
if (!hasClass(_this4.drop, '' + drop.classPrefix + '-open')) { | ||
removeClass(_this4.drop, '' + drop.classPrefix + '-open-transitionend'); | ||
} | ||
_this4.drop.removeEventListener(transitionEndEvent, handler); | ||
}; | ||
this.drop.addEventListener(transitionEndEvent, this.transitionEndHandler); | ||
this.drop.addEventListener(transitionEndEvent, handler); | ||
this.trigger('close'); | ||
@@ -437,0 +442,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"function"==typeof define&&define.amd?define(["tether"],e):"object"==typeof exports?module.exports=e(require("tether")):t.Drop=e(t.Tether)}(this,function(t){"use strict";function e(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t)){var n=[],o=!0,i=!1,r=void 0;try{for(var s,a=t[Symbol.iterator]();!(o=(s=a.next()).done)&&(n.push(s.value),!e||n.length!==e);o=!0);}catch(p){i=!0,r=p}finally{try{!o&&a["return"]&&a["return"]()}finally{if(i)throw r}}return n}throw new TypeError("Invalid attempt to destructure non-iterable instance")}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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&&(t.__proto__=e)}function i(t){var n=t.split(" "),o=e(n,2),i=o[0],r=o[1];if(["left","right"].indexOf(i)>=0){var s=[r,i];i=s[0],r=s[1]}return[i,r].join(" ")}function r(t,e){for(var n=void 0,o=[];-1!==(n=t.indexOf(e));)o.push(t.splice(n,1));return o}function s(){var e=void 0===arguments[0]?{}:arguments[0],d=function(){for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];return new(u.apply(b,[null].concat(e)))};l(d,{createContext:s,drops:[],defaults:{}});var m={classPrefix:"drop",defaults:{position:"bottom left",openOn:"click",constrainToScrollParent:!0,constrainToWindow:!0,classes:"",remove:!1,tetherOptions:{}}};l(d,m,e),l(d.defaults,m.defaults,e.defaults),"undefined"==typeof P[d.classPrefix]&&(P[d.classPrefix]=[]),d.updateBodyClasses=function(){for(var t=!1,e=P[d.classPrefix],n=e.length,o=0;n>o;++o)if(e[o].isOpened()){t=!0;break}t?h(document.body,""+d.classPrefix+"-open"):c(document.body,""+d.classPrefix+"-open")};var b=function(e){function s(t){if(n(this,s),p(Object.getPrototypeOf(s.prototype),"constructor",this).call(this),this.options=l({},d.defaults,t),this.target=this.options.target,"undefined"==typeof this.target)throw new Error("Drop Error: You must provide a target.");this.options.classes&&this.options.addTargetClasses!==!1&&h(this.target,this.options.classes),d.drops.push(this),P[d.classPrefix].push(this),this._boundEvents=[],this.setupElements(),this.setupEvents(),this.setupTether()}return o(s,e),a(s,[{key:"_on",value:function(t,e,n){this._boundEvents.push({element:t,event:e,handler:n}),t.addEventListener(e,n)}},{key:"setupElements",value:function(){var t=this;if(this.drop=document.createElement("div"),h(this.drop,d.classPrefix),this.options.classes&&h(this.drop,this.options.classes),this.content=document.createElement("div"),h(this.content,""+d.classPrefix+"-content"),"function"==typeof this.options.content){var e=function(){var e=t.options.content.call(t,t);if("string"==typeof e)t.content.innerHTML=e;else{if("object"!=typeof e)throw new Error("Drop Error: Content function should return a string or HTMLElement.");t.content.innerHTML="",t.content.appendChild(e)}};e(),this.on("open",e.bind(this))}else"object"==typeof this.options.content?this.content.appendChild(this.options.content):this.content.innerHTML=this.options.content;this.drop.appendChild(this.content)}},{key:"setupTether",value:function(){var e=this.options.position.split(" ");e[0]=x[e[0]],e=e.join(" ");var n=[];n.push(this.options.constrainToScrollParent?{to:"scrollParent",pin:"top, bottom",attachment:"together none"}:{to:"scrollParent"}),n.push(this.options.constrainToWindow!==!1?{to:"window",attachment:"together"}:{to:"window"});var o={element:this.drop,target:this.target,attachment:i(e),targetAttachment:i(this.options.position),classPrefix:d.classPrefix,offset:"0 0",targetOffset:"0 0",enabled:!1,constraints:n,addTargetClasses:this.options.addTargetClasses};this.options.tetherOptions!==!1&&(this.tether=new t(l({},o,this.options.tetherOptions)))}},{key:"setupEvents",value:function(){var t=this;if(this.options.openOn){if("always"===this.options.openOn)return void setTimeout(this.open.bind(this));var e=this.options.openOn.split(" ");if(e.indexOf("click")>=0)for(var n=function(e){t.toggle(),e.preventDefault()},o=function(e){t.isOpened()&&(e.target===t.drop||t.drop.contains(e.target)||e.target===t.target||t.target.contains(e.target)||t.close())},i=0;i<y.length;++i){var r=y[i];this._on(this.target,r,n),this._on(document,r,o)}e.indexOf("hover")>=0&&!function(){var e=!1,n=function(){e=!0,t.open()},o=null,i=function(){e=!1,"undefined"!=typeof o&&clearTimeout(o),o=setTimeout(function(){e||t.close(),o=null},50)};t._on(t.target,"mouseover",n),t._on(t.drop,"mouseover",n),t._on(t.target,"mouseout",i),t._on(t.drop,"mouseout",i)}()}}},{key:"isOpened",value:function(){return this.drop?f(this.drop,""+d.classPrefix+"-open"):void 0}},{key:"toggle",value:function(){this.isOpened()?this.close():this.open()}},{key:"open",value:function(){var t=this;this.isOpened()||(this.drop.parentNode||document.body.appendChild(this.drop),"undefined"!=typeof this.tether&&this.tether.enable(),h(this.drop,""+d.classPrefix+"-open"),h(this.drop,""+d.classPrefix+"-open-transitionend"),setTimeout(function(){t.drop&&h(t.drop,""+d.classPrefix+"-after-open")}),"undefined"!=typeof this.tether&&this.tether.position(),this.trigger("open"),d.updateBodyClasses())}},{key:"close",value:function(){var t=this;if(this.isOpened()){c(this.drop,""+d.classPrefix+"-open"),c(this.drop,""+d.classPrefix+"-after-open");var e=function n(){f(t.drop,""+d.classPrefix+"-open")||c(t.drop,""+d.classPrefix+"-open-transitionend"),t.drop.removeEventListener(g,n)};this.drop.addEventListener(g,e),this.trigger("close"),"undefined"!=typeof this.tether&&this.tether.disable(),d.updateBodyClasses(),this.options.remove&&this.remove()}}},{key:"remove",value:function(){this.close(),this.drop.parentNode&&this.drop.parentNode.removeChild(this.drop)}},{key:"position",value:function(){this.isOpened()&&"undefined"!=typeof this.tether&&this.tether.position()}},{key:"destroy",value:function(){this.remove(),"undefined"!=typeof this.tether&&this.tether.destroy();for(var t=0;t<this._boundEvents.length;++t){var e=this._boundEvents[t],n=e.element,o=e.event,i=e.handler;n.removeEventListener(o,i)}this._boundEvents=[],this.tether=null,this.drop=null,this.content=null,this.target=null,r(P[d.classPrefix],this),r(d.drops,this)}}]),s}(v);return d}var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),p=function(t,e,n){for(var o=!0;o;){var i=t,r=e,s=n;a=u=p=void 0,o=!1;var a=Object.getOwnPropertyDescriptor(i,r);if(void 0!==a){if("value"in a)return a.value;var p=a.get;return void 0===p?void 0:p.call(s)}var u=Object.getPrototypeOf(i);if(null===u)return void 0;t=u,e=r,n=s,o=!0}},u=Function.prototype.bind,d=t.Utils,l=d.extend,h=d.addClass,c=d.removeClass,f=d.hasClass,v=d.Evented,y=["click"];"ontouchstart"in document.documentElement&&y.push("touchstart");var m={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"otransitionend",transition:"transitionend"},g="";for(var b in m)if({}.hasOwnProperty.call(m,b)){var O=document.createElement("p");"undefined"!=typeof O.style[b]&&(g=m[b])}var x={left:"right",right:"left",top:"bottom",bottom:"top",middle:"middle",center:"center"},P={},E=s();return document.addEventListener("DOMContentLoaded",function(){E.updateBodyClasses()}),E}); | ||
!function(t,e){"function"==typeof define&&define.amd?define(["tether"],e):"object"==typeof exports?module.exports=e(require("tether")):t.Drop=e(t.Tether)}(this,function(t){"use strict";function e(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t)){var n=[],o=!0,i=!1,s=void 0;try{for(var r,a=t[Symbol.iterator]();!(o=(r=a.next()).done)&&(n.push(r.value),!e||n.length!==e);o=!0);}catch(d){i=!0,s=d}finally{try{!o&&a["return"]&&a["return"]()}finally{if(i)throw s}}return n}throw new TypeError("Invalid attempt to destructure non-iterable instance")}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(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&&(t.__proto__=e)}function i(t){var n=t.split(" "),o=e(n,2),i=o[0],s=o[1];if(["left","right"].indexOf(i)>=0){var r=[s,i];i=r[0],s=r[1]}return[i,s].join(" ")}function s(t,e){for(var n=void 0,o=[];-1!==(n=t.indexOf(e));)o.push(t.splice(n,1));return o}function r(){var e=void 0===arguments[0]?{}:arguments[0],h=function(){for(var t=arguments.length,e=Array(t),n=0;t>n;n++)e[n]=arguments[n];return new(p.apply(b,[null].concat(e)))};l(h,{createContext:r,drops:[],defaults:{}});var m={classPrefix:"drop",defaults:{position:"bottom left",openOn:"click",constrainToScrollParent:!0,constrainToWindow:!0,classes:"",remove:!1,tetherOptions:{}}};l(h,m,e),l(h.defaults,m.defaults,e.defaults),"undefined"==typeof x[h.classPrefix]&&(x[h.classPrefix]=[]),h.updateBodyClasses=function(){for(var t=!1,e=x[h.classPrefix],n=e.length,o=0;n>o;++o)if(e[o].isOpened()){t=!0;break}t?u(document.body,""+h.classPrefix+"-open"):c(document.body,""+h.classPrefix+"-open")};var b=function(e){function r(t){if(n(this,r),d(Object.getPrototypeOf(r.prototype),"constructor",this).call(this),this.options=l({},h.defaults,t),this.target=this.options.target,"undefined"==typeof this.target)throw new Error("Drop Error: You must provide a target.");this.options.classes&&this.options.addTargetClasses!==!1&&u(this.target,this.options.classes),h.drops.push(this),x[h.classPrefix].push(this),this._boundEvents=[],this.bindMethods(),this.setupElements(),this.setupEvents(),this.setupTether()}return o(r,e),a(r,[{key:"_on",value:function(t,e,n){this._boundEvents.push({element:t,event:e,handler:n}),t.addEventListener(e,n)}},{key:"bindMethods",value:function(){this.transitionEndHandler=this._transitionEndHandler.bind(this)}},{key:"setupElements",value:function(){var t=this;if(this.drop=document.createElement("div"),u(this.drop,h.classPrefix),this.options.classes&&u(this.drop,this.options.classes),this.content=document.createElement("div"),u(this.content,""+h.classPrefix+"-content"),"function"==typeof this.options.content){var e=function(){var e=t.options.content.call(t,t);if("string"==typeof e)t.content.innerHTML=e;else{if("object"!=typeof e)throw new Error("Drop Error: Content function should return a string or HTMLElement.");t.content.innerHTML="",t.content.appendChild(e)}};e(),this.on("open",e.bind(this))}else"object"==typeof this.options.content?this.content.appendChild(this.options.content):this.content.innerHTML=this.options.content;this.drop.appendChild(this.content)}},{key:"setupTether",value:function(){var e=this.options.position.split(" ");e[0]=O[e[0]],e=e.join(" ");var n=[];n.push(this.options.constrainToScrollParent?{to:"scrollParent",pin:"top, bottom",attachment:"together none"}:{to:"scrollParent"}),n.push(this.options.constrainToWindow!==!1?{to:"window",attachment:"together"}:{to:"window"});var o={element:this.drop,target:this.target,attachment:i(e),targetAttachment:i(this.options.position),classPrefix:h.classPrefix,offset:"0 0",targetOffset:"0 0",enabled:!1,constraints:n,addTargetClasses:this.options.addTargetClasses};this.options.tetherOptions!==!1&&(this.tether=new t(l({},o,this.options.tetherOptions)))}},{key:"setupEvents",value:function(){var t=this;if(this.options.openOn){if("always"===this.options.openOn)return void setTimeout(this.open.bind(this));var e=this.options.openOn.split(" ");if(e.indexOf("click")>=0)for(var n=function(e){t.toggle(),e.preventDefault()},o=function(e){t.isOpened()&&(e.target===t.drop||t.drop.contains(e.target)||e.target===t.target||t.target.contains(e.target)||t.close())},i=0;i<y.length;++i){var s=y[i];this._on(this.target,s,n),this._on(document,s,o)}e.indexOf("hover")>=0&&!function(){var e=!1,n=function(){e=!0,t.open()},o=null,i=function(){e=!1,"undefined"!=typeof o&&clearTimeout(o),o=setTimeout(function(){e||t.close(),o=null},50)};t._on(t.target,"mouseover",n),t._on(t.drop,"mouseover",n),t._on(t.target,"mouseout",i),t._on(t.drop,"mouseout",i)}()}}},{key:"isOpened",value:function(){return this.drop?f(this.drop,""+h.classPrefix+"-open"):void 0}},{key:"toggle",value:function(){this.isOpened()?this.close():this.open()}},{key:"open",value:function(){var t=this;this.isOpened()||(this.drop.parentNode||document.body.appendChild(this.drop),"undefined"!=typeof this.tether&&this.tether.enable(),u(this.drop,""+h.classPrefix+"-open"),u(this.drop,""+h.classPrefix+"-open-transitionend"),setTimeout(function(){t.drop&&u(t.drop,""+h.classPrefix+"-after-open")}),"undefined"!=typeof this.tether&&this.tether.position(),this.trigger("open"),h.updateBodyClasses())}},{key:"_transitionEndHandler",value:function(){f(this.drop,""+h.classPrefix+"-open")||c(this.drop,""+h.classPrefix+"-open-transitionend"),this.drop.removeEventListener(g,this.transitionEndHandler)}},{key:"close",value:function(){this.isOpened()&&(c(this.drop,""+h.classPrefix+"-open"),c(this.drop,""+h.classPrefix+"-after-open"),this.drop.addEventListener(g,this.transitionEndHandler),this.trigger("close"),"undefined"!=typeof this.tether&&this.tether.disable(),h.updateBodyClasses(),this.options.remove&&this.remove())}},{key:"remove",value:function(){this.close(),this.drop.parentNode&&this.drop.parentNode.removeChild(this.drop)}},{key:"position",value:function(){this.isOpened()&&"undefined"!=typeof this.tether&&this.tether.position()}},{key:"destroy",value:function(){this.remove(),"undefined"!=typeof this.tether&&this.tether.destroy();for(var t=0;t<this._boundEvents.length;++t){var e=this._boundEvents[t],n=e.element,o=e.event,i=e.handler;n.removeEventListener(o,i)}this._boundEvents=[],this.tether=null,this.drop=null,this.content=null,this.target=null,s(x[h.classPrefix],this),s(h.drops,this)}}]),r}(v);return h}var a=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),d=function(t,e,n){for(var o=!0;o;){var i=t,s=e,r=n;a=p=d=void 0,o=!1;var a=Object.getOwnPropertyDescriptor(i,s);if(void 0!==a){if("value"in a)return a.value;var d=a.get;return void 0===d?void 0:d.call(r)}var p=Object.getPrototypeOf(i);if(null===p)return void 0;t=p,e=s,n=r,o=!0}},p=Function.prototype.bind,h=t.Utils,l=h.extend,u=h.addClass,c=h.removeClass,f=h.hasClass,v=h.Evented,y=["click"];"ontouchstart"in document.documentElement&&y.push("touchstart");var m={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"otransitionend",transition:"transitionend"},g="";for(var b in m)if({}.hasOwnProperty.call(m,b)){var E=document.createElement("p");"undefined"!=typeof E.style[b]&&(g=m[b])}var O={left:"right",right:"left",top:"bottom",bottom:"top",middle:"middle",center:"center"},x={},P=r();return document.addEventListener("DOMContentLoaded",function(){P.updateBodyClasses()}),P}); |
{ | ||
"name": "tether-drop", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Client-side library for creating dropdowns", | ||
@@ -34,4 +34,4 @@ "authors": [ | ||
"dependencies": { | ||
"tether": "^1.0.0" | ||
"tether": "^1.0.2" | ||
} | ||
} |
@@ -134,2 +134,3 @@ /* global Tether */ | ||
this._boundEvents = []; | ||
this.bindMethods(); | ||
this.setupElements(); | ||
@@ -145,2 +146,6 @@ this.setupEvents(); | ||
bindMethods() { | ||
this.transitionEndHandler = this._transitionEndHandler.bind(this); | ||
} | ||
setupElements() { | ||
@@ -356,2 +361,9 @@ this.drop = document.createElement('div'); | ||
_transitionEndHandler() { | ||
if (!hasClass(this.drop, `${ drop.classPrefix }-open`)) { | ||
removeClass(this.drop, `${ drop.classPrefix }-open-transitionend`); | ||
} | ||
this.drop.removeEventListener(transitionEndEvent, this.transitionEndHandler); | ||
} | ||
close() { | ||
@@ -365,11 +377,4 @@ if (!this.isOpened()) { | ||
const handler = () => { | ||
if (!hasClass(this.drop, `${ drop.classPrefix }-open`)) { | ||
removeClass(this.drop, `${ drop.classPrefix }-open-transitionend`); | ||
} | ||
this.drop.removeEventListener(transitionEndEvent, handler); | ||
}; | ||
this.drop.addEventListener(transitionEndEvent, this.transitionEndHandler); | ||
this.drop.addEventListener(transitionEndEvent, handler); | ||
this.trigger('close'); | ||
@@ -376,0 +381,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
736384
10593
Updatedtether@^1.0.2