criss-cross
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -10,2 +10,8 @@ # Changelog | ||
## [0.0.5] - 2017-11-20 | ||
### Added | ||
- Add `update` method | ||
## [0.0.4] - 2017-11-17 | ||
@@ -12,0 +18,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("crissCross",[],t):"object"==typeof exports?exports.crissCross=t():e.crissCross=t()}(this,function(){return function(e){function t(i){if(r[i])return r[i].exports;var o=r[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,i){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.ENTER_VIEWPORT="enterViewport",t.FULLY_ENTER_VIEWPORT="fullyEnterViewport",t.EXIT_VIEWPORT="exitViewport",t.FULLY_EXIT_VIEWPORT="fullyExitViewport",t.VISIBILITY_CHANGE="visibilityChange",t.STATE_CHANGE="stateChange"},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=r(2),o=function(e){return e&&e.__esModule?e:{default:e}}(i);t.default=new o.default,e.exports=t.default},function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),s=r(0),u=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(s),l=r(3),a=function(e){return e&&e.__esModule?e:{default:e}}(l),f=new WeakMap,c=new WeakMap,p=function(){function e(){i(this,e),f.set(this,[]),c.set(this,[]),this._intersected=this._intersected.bind(this)}return n(e,[{key:"create",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.offset,i=void 0===r?0:r,n=t.root,s=void 0===n?null:n,u=e;if("string"==typeof u&&(u=document.querySelector(e)),!(u&&u instanceof HTMLElement))throw new Error("[🎤 criss-cross] Invalid target. Should be an HTMLElement.");if(null!==s&&!s.contains(u))throw new Error("[🎤 criss-cross] Invalid target. Should be a child of root.");if(this.options={root:null,rootMargin:"0px 0px 0px 0px",threshold:[0,1]},"object"===(void 0===i?"undefined":o(i))){var l=i.top||0,a=i.bottom||0;this.options.rootMargin=l+"px 0px "+a+"px 0px"}else this.options.rootMargin=i+"px 0px "+i+"px 0px";this.options.root=s;var f=this._createObserver(this.options),c=this._createItem(u,f);return c.init(),c}},{key:"destroy",value:function(){var e=f.get(this),t=c.get(this);e.length=0,t.forEach(function(e){e.disconnect()}),t.length=0}},{key:"_intersected",value:function(e,t){var r=this._getItems(t);e.forEach(function(e){var t=r.find(function(t){return t.isLocked?t.$ghost===e.target:t.$el===e.target});t.isBeforeViewport=e.boundingClientRect.top<e.rootBounds.top,t.isAfterViewport=e.boundingClientRect.top+e.boundingClientRect.height>e.rootBounds.top+e.rootBounds.height,e.isIntersecting?(t.isInViewport=!0,e.intersectionRatio>=1?t.isFullyInViewport=!0:t.isFullyInViewport=!1):(t.isInViewport=!1,t.isFullyInViewport=!1),void 0===t.wasInViewport?(t.isInViewport&&!t.isFullyInViewport&&(t.isAfterViewport&&t.trigger(u.ENTER_VIEWPORT),t.isBeforeViewport&&t.trigger(u.EXIT_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE)),t.isFullyInViewport&&(t.trigger(u.FULLY_ENTER_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE)),!t.isInViewport&&t.isBeforeViewport&&(t.trigger(u.EXIT_VIEWPORT),t.trigger(u.FULLY_EXIT_VIEWPORT))):(t.isInViewport&&!t.wasInViewport&&(t.trigger(u.ENTER_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE),t.trigger(u.STATE_CHANGE)),t.isFullyInViewport&&!t.wasFullyInViewport&&(t.trigger(u.FULLY_ENTER_VIEWPORT),t.trigger(u.STATE_CHANGE)),!t.isFullyInViewport&&t.wasFullyInViewport&&(t.trigger(u.EXIT_VIEWPORT),t.trigger(u.STATE_CHANGE)),!t.isInViewport&&t.wasInViewport&&(t.trigger(u.FULLY_EXIT_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE),t.trigger(u.STATE_CHANGE))),t.wasBeforeViewport=t.isBeforeViewport,t.wasInViewport=t.isInViewport,t.wasFullyInViewport=t.isFullyInViewport,t.wasAfterViewport=t.isAfterViewport})}},{key:"_createObserver",value:function(e){var t=this._getObserver(e);if(t)return t;var r=new IntersectionObserver(this._intersected,e);return this._addObserver(r),r}},{key:"_addObserver",value:function(e){c.get(this).push(e)}},{key:"_getObserver",value:function(e){return c.get(this).find(function(t){return t.root===e.root&&t.rootMargin===e.rootMargin})}},{key:"_destroyObserver",value:function(e){var t=c.get(this),r=t.indexOf(e);e.disconnect(),t.splice(r,1)}},{key:"_createItem",value:function(e,t){var r=new a.default(e,t,this);return this._addItem(r),r}},{key:"_addItem",value:function(e){f.get(this).push(e)}},{key:"_getItems",value:function(e){return f.get(this).filter(function(t){return t.observer===e})}},{key:"_destroyItem",value:function(e){var t=f.get(this),r=t.indexOf(e),i=e.observer;t.splice(r,1),0===this._getItems(i).length&&this._destroyObserver(i)}}]),e}();t.default=p,e.exports=t.default},function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),n=r(0),s=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(n),u=r(4),l=Object.values(s),a=new WeakMap,f=function(){function e(t,r,o){var n=this;i(this,e),this.$el=t,this.observer=r,this.manager=o,this.isInViewport=!1,this.isFullyInViewport=!1,this.isBeforeViewport=!1,this.isAfterViewport=!1,a.set(this,{}),l.forEach(function(e){a.get(n)[e]=[]})}return o(e,[{key:"init",value:function(){this.observer.observe(this.target)}},{key:"pause",value:function(){this.observer.unobserve(this.target)}},{key:"resume",value:function(){this.init()}},{key:"destroy",value:function(){this.pause(),this.manager._destroyItem(this)}},{key:"lock",value:function(){if(!this.isLocked){if("absolute"!==getComputedStyle(this.$el).position)throw new Error("[🎤 criss-cross] Target should be in absolute position.");for(var e=this.$el.cloneNode(!1),t=e.classList;t.length>0;)t.remove(t.item(0));e.style.position="absolute",e.style.top=this.$el.offsetTop+"px",e.style.left=this.$el.offsetLeft+"px",e.style.width="100%",e.style.height=(0,u.$outerHeight)(this.$el)+"px",e.style.visibility="hidden",e.style.opacity=0,this.$ghost=e,this.observer.unobserve(this.$el),this.observer.observe(this.$ghost),this.isLocked=!0,(0,u.$insertAfter)(e,this.$el)}}},{key:"unlock",value:function(){this.isLocked&&(this.observer.unobserve(this.$ghost),this.observer.observe(this.$el),this.isLocked=!1,this.$ghost.remove())}},{key:"on",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=a.get(this);if(!i[e])throw new Error("[🎤 criss-cross] Unavailable listener '"+e+"' ["+l.join(", ")+"]");i[e].push({cb:t,one:r})}},{key:"one",value:function(e,t){this.on(e,t,!0)}},{key:"off",value:function(e,t){var r=a.get(this);if(!r[e])throw new Error("[🎤 criss-cross] Unavailable listener '"+e+"' ["+l.join(", ")+"]");r[e].some(function(i,o){return i.cb===t&&r[e].splice(o,1),i.cb===t})}},{key:"trigger",value:function(e){var t=this,r=a.get(this);r[e].length>0&&r[e].forEach(function(r){r.cb(t),r.one&&t.off(e,r.cb)})}},{key:"target",get:function(){return this.isLocked?this.$ghost:this.$el}}]),e}();l.forEach(function(e){f.prototype[e]=function(t){this.on(e,t)}}),t.default=f,e.exports=t.default},function(e,t,r){"use strict";function i(e){var t=e.offsetWidth,r=getComputedStyle(e);return t+=parseInt(r.marginLeft,10)+parseInt(r.marginRight,10)}function o(e){var t=e.offsetHeight,r=getComputedStyle(e);return t+=parseInt(r.marginTop,10)+parseInt(r.marginBottom,10)}function n(e,t){t.parentNode.insertBefore(e,t.nextSibling)}Object.defineProperty(t,"__esModule",{value:!0}),t.$outerWidth=i,t.$outerHeight=o,t.$insertAfter=n}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("crissCross",[],t):"object"==typeof exports?exports.crissCross=t():e.crissCross=t()}(this,function(){return function(e){function t(i){if(r[i])return r[i].exports;var o=r[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,i){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.ENTER_VIEWPORT="enterViewport",t.FULLY_ENTER_VIEWPORT="fullyEnterViewport",t.EXIT_VIEWPORT="exitViewport",t.FULLY_EXIT_VIEWPORT="fullyExitViewport",t.VISIBILITY_CHANGE="visibilityChange",t.STATE_CHANGE="stateChange"},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=r(2),o=function(e){return e&&e.__esModule?e:{default:e}}(i);t.default=new o.default,e.exports=t.default},function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),s=r(0),u=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(s),l=r(3),a=function(e){return e&&e.__esModule?e:{default:e}}(l),f=new WeakMap,c=new WeakMap,p=function(){function e(){i(this,e),f.set(this,[]),c.set(this,[]),this._intersected=this._intersected.bind(this)}return n(e,[{key:"create",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.offset,o=void 0===i?0:i,n=r.root,s=void 0===n?null:n,u=t;if("string"==typeof u&&(u=document.querySelector(t)),!(u&&u instanceof HTMLElement))throw new Error("[🎤 criss-cross] Invalid target. Should be an HTMLElement.");if(null!==s&&!s.contains(u))throw new Error("[🎤 criss-cross] Invalid target. Should be a child of root.");var l=e._setOptions(o,s),a=this._createObserver(l),f=this._createItem(u,a);return f.init(),f}},{key:"update",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.offset,o=void 0===i?0:i,n=r.root,s=void 0===n?null:n;t.pause(),this._destroyObserver(t.observer);var u=e._setOptions(o,s),l=this._createObserver(u);t.observer=l,t.resume()}},{key:"destroy",value:function(){var e=f.get(this),t=c.get(this);e.length=0,t.forEach(function(e){e.disconnect()}),t.length=0}},{key:"_intersected",value:function(e,t){var r=this._getItems(t);e.forEach(function(e){var t=r.find(function(t){return t.isLocked?t.$ghost===e.target:t.$el===e.target});t.isBeforeViewport=e.boundingClientRect.top<e.rootBounds.top,t.isAfterViewport=e.boundingClientRect.top+e.boundingClientRect.height>e.rootBounds.top+e.rootBounds.height,e.isIntersecting?(t.isInViewport=!0,e.intersectionRatio>=1?t.isFullyInViewport=!0:t.isFullyInViewport=!1):(t.isInViewport=!1,t.isFullyInViewport=!1),void 0===t.wasInViewport?(t.isInViewport&&!t.isFullyInViewport&&(t.isAfterViewport&&t.trigger(u.ENTER_VIEWPORT),t.isBeforeViewport&&t.trigger(u.EXIT_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE)),t.isFullyInViewport&&(t.trigger(u.FULLY_ENTER_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE)),!t.isInViewport&&t.isBeforeViewport&&(t.trigger(u.EXIT_VIEWPORT),t.trigger(u.FULLY_EXIT_VIEWPORT))):(t.isInViewport&&!t.wasInViewport&&(t.trigger(u.ENTER_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE),t.trigger(u.STATE_CHANGE)),t.isFullyInViewport&&!t.wasFullyInViewport&&(t.trigger(u.FULLY_ENTER_VIEWPORT),t.trigger(u.STATE_CHANGE)),!t.isFullyInViewport&&t.wasFullyInViewport&&(t.trigger(u.EXIT_VIEWPORT),t.trigger(u.STATE_CHANGE)),!t.isInViewport&&t.wasInViewport&&(t.trigger(u.FULLY_EXIT_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE),t.trigger(u.STATE_CHANGE))),t.wasBeforeViewport=t.isBeforeViewport,t.wasInViewport=t.isInViewport,t.wasFullyInViewport=t.isFullyInViewport,t.wasAfterViewport=t.isAfterViewport})}},{key:"_createObserver",value:function(e){var t=this._getObserver(e);if(t)return t;var r=new IntersectionObserver(this._intersected,e);return this._addObserver(r),r}},{key:"_addObserver",value:function(e){c.get(this).push(e)}},{key:"_getObserver",value:function(e){return c.get(this).find(function(t){return t.root===e.root&&t.rootMargin===e.rootMargin})}},{key:"_destroyObserver",value:function(e){var t=c.get(this),r=t.indexOf(e);e.disconnect(),t.splice(r,1)}},{key:"_createItem",value:function(e,t){var r=new a.default(e,t,this);return this._addItem(r),r}},{key:"_addItem",value:function(e){f.get(this).push(e)}},{key:"_getItems",value:function(e){return f.get(this).filter(function(t){return t.observer===e})}},{key:"_destroyItem",value:function(e){var t=f.get(this),r=t.indexOf(e),i=e.observer;t.splice(r,1),0===this._getItems(i).length&&this._destroyObserver(i)}}],[{key:"_setOptions",value:function(e,t){var r={root:null,rootMargin:"0px 0px 0px 0px",threshold:[0,1]};if("object"===(void 0===e?"undefined":o(e))){var i=e.top||0,n=e.bottom||0;r.rootMargin=i+"px 0px "+n+"px 0px"}else r.rootMargin=e+"px 0px "+e+"px 0px";return r.root=t,r}}]),e}();t.default=p,e.exports=t.default},function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),n=r(0),s=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(n),u=r(4),l=Object.values(s),a=new WeakMap,f=function(){function e(t,r,o){var n=this;i(this,e),this.$el=t,this.observer=r,this.manager=o,this.isInViewport=!1,this.isFullyInViewport=!1,this.isBeforeViewport=!1,this.isAfterViewport=!1,a.set(this,{}),l.forEach(function(e){a.get(n)[e]=[]})}return o(e,[{key:"init",value:function(){this.observer.observe(this.target)}},{key:"pause",value:function(){this.observer.unobserve(this.target)}},{key:"resume",value:function(){this.init()}},{key:"destroy",value:function(){this.pause(),this.manager._destroyItem(this)}},{key:"lock",value:function(){if(!this.isLocked){if("absolute"!==getComputedStyle(this.$el).position)throw new Error("[🎤 criss-cross] Target should be in absolute position.");for(var e=this.$el.cloneNode(!1),t=e.classList;t.length>0;)t.remove(t.item(0));e.style.position="absolute",e.style.top=this.$el.offsetTop+"px",e.style.left=this.$el.offsetLeft+"px",e.style.width="100%",e.style.height=(0,u.$outerHeight)(this.$el)+"px",e.style.visibility="hidden",e.style.opacity=0,this.$ghost=e,this.observer.unobserve(this.$el),this.observer.observe(this.$ghost),this.isLocked=!0,(0,u.$insertAfter)(e,this.$el)}}},{key:"unlock",value:function(){this.isLocked&&(this.observer.unobserve(this.$ghost),this.observer.observe(this.$el),this.isLocked=!1,this.$ghost.remove())}},{key:"on",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=a.get(this);if(!i[e])throw new Error("[🎤 criss-cross] Unavailable listener '"+e+"' ["+l.join(", ")+"]");i[e].push({cb:t,one:r})}},{key:"one",value:function(e,t){this.on(e,t,!0)}},{key:"off",value:function(e,t){var r=a.get(this);if(!r[e])throw new Error("[🎤 criss-cross] Unavailable listener '"+e+"' ["+l.join(", ")+"]");r[e].some(function(i,o){return i.cb===t&&r[e].splice(o,1),i.cb===t})}},{key:"trigger",value:function(e){var t=this,r=a.get(this);r[e].length>0&&r[e].forEach(function(r){r.cb(t),r.one&&t.off(e,r.cb)})}},{key:"target",get:function(){return this.isLocked?this.$ghost:this.$el}}]),e}();l.forEach(function(e){f.prototype[e]=function(t){this.on(e,t)}}),t.default=f,e.exports=t.default},function(e,t,r){"use strict";function i(e){var t=e.offsetWidth,r=getComputedStyle(e);return t+=parseInt(r.marginLeft,10)+parseInt(r.marginRight,10)}function o(e){var t=e.offsetHeight,r=getComputedStyle(e);return t+=parseInt(r.marginTop,10)+parseInt(r.marginBottom,10)}function n(e,t){t.parentNode.insertBefore(e,t.nextSibling)}Object.defineProperty(t,"__esModule",{value:!0}),t.$outerWidth=i,t.$outerHeight=o,t.$insertAfter=n}])}); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("crissCross",[],t):"object"==typeof exports?exports.crissCross=t():e.crissCross=t()}(this,function(){return function(e){function t(i){if(r[i])return r[i].exports;var o=r[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,i){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.ENTER_VIEWPORT="enterViewport",t.FULLY_ENTER_VIEWPORT="fullyEnterViewport",t.EXIT_VIEWPORT="exitViewport",t.FULLY_EXIT_VIEWPORT="fullyExitViewport",t.VISIBILITY_CHANGE="visibilityChange",t.STATE_CHANGE="stateChange"},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=r(2),o=function(e){return e&&e.__esModule?e:{default:e}}(i);t.default=new o.default,e.exports=t.default},function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),s=r(0),u=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(s),l=r(3),a=function(e){return e&&e.__esModule?e:{default:e}}(l),f=new WeakMap,c=new WeakMap,p=function(){function e(){i(this,e),f.set(this,[]),c.set(this,[]),this._intersected=this._intersected.bind(this)}return n(e,[{key:"create",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.offset,i=void 0===r?0:r,n=t.root,s=void 0===n?null:n,u=e;if("string"==typeof u&&(u=document.querySelector(e)),!(u&&u instanceof HTMLElement))throw new Error("[🎤 criss-cross] Invalid target. Should be an HTMLElement.");if(null!==s&&!s.contains(u))throw new Error("[🎤 criss-cross] Invalid target. Should be a child of root.");if(this.options={root:null,rootMargin:"0px 0px 0px 0px",threshold:[0,1]},"object"===(void 0===i?"undefined":o(i))){var l=i.top||0,a=i.bottom||0;this.options.rootMargin=l+"px 0px "+a+"px 0px"}else this.options.rootMargin=i+"px 0px "+i+"px 0px";this.options.root=s;var f=this._createObserver(this.options),c=this._createItem(u,f);return c.init(),c}},{key:"destroy",value:function(){var e=f.get(this),t=c.get(this);e.length=0,t.forEach(function(e){e.disconnect()}),t.length=0}},{key:"_intersected",value:function(e,t){var r=this._getItems(t);e.forEach(function(e){var t=r.find(function(t){return t.isLocked?t.$ghost===e.target:t.$el===e.target});t.isBeforeViewport=e.boundingClientRect.top<e.rootBounds.top,t.isAfterViewport=e.boundingClientRect.top+e.boundingClientRect.height>e.rootBounds.top+e.rootBounds.height,e.isIntersecting?(t.isInViewport=!0,e.intersectionRatio>=1?t.isFullyInViewport=!0:t.isFullyInViewport=!1):(t.isInViewport=!1,t.isFullyInViewport=!1),void 0===t.wasInViewport?(t.isInViewport&&!t.isFullyInViewport&&(t.isAfterViewport&&t.trigger(u.ENTER_VIEWPORT),t.isBeforeViewport&&t.trigger(u.EXIT_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE)),t.isFullyInViewport&&(t.trigger(u.FULLY_ENTER_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE)),!t.isInViewport&&t.isBeforeViewport&&(t.trigger(u.EXIT_VIEWPORT),t.trigger(u.FULLY_EXIT_VIEWPORT))):(t.isInViewport&&!t.wasInViewport&&(t.trigger(u.ENTER_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE),t.trigger(u.STATE_CHANGE)),t.isFullyInViewport&&!t.wasFullyInViewport&&(t.trigger(u.FULLY_ENTER_VIEWPORT),t.trigger(u.STATE_CHANGE)),!t.isFullyInViewport&&t.wasFullyInViewport&&(t.trigger(u.EXIT_VIEWPORT),t.trigger(u.STATE_CHANGE)),!t.isInViewport&&t.wasInViewport&&(t.trigger(u.FULLY_EXIT_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE),t.trigger(u.STATE_CHANGE))),t.wasBeforeViewport=t.isBeforeViewport,t.wasInViewport=t.isInViewport,t.wasFullyInViewport=t.isFullyInViewport,t.wasAfterViewport=t.isAfterViewport})}},{key:"_createObserver",value:function(e){var t=this._getObserver(e);if(t)return t;var r=new IntersectionObserver(this._intersected,e);return this._addObserver(r),r}},{key:"_addObserver",value:function(e){c.get(this).push(e)}},{key:"_getObserver",value:function(e){return c.get(this).find(function(t){return t.root===e.root&&t.rootMargin===e.rootMargin})}},{key:"_destroyObserver",value:function(e){var t=c.get(this),r=t.indexOf(e);e.disconnect(),t.splice(r,1)}},{key:"_createItem",value:function(e,t){var r=new a.default(e,t,this);return this._addItem(r),r}},{key:"_addItem",value:function(e){f.get(this).push(e)}},{key:"_getItems",value:function(e){return f.get(this).filter(function(t){return t.observer===e})}},{key:"_destroyItem",value:function(e){var t=f.get(this),r=t.indexOf(e),i=e.observer;t.splice(r,1),0===this._getItems(i).length&&this._destroyObserver(i)}}]),e}();t.default=p,e.exports=t.default},function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),n=r(0),s=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(n),u=r(4),l=Object.values(s),a=new WeakMap,f=function(){function e(t,r,o){var n=this;i(this,e),this.$el=t,this.observer=r,this.manager=o,this.isInViewport=!1,this.isFullyInViewport=!1,this.isBeforeViewport=!1,this.isAfterViewport=!1,a.set(this,{}),l.forEach(function(e){a.get(n)[e]=[]})}return o(e,[{key:"init",value:function(){this.observer.observe(this.target)}},{key:"pause",value:function(){this.observer.unobserve(this.target)}},{key:"resume",value:function(){this.init()}},{key:"destroy",value:function(){this.pause(),this.manager._destroyItem(this)}},{key:"lock",value:function(){if(!this.isLocked){if("absolute"!==getComputedStyle(this.$el).position)throw new Error("[🎤 criss-cross] Target should be in absolute position.");for(var e=this.$el.cloneNode(!1),t=e.classList;t.length>0;)t.remove(t.item(0));e.style.position="absolute",e.style.top=this.$el.offsetTop+"px",e.style.left=this.$el.offsetLeft+"px",e.style.width="100%",e.style.height=(0,u.$outerHeight)(this.$el)+"px",e.style.visibility="hidden",e.style.opacity=0,this.$ghost=e,this.observer.unobserve(this.$el),this.observer.observe(this.$ghost),this.isLocked=!0,(0,u.$insertAfter)(e,this.$el)}}},{key:"unlock",value:function(){this.isLocked&&(this.observer.unobserve(this.$ghost),this.observer.observe(this.$el),this.isLocked=!1,this.$ghost.remove())}},{key:"on",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=a.get(this);if(!i[e])throw new Error("[🎤 criss-cross] Unavailable listener '"+e+"' ["+l.join(", ")+"]");i[e].push({cb:t,one:r})}},{key:"one",value:function(e,t){this.on(e,t,!0)}},{key:"off",value:function(e,t){var r=a.get(this);if(!r[e])throw new Error("[🎤 criss-cross] Unavailable listener '"+e+"' ["+l.join(", ")+"]");r[e].some(function(i,o){return i.cb===t&&r[e].splice(o,1),i.cb===t})}},{key:"trigger",value:function(e){var t=this,r=a.get(this);r[e].length>0&&r[e].forEach(function(r){r.cb(t),r.one&&t.off(e,r.cb)})}},{key:"target",get:function(){return this.isLocked?this.$ghost:this.$el}}]),e}();l.forEach(function(e){f.prototype[e]=function(t){this.on(e,t)}}),t.default=f,e.exports=t.default},function(e,t,r){"use strict";function i(e){var t=e.offsetWidth,r=getComputedStyle(e);return t+=parseInt(r.marginLeft,10)+parseInt(r.marginRight,10)}function o(e){var t=e.offsetHeight,r=getComputedStyle(e);return t+=parseInt(r.marginTop,10)+parseInt(r.marginBottom,10)}function n(e,t){t.parentNode.insertBefore(e,t.nextSibling)}Object.defineProperty(t,"__esModule",{value:!0}),t.$outerWidth=i,t.$outerHeight=o,t.$insertAfter=n}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("crissCross",[],t):"object"==typeof exports?exports.crissCross=t():e.crissCross=t()}(this,function(){return function(e){function t(i){if(r[i])return r[i].exports;var o=r[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,i){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.ENTER_VIEWPORT="enterViewport",t.FULLY_ENTER_VIEWPORT="fullyEnterViewport",t.EXIT_VIEWPORT="exitViewport",t.FULLY_EXIT_VIEWPORT="fullyExitViewport",t.VISIBILITY_CHANGE="visibilityChange",t.STATE_CHANGE="stateChange"},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=r(2),o=function(e){return e&&e.__esModule?e:{default:e}}(i);t.default=new o.default,e.exports=t.default},function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),s=r(0),u=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(s),l=r(3),a=function(e){return e&&e.__esModule?e:{default:e}}(l),f=new WeakMap,c=new WeakMap,p=function(){function e(){i(this,e),f.set(this,[]),c.set(this,[]),this._intersected=this._intersected.bind(this)}return n(e,[{key:"create",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.offset,o=void 0===i?0:i,n=r.root,s=void 0===n?null:n,u=t;if("string"==typeof u&&(u=document.querySelector(t)),!(u&&u instanceof HTMLElement))throw new Error("[🎤 criss-cross] Invalid target. Should be an HTMLElement.");if(null!==s&&!s.contains(u))throw new Error("[🎤 criss-cross] Invalid target. Should be a child of root.");var l=e._setOptions(o,s),a=this._createObserver(l),f=this._createItem(u,a);return f.init(),f}},{key:"update",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=r.offset,o=void 0===i?0:i,n=r.root,s=void 0===n?null:n;t.pause(),this._destroyObserver(t.observer);var u=e._setOptions(o,s),l=this._createObserver(u);t.observer=l,t.resume()}},{key:"destroy",value:function(){var e=f.get(this),t=c.get(this);e.length=0,t.forEach(function(e){e.disconnect()}),t.length=0}},{key:"_intersected",value:function(e,t){var r=this._getItems(t);e.forEach(function(e){var t=r.find(function(t){return t.isLocked?t.$ghost===e.target:t.$el===e.target});t.isBeforeViewport=e.boundingClientRect.top<e.rootBounds.top,t.isAfterViewport=e.boundingClientRect.top+e.boundingClientRect.height>e.rootBounds.top+e.rootBounds.height,e.isIntersecting?(t.isInViewport=!0,e.intersectionRatio>=1?t.isFullyInViewport=!0:t.isFullyInViewport=!1):(t.isInViewport=!1,t.isFullyInViewport=!1),void 0===t.wasInViewport?(t.isInViewport&&!t.isFullyInViewport&&(t.isAfterViewport&&t.trigger(u.ENTER_VIEWPORT),t.isBeforeViewport&&t.trigger(u.EXIT_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE)),t.isFullyInViewport&&(t.trigger(u.FULLY_ENTER_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE)),!t.isInViewport&&t.isBeforeViewport&&(t.trigger(u.EXIT_VIEWPORT),t.trigger(u.FULLY_EXIT_VIEWPORT))):(t.isInViewport&&!t.wasInViewport&&(t.trigger(u.ENTER_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE),t.trigger(u.STATE_CHANGE)),t.isFullyInViewport&&!t.wasFullyInViewport&&(t.trigger(u.FULLY_ENTER_VIEWPORT),t.trigger(u.STATE_CHANGE)),!t.isFullyInViewport&&t.wasFullyInViewport&&(t.trigger(u.EXIT_VIEWPORT),t.trigger(u.STATE_CHANGE)),!t.isInViewport&&t.wasInViewport&&(t.trigger(u.FULLY_EXIT_VIEWPORT),t.trigger(u.VISIBILITY_CHANGE),t.trigger(u.STATE_CHANGE))),t.wasBeforeViewport=t.isBeforeViewport,t.wasInViewport=t.isInViewport,t.wasFullyInViewport=t.isFullyInViewport,t.wasAfterViewport=t.isAfterViewport})}},{key:"_createObserver",value:function(e){var t=this._getObserver(e);if(t)return t;var r=new IntersectionObserver(this._intersected,e);return this._addObserver(r),r}},{key:"_addObserver",value:function(e){c.get(this).push(e)}},{key:"_getObserver",value:function(e){return c.get(this).find(function(t){return t.root===e.root&&t.rootMargin===e.rootMargin})}},{key:"_destroyObserver",value:function(e){var t=c.get(this),r=t.indexOf(e);e.disconnect(),t.splice(r,1)}},{key:"_createItem",value:function(e,t){var r=new a.default(e,t,this);return this._addItem(r),r}},{key:"_addItem",value:function(e){f.get(this).push(e)}},{key:"_getItems",value:function(e){return f.get(this).filter(function(t){return t.observer===e})}},{key:"_destroyItem",value:function(e){var t=f.get(this),r=t.indexOf(e),i=e.observer;t.splice(r,1),0===this._getItems(i).length&&this._destroyObserver(i)}}],[{key:"_setOptions",value:function(e,t){var r={root:null,rootMargin:"0px 0px 0px 0px",threshold:[0,1]};if("object"===(void 0===e?"undefined":o(e))){var i=e.top||0,n=e.bottom||0;r.rootMargin=i+"px 0px "+n+"px 0px"}else r.rootMargin=e+"px 0px "+e+"px 0px";return r.root=t,r}}]),e}();t.default=p,e.exports=t.default},function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),n=r(0),s=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(n),u=r(4),l=Object.values(s),a=new WeakMap,f=function(){function e(t,r,o){var n=this;i(this,e),this.$el=t,this.observer=r,this.manager=o,this.isInViewport=!1,this.isFullyInViewport=!1,this.isBeforeViewport=!1,this.isAfterViewport=!1,a.set(this,{}),l.forEach(function(e){a.get(n)[e]=[]})}return o(e,[{key:"init",value:function(){this.observer.observe(this.target)}},{key:"pause",value:function(){this.observer.unobserve(this.target)}},{key:"resume",value:function(){this.init()}},{key:"destroy",value:function(){this.pause(),this.manager._destroyItem(this)}},{key:"lock",value:function(){if(!this.isLocked){if("absolute"!==getComputedStyle(this.$el).position)throw new Error("[🎤 criss-cross] Target should be in absolute position.");for(var e=this.$el.cloneNode(!1),t=e.classList;t.length>0;)t.remove(t.item(0));e.style.position="absolute",e.style.top=this.$el.offsetTop+"px",e.style.left=this.$el.offsetLeft+"px",e.style.width="100%",e.style.height=(0,u.$outerHeight)(this.$el)+"px",e.style.visibility="hidden",e.style.opacity=0,this.$ghost=e,this.observer.unobserve(this.$el),this.observer.observe(this.$ghost),this.isLocked=!0,(0,u.$insertAfter)(e,this.$el)}}},{key:"unlock",value:function(){this.isLocked&&(this.observer.unobserve(this.$ghost),this.observer.observe(this.$el),this.isLocked=!1,this.$ghost.remove())}},{key:"on",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=a.get(this);if(!i[e])throw new Error("[🎤 criss-cross] Unavailable listener '"+e+"' ["+l.join(", ")+"]");i[e].push({cb:t,one:r})}},{key:"one",value:function(e,t){this.on(e,t,!0)}},{key:"off",value:function(e,t){var r=a.get(this);if(!r[e])throw new Error("[🎤 criss-cross] Unavailable listener '"+e+"' ["+l.join(", ")+"]");r[e].some(function(i,o){return i.cb===t&&r[e].splice(o,1),i.cb===t})}},{key:"trigger",value:function(e){var t=this,r=a.get(this);r[e].length>0&&r[e].forEach(function(r){r.cb(t),r.one&&t.off(e,r.cb)})}},{key:"target",get:function(){return this.isLocked?this.$ghost:this.$el}}]),e}();l.forEach(function(e){f.prototype[e]=function(t){this.on(e,t)}}),t.default=f,e.exports=t.default},function(e,t,r){"use strict";function i(e){var t=e.offsetWidth,r=getComputedStyle(e);return t+=parseInt(r.marginLeft,10)+parseInt(r.marginRight,10)}function o(e){var t=e.offsetHeight,r=getComputedStyle(e);return t+=parseInt(r.marginTop,10)+parseInt(r.marginBottom,10)}function n(e,t){t.parentNode.insertBefore(e,t.nextSibling)}Object.defineProperty(t,"__esModule",{value:!0}),t.$outerWidth=i,t.$outerHeight=o,t.$insertAfter=n}])}); |
@@ -49,23 +49,4 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
this.options = { | ||
root: null, | ||
rootMargin: '0px 0px 0px 0px', | ||
// !DEV | ||
// precision properties ? from > 0 to 1 ? | ||
// threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], // Perf matters? | ||
threshold: [0, 1] | ||
}; | ||
if ((typeof offset === 'undefined' ? 'undefined' : _typeof(offset)) === 'object') { | ||
var top = offset.top || 0; | ||
var bottom = offset.bottom || 0; | ||
this.options.rootMargin = top + 'px 0px ' + bottom + 'px 0px'; | ||
} else { | ||
this.options.rootMargin = offset + 'px 0px ' + offset + 'px 0px'; | ||
} | ||
this.options.root = root; | ||
var observer = this._createObserver(this.options); | ||
var options = CrissCross._setOptions(offset, root); | ||
var observer = this._createObserver(options); | ||
var item = this._createItem($el, observer); | ||
@@ -77,13 +58,20 @@ | ||
} | ||
}, { | ||
key: 'update', | ||
value: function update(item) { | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$offset = _ref2.offset, | ||
offset = _ref2$offset === undefined ? 0 : _ref2$offset, | ||
_ref2$root = _ref2.root, | ||
root = _ref2$root === undefined ? null : _ref2$root; | ||
// !DEV | ||
// May be not needed? | ||
// update() { | ||
// const items = _items.get(this); | ||
item.pause(); | ||
this._destroyObserver(item.observer); | ||
// items.forEach(item => { | ||
// item.update(); | ||
// }); | ||
// } | ||
var options = CrissCross._setOptions(offset, root); | ||
var observer = this._createObserver(options); | ||
item.observer = observer; | ||
item.resume(); | ||
} | ||
}, { | ||
@@ -260,2 +248,27 @@ key: 'destroy', | ||
} | ||
}], [{ | ||
key: '_setOptions', | ||
value: function _setOptions(offset, root) { | ||
var options = { | ||
root: null, | ||
rootMargin: '0px 0px 0px 0px', | ||
// !DEV | ||
// precision properties ? from > 0 to 1 ? | ||
// threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], // Perf matters? | ||
threshold: [0, 1] | ||
}; | ||
if ((typeof offset === 'undefined' ? 'undefined' : _typeof(offset)) === 'object') { | ||
var top = offset.top || 0; | ||
var bottom = offset.bottom || 0; | ||
options.rootMargin = top + 'px 0px ' + bottom + 'px 0px'; | ||
} else { | ||
options.rootMargin = offset + 'px 0px ' + offset + 'px 0px'; | ||
} | ||
options.root = root; | ||
return options; | ||
} | ||
}]); | ||
@@ -262,0 +275,0 @@ |
@@ -54,10 +54,2 @@ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
} | ||
// !DEV | ||
// May be not needed? | ||
// update() { | ||
// this.pause(); | ||
// this.resume(); | ||
// } | ||
}, { | ||
@@ -64,0 +56,0 @@ key: 'lock', |
@@ -64,23 +64,4 @@ 'use strict'; | ||
this.options = { | ||
root: null, | ||
rootMargin: '0px 0px 0px 0px', | ||
// !DEV | ||
// precision properties ? from > 0 to 1 ? | ||
// threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], // Perf matters? | ||
threshold: [0, 1] | ||
}; | ||
if ((typeof offset === 'undefined' ? 'undefined' : _typeof(offset)) === 'object') { | ||
var top = offset.top || 0; | ||
var bottom = offset.bottom || 0; | ||
this.options.rootMargin = top + 'px 0px ' + bottom + 'px 0px'; | ||
} else { | ||
this.options.rootMargin = offset + 'px 0px ' + offset + 'px 0px'; | ||
} | ||
this.options.root = root; | ||
var observer = this._createObserver(this.options); | ||
var options = CrissCross._setOptions(offset, root); | ||
var observer = this._createObserver(options); | ||
var item = this._createItem($el, observer); | ||
@@ -92,13 +73,20 @@ | ||
} | ||
}, { | ||
key: 'update', | ||
value: function update(item) { | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$offset = _ref2.offset, | ||
offset = _ref2$offset === undefined ? 0 : _ref2$offset, | ||
_ref2$root = _ref2.root, | ||
root = _ref2$root === undefined ? null : _ref2$root; | ||
// !DEV | ||
// May be not needed? | ||
// update() { | ||
// const items = _items.get(this); | ||
item.pause(); | ||
this._destroyObserver(item.observer); | ||
// items.forEach(item => { | ||
// item.update(); | ||
// }); | ||
// } | ||
var options = CrissCross._setOptions(offset, root); | ||
var observer = this._createObserver(options); | ||
item.observer = observer; | ||
item.resume(); | ||
} | ||
}, { | ||
@@ -275,2 +263,27 @@ key: 'destroy', | ||
} | ||
}], [{ | ||
key: '_setOptions', | ||
value: function _setOptions(offset, root) { | ||
var options = { | ||
root: null, | ||
rootMargin: '0px 0px 0px 0px', | ||
// !DEV | ||
// precision properties ? from > 0 to 1 ? | ||
// threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], // Perf matters? | ||
threshold: [0, 1] | ||
}; | ||
if ((typeof offset === 'undefined' ? 'undefined' : _typeof(offset)) === 'object') { | ||
var top = offset.top || 0; | ||
var bottom = offset.bottom || 0; | ||
options.rootMargin = top + 'px 0px ' + bottom + 'px 0px'; | ||
} else { | ||
options.rootMargin = offset + 'px 0px ' + offset + 'px 0px'; | ||
} | ||
options.root = root; | ||
return options; | ||
} | ||
}]); | ||
@@ -277,0 +290,0 @@ |
@@ -65,10 +65,2 @@ 'use strict'; | ||
} | ||
// !DEV | ||
// May be not needed? | ||
// update() { | ||
// this.pause(); | ||
// this.resume(); | ||
// } | ||
}, { | ||
@@ -75,0 +67,0 @@ key: 'lock', |
{ | ||
"name": "criss-cross", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A simple and fast API to manage viewport and DOM elements intersections as you scroll", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/thierrymichel/criss-cross#readme", |
@@ -106,2 +106,16 @@ # 🎤 criss-cross | ||
### update(watchItem, [options]) | ||
#### target | ||
Type: `Item` | ||
The watchItem you want to update the observer. | ||
#### options | ||
Type: `Object` | ||
Same as `create()` options parameter… | ||
--- | ||
@@ -108,0 +122,0 @@ |
@@ -36,23 +36,4 @@ import * as events from './event-types'; | ||
this.options = { | ||
root: null, | ||
rootMargin: '0px 0px 0px 0px', | ||
// !DEV | ||
// precision properties ? from > 0 to 1 ? | ||
// threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], // Perf matters? | ||
threshold: [0, 1], | ||
}; | ||
if (typeof offset === 'object') { | ||
const top = offset.top || 0; | ||
const bottom = offset.bottom || 0; | ||
this.options.rootMargin = `${top}px 0px ${bottom}px 0px`; | ||
} else { | ||
this.options.rootMargin = `${offset}px 0px ${offset}px 0px`; | ||
} | ||
this.options.root = root; | ||
const observer = this._createObserver(this.options); | ||
const options = CrissCross._setOptions(offset, root); | ||
const observer = this._createObserver(options); | ||
const item = this._createItem($el, observer); | ||
@@ -65,12 +46,16 @@ | ||
// !DEV | ||
// May be not needed? | ||
// update() { | ||
// const items = _items.get(this); | ||
update(item, { | ||
offset = 0, | ||
root = null, | ||
} = {}) { | ||
item.pause(); | ||
this._destroyObserver(item.observer); | ||
// items.forEach(item => { | ||
// item.update(); | ||
// }); | ||
// } | ||
const options = CrissCross._setOptions(offset, root); | ||
const observer = this._createObserver(options); | ||
item.observer = observer; | ||
item.resume(); | ||
} | ||
destroy() { | ||
@@ -87,2 +72,26 @@ const items = _items.get(this); | ||
static _setOptions(offset, root) { | ||
const options = { | ||
root: null, | ||
rootMargin: '0px 0px 0px 0px', | ||
// !DEV | ||
// precision properties ? from > 0 to 1 ? | ||
// threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], // Perf matters? | ||
threshold: [0, 1], | ||
}; | ||
if (typeof offset === 'object') { | ||
const top = offset.top || 0; | ||
const bottom = offset.bottom || 0; | ||
options.rootMargin = `${top}px 0px ${bottom}px 0px`; | ||
} else { | ||
options.rootMargin = `${offset}px 0px ${offset}px 0px`; | ||
} | ||
options.root = root; | ||
return options; | ||
} | ||
_intersected(entries, observer) { | ||
@@ -89,0 +98,0 @@ // Get observed items |
@@ -49,9 +49,2 @@ import * as events from './event-types'; | ||
// !DEV | ||
// May be not needed? | ||
// update() { | ||
// this.pause(); | ||
// this.resume(); | ||
// } | ||
lock() { | ||
@@ -58,0 +51,0 @@ if (this.isLocked) { |
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
67494
1218
177