@nrk/core-scroll
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -267,3 +267,3 @@ (function (global, factory) { | ||
_this[k] = function (event) { | ||
return _this.props[on] && _this.props[on](event); | ||
return _this.props[on] && closest(event.target, _this.el.nodeName) === _this.el && _this.props[on](event); | ||
}; | ||
@@ -270,0 +270,0 @@ }); |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-scroll v4.0.0 - Copyright (c) 2017-2019 NRK */ | ||
/*! @nrk/core-scroll v4.0.1 - Copyright (c) 2017-2019 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).coreScroll=e()}(this,function(){"use strict";function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(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)}}function l(t){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e,n){return(r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,n){var o=[null];o.push.apply(o,e);var r=new(Function.bind.apply(t,o));return n&&c(r,n.prototype),r}).apply(null,arguments)}function s(t){var o="function"==typeof Map?new Map:void 0;return(s=function(t){if(null===t||(e=t,-1===Function.toString.call(e).indexOf("[native code]")))return t;var e;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==o){if(o.has(t))return o.get(t);o.set(t,n)}function n(){return r(t,arguments,l(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),c(n,t)})(t)}function a(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}var t="undefined"!=typeof window;t&&/(android)/i.test(navigator.userAgent),t&&/iPad|iPhone|iPod/.test(String(navigator.platform));t&&!window.Element.prototype.toggleAttribute&&(window.Element.prototype.toggleAttribute=function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:!this.hasAttribute(t);return!e===this.hasAttribute(t)&&this[e?"setAttribute":"removeAttribute"](t,""),e});var e,n,f=(e="undefined"==typeof window?{}:window.Element.prototype,n=e.matches||e.msMatchesSelector||e.webkitMatchesSelector,e.closest?function(t,e){return t.closest(e)}:function(t,e){for(;t;t=t.parentElement)if(n.call(t,e))return t;return null});function h(t,e){var n,o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},r="prevent_recursive_dispatch_maximum_callstack".concat(e);if(t[r])return!0;t[r]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(e,{bubbles:!0,cancelable:!0,detail:o}):(n=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,o);var i=t.dispatchEvent(n);return t[r]=null,i}function d(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document;if(t){if(t.nodeType)return[t];if("string"==typeof t)return[].slice.call(e.querySelectorAll(t));if(t.length)return[].slice.call(t)}return[]}var p={},v={up:{y:-1,prop:"top"},down:{y:1,prop:"bottom"},left:{x:-1},right:{x:1}},m=function(){var t=0<arguments.length&&void 0!==arguments[0]&&arguments[0];try{window.addEventListener("test",null,{get passive(){t={passive:!0}}})}catch(t){}return t}(),y=t&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion)").matches,g=t&&(window.requestAnimationFrame||window.setTimeout);function b(t){p.diffX=p.pageX-(p.pageX=t.pageX),p.diffY=p.pageY-(p.pageY=t.pageY),p.target.scrollLeft=p.scrollX+=p.diffX,p.target.scrollTop=p.scrollY+=p.diffY,(10<Math.abs(p.scrollX)||10<Math.abs(p.scrollY))&&(p.target.style.pointerEvents="none")}function w(t){var e=p.diffX||p.diffY?20:0;document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",w),document.body.style.cursor="",e&&p.target.scroll({x:p.scrollX+p.diffX*e,y:p.scrollY+p.diffY*e}),p.target.style.pointerEvents="",p.target.style.cursor="-webkit-grab",p.target.style.cursor="grab",p.target=null}return function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),a(this,l(e).apply(this,arguments))}var n,o,r;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&c(t,e)}(e,s(HTMLElement)),n=e,(o=[{key:"connectedCallback",value:function(){var t,e,n,o,r=this;t=this.nodeName,e="\n ".concat(this.nodeName,"{display:block}\n ").concat(this.nodeName,"::-webkit-scrollbar{display:none}\n "),n="style-".concat(t.toLowerCase()),o=e.replace(/\/\*[^!][^*]*\*\//g,"").replace(/\s*(^|[:;,{}]|$)\s*/g,"$1"),document.getElementById(n)||document.head.insertAdjacentHTML("afterbegin",'<style id="'.concat(n,'">').concat(o,"</style>")),this.style.overflow="scroll",this.style.willChange="scroll-position",this.style.webkitOverflowScrolling="touch";var i,l,c,s=this.offsetWidth-this.clientWidth,u=this.offsetHeight-this.clientHeight;this.style.marginRight="-".concat(s,"px"),this.style.marginBottom="-".concat(u,"px"),this.style.maxHeight="calc(100% + ".concat(u,"px)"),this._throttledEvent=(i=this.handleEvent.bind(this),l=500,function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];c||(c=setTimeout(function(){i.apply(this,e),c=null},l))}),this.addEventListener("mousedown",this),this.addEventListener("wheel",this,m),this.addEventListener("scroll",this._throttledEvent,m),window.addEventListener("resize",this._throttledEvent,m),window.addEventListener("load",this),document.addEventListener("click",this),setTimeout(function(){return r.handleEvent()})}},{key:"disconnectedCallback",value:function(){this._throttledEvent=null,this.removeEventListener("mousedown",this),this.removeEventListener("wheel",this,m),this.removeEventListener("scroll",this._throttledEvent,m),window.removeEventListener("resize",this._throttledEvent,m),window.removeEventListener("load",this),document.removeEventListener("click",this)}},{key:"handleEvent",value:function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};if(!t.defaultPrevented)if("wheel"===t.type)p.animate=!1;else if("mousedown"===t.type)(function(t){if(f(t.target,'[contenteditable="true"],input,select,textarea'))return;t.preventDefault(),p.pageX=t.pageX,p.pageY=t.pageY,p.animate=p.diffX=p.diffY=0,p.scrollX=this.scrollLeft,p.scrollY=this.scrollTop,p.target=this,document.body.style.cursor=this.style.cursor="-webkit-grabbing",document.body.style.cursor=this.style.cursor="grabbing",document.addEventListener("mousemove",b),document.addEventListener("mouseup",w)}).call(this,t);else if("click"===t.type){var e=this.id&&f(t.target,'[for="'.concat(this.id,'"]'));e&&h(this,"scroll.click",{move:e.value})&&this.scroll(e.value)}else{var n={left:this.scrollLeft,up:this.scrollTop,right:this.scrollRight,down:this.scrollBottom},o=n.left||n.right||n.up||n.down?"grab":"";d(this.id&&'[for="'.concat(this.id,'"]')).forEach(function(t){return t.disabled=!n[t.value]}),h(this,"scroll.change"),t.type||(this.style.cursor="-webkit-".concat(o),this.style.cursor=o)}}},{key:"scroll",value:function(t){var e=this,n=function(t,o){var r="object"===u(o)?o:{move:o};"number"!=typeof r.x&&(r.x=t.scrollLeft);"number"!=typeof r.y&&(r.y=t.scrollTop);if(r.move=v[r.move]){var i=r.move.x?"x":"y",l=r.move.x?"left":"top",e=t.getBoundingClientRect(),c=e[l]-t[r.move.x?"scrollLeft":"scrollTop"],s=e[l]+e[r.move.x?"width":"height"]*r.move[i];d(t.children).every(function(t){var e=t.getBoundingClientRect(),n=t.ownerDocument.defaultView.getComputedStyle(t)["margin-".concat(l)];return r[i]=e[l]-parseInt(n,10)-c,e[r.move.prop||o]<s})}return{x:Math.max(0,Math.min(r.x,t.scrollWidth-t.clientWidth)),y:Math.max(0,Math.min(r.y,t.scrollHeight-t.clientHeight))}}(this,t),o=n.x,r=n.y,i=p.animate=Date.now().toString(36)+Math.random().toString(36).slice(2,5),l=this.friction,c=y?1:o-this.scrollLeft,s=y?1:r-this.scrollTop;!function t(){p.animate===i&&(Math.round(c)||Math.round(s))&&(e.scrollLeft=o-Math.round(c*=l),e.scrollTop=r-Math.round(s*=l),g(t))}()}},{key:"scrollRight",get:function(){return this.scrollWidth-this.clientWidth-this.scrollLeft}},{key:"scrollBottom",get:function(){return this.scrollHeight-this.clientHeight-this.scrollTop}},{key:"friction",get:function(){return Math.min(.99,this.getAttribute("friction"))||.8},set:function(t){this.setAttribute("friction",t)}}])&&i(n.prototype,o),r&&i(n,r),e}()}),window.customElements.define("core-scroll",coreScroll); | ||
//# sourceMappingURL=core-scroll.min.js.map |
@@ -265,3 +265,3 @@ 'use strict'; | ||
_this[k] = function (event) { | ||
return _this.props[on] && _this.props[on](event); | ||
return _this.props[on] && closest(event.target, _this.el.nodeName) === _this.el && _this.props[on](event); | ||
}; | ||
@@ -268,0 +268,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-scroll.cjs.js", |
@@ -114,3 +114,3 @@ # Core Scroll | ||
```html | ||
<script src="https://static.nrk.no/core-components/major/5/core-scroll/core-scroll.min.js"></script> <!-- Using static --> | ||
<script src="https://static.nrk.no/core-components/major/6/core-scroll/core-scroll.min.js"></script> <!-- Using static --> | ||
``` | ||
@@ -117,0 +117,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
165325
13