@nrk/core-scroll
Advanced tools
Comparing version 3.1.0 to 3.1.1
'use strict'; | ||
var name = "@nrk/core-scroll"; | ||
var version = "3.0.2"; | ||
var version = "3.1.0"; | ||
@@ -140,2 +140,3 @@ var IS_BROWSER = typeof window !== 'undefined'; | ||
var VELOCITY = 20; | ||
var NEEDS_MOUSEDOWN = /INPUT|TEXTAREA|SELECT/; | ||
@@ -172,2 +173,3 @@ // https://css-tricks.com/introduction-reduced-motion-media-query/ | ||
for (var el = event.target; el; el = el.parentElement) { | ||
if (el.contentEditable === 'true' || NEEDS_MOUSEDOWN.test(el.nodeName)) { return } // No dragging when user clicks input fields | ||
if (!event.defaultPrevented && el.hasAttribute && el.hasAttribute(UUID)) { | ||
@@ -174,0 +176,0 @@ event.preventDefault(); // Prevent text selection and enable nesting |
@@ -11,2 +11,3 @@ import { name, version } from './package.json' | ||
const VELOCITY = 20 | ||
const NEEDS_MOUSEDOWN = /INPUT|TEXTAREA|SELECT/ | ||
@@ -40,2 +41,3 @@ // https://css-tricks.com/introduction-reduced-motion-media-query/ | ||
for (let el = event.target; el; el = el.parentElement) { | ||
if (el.contentEditable === 'true' || NEEDS_MOUSEDOWN.test(el.nodeName)) return // No dragging when user clicks input fields | ||
if (!event.defaultPrevented && el.hasAttribute && el.hasAttribute(UUID)) { | ||
@@ -42,0 +44,0 @@ event.preventDefault() // Prevent text selection and enable nesting |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-scroll v3.0.2 - Copyright (c) 2017-2018 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],e):t.CoreScroll=e(t.React,t.PropTypes)}(this,function(l,t){"use strict";l=l&&l.hasOwnProperty("default")?l.default:l,t=t&&t.hasOwnProperty("default")?t.default:t;var e="undefined"!=typeof window,r=(e&&/(android)/i.test(navigator.userAgent),e&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(t){void 0===t&&(t=!1);try{window.addEventListener("test",null,{get passive(){t=!0}})}catch(t){}return t}());function p(t,e,o,n){(void 0===n&&(n=!1),"undefined"==typeof window||window[t=t+"-"+e])||(r||"object"!=typeof n||(n=Boolean(n.capture)),("resize"===e||"load"===e?window:document).addEventListener(window[t]=e,o,n))}var s="prevent_recursive_dispatch_maximum_callstack";function i(t,e,o){void 0===o&&(o={});var n,r=""+s+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 f(t){(window.requestAnimationFrame||window.setTimeout)(t)}function h(t,e){if(void 0===e&&(e=document),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 d={},c="data-core-scroll",m="data-@nrk/core-scroll-3.0.2".replace(/\W+/g,"-"),v={up:{y:-1,prop:"top"},down:{y:1,prop:"bottom"},left:{x:-1},right:{x:1}},o=10,g=.8,n=20,y=e&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion)").matches;function a(t,e,u){void 0===e&&(e=""),void 0===u&&(u={});var f="object"==typeof e?e:{move:e},d="x"in f||"y"in f||f.move;return h(t).map(function(t){var o,n,r,i,l,s,c,a;return t.hasAttribute(m)||(t.setAttribute(m,f.friction||""),p(m,"resize",(l=b,s=u.resizeMs||500,function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var o=this,n=Date.now();c&&n<c+s?(clearTimeout(a),a=setTimeout(function(){c=n,l.apply(o,t)},s)):(c=n,l.apply(o,t))})),p(m,"scroll",(o=b,n=u.scrollMs||500,function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];r=t,i||(i=setTimeout(function(){o.apply(this,r),i=null},n))}),!0),function(t){document.getElementById(m)||document.head.insertAdjacentHTML("beforeend",'<style id="'+m+'">['+m+"]::-webkit-scrollbar{display:none}</style>");t.style.overflow="scroll",t.style.willChange="scroll-position",t.style.webkitOverflowScrolling="touch";var e=t.offsetWidth-t.clientWidth,o=t.offsetHeight-t.clientHeight;t.style.marginRight="-"+e+"px",t.style.marginBottom="-"+o+"px",t.style.maxHeight="calc(100% + "+o+"px)"}(t)),d?x(t,function(t,e){var o=e.x,n=e.y,r=e.move,i={x:o,y:n,move:v[r]};"number"!=typeof i.x&&(i.x=t.scrollLeft);"number"!=typeof i.y&&(i.y=t.scrollTop);if(i.move){var l=i.move.x?"x":"y",s=i.move.x?"left":"top",c=t.getBoundingClientRect(),a=c[s]-t[i.move.x?"scrollLeft":"scrollTop"],u=c[s]+c[i.move.x?"width":"height"]*i.move[l];h(t.children).every(function(t){var e=t.getBoundingClientRect(),o=t.ownerDocument.defaultView.getComputedStyle(t)["margin-"+s];return i[l]=e[s]-parseInt(o,10)-a,e[i.move.prop||r]<u})}return i}(t,f)):b(t),t})}function u(t){d.diffX=d.pageX-(d.pageX=t.pageX),d.diffY=d.pageY-(d.pageY=t.pageY),d.diffSumX+=d.diffX,d.diffSumY+=d.diffY,d.target.scrollLeft=d.scrollX+=d.diffX,d.target.scrollTop=d.scrollY+=d.diffY,(Math.abs(d.diffSumX)>o||Math.abs(d.diffSumY)>o)&&(d.target.style.pointerEvents="none")}function w(t){var e=d.diffX||d.diffY;document.removeEventListener("mousemove",u),document.removeEventListener("mouseup",w),document.body.style.cursor="",b(d.target),e&&x(d.target,{x:d.scrollX+d.diffX*n,y:d.scrollY+d.diffY*n}),d.target.style.pointerEvents="",d.target=null}function b(t){var e=t.target||t;if("resize"===t.type||"load"===t.type)return h("["+m+"]").forEach(b);if(e.hasAttribute&&e.hasAttribute(m)){var o={left:e.scrollLeft,up:e.scrollTop};o.right=e.scrollWidth-e.clientWidth-o.left,o.down=e.scrollHeight-e.clientHeight-o.up;var n=o.left||o.right||o.up||o.down?"grab":"";i(e,"scroll.change",o),t.type||(e.style.cursor="-webkit-"+n,e.style.cursor=n),e.id&&h("["+c+"]").forEach(function(t){t.getAttribute(c)===e.id&&(t.disabled=!o[t.value])})}}function x(t,e){var o=e.x,n=e.y,r=Math.min(.99,t.getAttribute(m))||g,i=d.animate=Math.floor(Date.now()*Math.random()).toString(16),l=Math.max(0,Math.min(o,t.scrollWidth-t.clientWidth)),s=Math.max(0,Math.min(n,t.scrollHeight-t.clientHeight)),c=y?1:l-t.scrollLeft,a=y?1:s-t.scrollTop,u=function(){d.animate===i&&(Math.round(c)||Math.round(a))&&(t.scrollLeft=l-Math.round(c*=r),t.scrollTop=s-Math.round(a*=r),f(u))};u()}p(m,"mousedown",function(t){for(var e=t.target;e;e=e.parentElement)!t.defaultPrevented&&e.hasAttribute&&e.hasAttribute(m)&&(t.preventDefault(),d.pageX=t.pageX,d.pageY=t.pageY,d.diffSumX=0,d.diffSumY=0,d.scrollX=e.scrollLeft,d.scrollY=e.scrollTop,d.animate=d.diffX=d.diffY=0,d.target=e,document.body.style.cursor=e.style.cursor="-webkit-grabbing",document.body.style.cursor=e.style.cursor="grabbing",document.addEventListener("mousemove",u),document.addEventListener("mouseup",w))}),p(m,"wheel",function(){return d.animate=!1},{passive:!0}),p(m,"load",b),p(m,"click",function(t){if(t.defaultPrevented)return;for(var e=t.target;e;e=e.parentElement){var o=document.getElementById(e.getAttribute(c));if(o&&i(o,"scroll.click",{move:e.value}))return a(o,e.value)}});var E=function(o){function i(t){var e=this;o.call(this,t),this.onScroll=this.onScroll.bind(this),this.scrollTo=function(t){return a(e.el,t)},this.scrollUp=function(){return a(e.el,"up")},this.scrollDown=function(){return a(e.el,"down")},this.scrollLeft=function(){return a(e.el,"left")},this.scrollRight=function(){return a(e.el,"right")}}o&&(i.__proto__=o),(i.prototype=Object.create(o&&o.prototype)).constructor=i;var t={defaultProps:{configurable:!0}};return t.defaultProps.get=function(){return{onChange:null,friction:null}},i.prototype.componentDidMount=function(){var t=this;this.el.addEventListener("scroll.change",this.onScroll),f(function(){return a(t.el,{friction:t.props.friction},t.props.settings)})},i.prototype.componentDidUpdate=function(t,e){this.skipUpdate?this.skipUpdate=!1:a(this.el)},i.prototype.componentWillUnmount=function(){this.el.removeEventListener("scroll.change",this.onScroll)},i.prototype.onScroll=function(t){var e=t.detail;this.props.onChange&&(this.skipUpdate=!0,this.props.onChange({scrollUp:e.up?this.scrollUp:null,scrollDown:e.down?this.scrollDown:null,scrollLeft:e.left?this.scrollLeft:null,scrollRight:e.right?this.scrollRight:null}))},i.prototype.render=function(){var o,n,t,e=this,r=(o=this.props,n=i.defaultProps,void 0===(t={ref:function(t){return e.el=t}})&&(t={}),Object.keys(o).reduce(function(t,e){return n.hasOwnProperty(e)||(t[e]=o[e]),t},t));return l.createElement("div",r,this.props.children)},Object.defineProperties(i,t),i}(l.Component);return E.propTypes={onChange:t.func,friction:t.number},E}); | ||
/*! @nrk/core-scroll v3.1.0 - Copyright (c) 2017-2018 NRK */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],e):t.CoreScroll=e(t.React,t.PropTypes)}(this,function(l,t){"use strict";l=l&&l.hasOwnProperty("default")?l.default:l,t=t&&t.hasOwnProperty("default")?t.default:t;var e="undefined"!=typeof window,r=(e&&/(android)/i.test(navigator.userAgent),e&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(t){void 0===t&&(t=!1);try{window.addEventListener("test",null,{get passive(){t=!0}})}catch(t){}return t}());function p(t,e,o,n){(void 0===n&&(n=!1),"undefined"==typeof window||window[t=t+"-"+e])||(r||"object"!=typeof n||(n=Boolean(n.capture)),("resize"===e||"load"===e?window:document).addEventListener(window[t]=e,o,n))}var s="prevent_recursive_dispatch_maximum_callstack";function i(t,e,o){void 0===o&&(o={});var n,r=""+s+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 f(t){(window.requestAnimationFrame||window.setTimeout)(t)}function h(t,e){if(void 0===e&&(e=document),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 d={},c="data-core-scroll",m="data-@nrk/core-scroll-3.1.0".replace(/\W+/g,"-"),v={up:{y:-1,prop:"top"},down:{y:1,prop:"bottom"},left:{x:-1},right:{x:1}},o=10,g=.8,n=20,a=/INPUT|TEXTAREA|SELECT/,y=e&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion)").matches;function u(t,e,u){void 0===e&&(e=""),void 0===u&&(u={});var f="object"==typeof e?e:{move:e},d="x"in f||"y"in f||f.move;return h(t).map(function(t){var o,n,r,i,l,s,c,a;return t.hasAttribute(m)||(t.setAttribute(m,f.friction||""),p(m,"resize",(l=E,s=u.resizeMs||500,function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var o=this,n=Date.now();c&&n<c+s?(clearTimeout(a),a=setTimeout(function(){c=n,l.apply(o,t)},s)):(c=n,l.apply(o,t))})),p(m,"scroll",(o=E,n=u.scrollMs||500,function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];r=t,i||(i=setTimeout(function(){o.apply(this,r),i=null},n))}),!0),function(t){document.getElementById(m)||document.head.insertAdjacentHTML("beforeend",'<style id="'+m+'">['+m+"]::-webkit-scrollbar{display:none}</style>");t.style.overflow="scroll",t.style.willChange="scroll-position",t.style.webkitOverflowScrolling="touch";var e=t.offsetWidth-t.clientWidth,o=t.offsetHeight-t.clientHeight;t.style.marginRight="-"+e+"px",t.style.marginBottom="-"+o+"px",t.style.maxHeight="calc(100% + "+o+"px)"}(t)),d?x(t,function(t,e){var o=e.x,n=e.y,r=e.move,i={x:o,y:n,move:v[r]};"number"!=typeof i.x&&(i.x=t.scrollLeft);"number"!=typeof i.y&&(i.y=t.scrollTop);if(i.move){var l=i.move.x?"x":"y",s=i.move.x?"left":"top",c=t.getBoundingClientRect(),a=c[s]-t[i.move.x?"scrollLeft":"scrollTop"],u=c[s]+c[i.move.x?"width":"height"]*i.move[l];h(t.children).every(function(t){var e=t.getBoundingClientRect(),o=t.ownerDocument.defaultView.getComputedStyle(t)["margin-"+s];return i[l]=e[s]-parseInt(o,10)-a,e[i.move.prop||r]<u})}return i}(t,f)):E(t),t})}function w(t){d.diffX=d.pageX-(d.pageX=t.pageX),d.diffY=d.pageY-(d.pageY=t.pageY),d.diffSumX+=d.diffX,d.diffSumY+=d.diffY,d.target.scrollLeft=d.scrollX+=d.diffX,d.target.scrollTop=d.scrollY+=d.diffY,(Math.abs(d.diffSumX)>o||Math.abs(d.diffSumY)>o)&&(d.target.style.pointerEvents="none")}function b(t){var e=d.diffX||d.diffY;document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",b),document.body.style.cursor="",E(d.target),e&&x(d.target,{x:d.scrollX+d.diffX*n,y:d.scrollY+d.diffY*n}),d.target.style.pointerEvents="",d.target=null}function E(t){var e=t.target||t;if("resize"===t.type||"load"===t.type)return h("["+m+"]").forEach(E);if(e.hasAttribute&&e.hasAttribute(m)){var o={left:e.scrollLeft,up:e.scrollTop};o.right=e.scrollWidth-e.clientWidth-o.left,o.down=e.scrollHeight-e.clientHeight-o.up;var n=o.left||o.right||o.up||o.down?"grab":"";i(e,"scroll.change",o),t.type||(e.style.cursor="-webkit-"+n,e.style.cursor=n),e.id&&h("["+c+"]").forEach(function(t){t.getAttribute(c)===e.id&&(t.disabled=!o[t.value])})}}function x(t,e){var o=e.x,n=e.y,r=Math.min(.99,t.getAttribute(m))||g,i=d.animate=Math.floor(Date.now()*Math.random()).toString(16),l=Math.max(0,Math.min(o,t.scrollWidth-t.clientWidth)),s=Math.max(0,Math.min(n,t.scrollHeight-t.clientHeight)),c=y?1:l-t.scrollLeft,a=y?1:s-t.scrollTop,u=function(){d.animate===i&&(Math.round(c)||Math.round(a))&&(t.scrollLeft=l-Math.round(c*=r),t.scrollTop=s-Math.round(a*=r),f(u))};u()}p(m,"mousedown",function(t){for(var e=t.target;e;e=e.parentElement){if("true"===e.contentEditable||a.test(e.nodeName))return;!t.defaultPrevented&&e.hasAttribute&&e.hasAttribute(m)&&(t.preventDefault(),d.pageX=t.pageX,d.pageY=t.pageY,d.diffSumX=0,d.diffSumY=0,d.scrollX=e.scrollLeft,d.scrollY=e.scrollTop,d.animate=d.diffX=d.diffY=0,d.target=e,document.body.style.cursor=e.style.cursor="-webkit-grabbing",document.body.style.cursor=e.style.cursor="grabbing",document.addEventListener("mousemove",w),document.addEventListener("mouseup",b))}}),p(m,"wheel",function(){return d.animate=!1},{passive:!0}),p(m,"load",E),p(m,"click",function(t){if(t.defaultPrevented)return;for(var e=t.target;e;e=e.parentElement){var o=document.getElementById(e.getAttribute(c));if(o&&i(o,"scroll.click",{move:e.value}))return u(o,e.value)}});var L=function(o){function i(t){var e=this;o.call(this,t),this.onScroll=this.onScroll.bind(this),this.scrollTo=function(t){return u(e.el,t)},this.scrollUp=function(){return u(e.el,"up")},this.scrollDown=function(){return u(e.el,"down")},this.scrollLeft=function(){return u(e.el,"left")},this.scrollRight=function(){return u(e.el,"right")}}o&&(i.__proto__=o),(i.prototype=Object.create(o&&o.prototype)).constructor=i;var t={defaultProps:{configurable:!0}};return t.defaultProps.get=function(){return{onChange:null,friction:null}},i.prototype.componentDidMount=function(){var t=this;this.el.addEventListener("scroll.change",this.onScroll),f(function(){return u(t.el,{friction:t.props.friction},t.props.settings)})},i.prototype.componentDidUpdate=function(t,e){this.skipUpdate?this.skipUpdate=!1:u(this.el)},i.prototype.componentWillUnmount=function(){this.el.removeEventListener("scroll.change",this.onScroll)},i.prototype.onScroll=function(t){var e=t.detail;this.props.onChange&&(this.skipUpdate=!0,this.props.onChange({scrollUp:e.up?this.scrollUp:null,scrollDown:e.down?this.scrollDown:null,scrollLeft:e.left?this.scrollLeft:null,scrollRight:e.right?this.scrollRight:null}))},i.prototype.render=function(){var o,n,t,e=this,r=(o=this.props,n=i.defaultProps,void 0===(t={ref:function(t){return e.el=t}})&&(t={}),Object.keys(o).reduce(function(t,e){return n.hasOwnProperty(e)||(t[e]=o[e]),t},t));return l.createElement("div",r,this.props.children)},Object.defineProperties(i,t),i}(l.Component);return L.propTypes={onChange:t.func,friction:t.number},L}); | ||
//# sourceMappingURL=core-scroll.jsx.js.map |
@@ -1,3 +0,3 @@ | ||
/*! @nrk/core-scroll v3.0.2 - Copyright (c) 2017-2018 NRK */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.coreScroll=t()}(this,function(){"use strict";var e="undefined"!=typeof window,r=(e&&/(android)/i.test(navigator.userAgent),e&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(e){void 0===e&&(e=!1);try{window.addEventListener("test",null,{get passive(){e=!0}})}catch(e){}return e}());function m(e,t,o,n){(void 0===n&&(n=!1),"undefined"==typeof window||window[e=e+"-"+t])||(r||"object"!=typeof n||(n=Boolean(n.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,o,n))}var l="prevent_recursive_dispatch_maximum_callstack";function i(e,t,o){void 0===o&&(o={});var n,r=""+l+t;if(e[r])return!0;e[r]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(t,{bubbles:!0,cancelable:!0,detail:o}):(n=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!0,o);var i=e.dispatchEvent(n);return e[r]=null,i}function p(e,t){if(void 0===t&&(t=document),e){if(e.nodeType)return[e];if("string"==typeof e)return[].slice.call(t.querySelectorAll(e));if(e.length)return[].slice.call(e)}return[]}var s={},a="data-core-scroll",v="data-@nrk/core-scroll-3.0.2".replace(/\W+/g,"-"),g={up:{y:-1,prop:"top"},down:{y:1,prop:"bottom"},left:{x:-1},right:{x:1}},t=10,f=.8,o=20,h=e&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion)").matches;function n(e,t,d){void 0===t&&(t=""),void 0===d&&(d={});var s="object"==typeof t?t:{move:t},f="x"in s||"y"in s||s.move;return p(e).map(function(e){var o,n,r,i,l,a,c,u;return e.hasAttribute(v)||(e.setAttribute(v,s.friction||""),m(v,"resize",(l=y,a=d.resizeMs||500,function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var o=this,n=Date.now();c&&n<c+a?(clearTimeout(u),u=setTimeout(function(){c=n,l.apply(o,e)},a)):(c=n,l.apply(o,e))})),m(v,"scroll",(o=y,n=d.scrollMs||500,function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r=e,i||(i=setTimeout(function(){o.apply(this,r),i=null},n))}),!0),function(e){document.getElementById(v)||document.head.insertAdjacentHTML("beforeend",'<style id="'+v+'">['+v+"]::-webkit-scrollbar{display:none}</style>");e.style.overflow="scroll",e.style.willChange="scroll-position",e.style.webkitOverflowScrolling="touch";var t=e.offsetWidth-e.clientWidth,o=e.offsetHeight-e.clientHeight;e.style.marginRight="-"+t+"px",e.style.marginBottom="-"+o+"px",e.style.maxHeight="calc(100% + "+o+"px)"}(e)),f?w(e,function(e,t){var o=t.x,n=t.y,r=t.move,i={x:o,y:n,move:g[r]};"number"!=typeof i.x&&(i.x=e.scrollLeft);"number"!=typeof i.y&&(i.y=e.scrollTop);if(i.move){var l=i.move.x?"x":"y",a=i.move.x?"left":"top",c=e.getBoundingClientRect(),u=c[a]-e[i.move.x?"scrollLeft":"scrollTop"],d=c[a]+c[i.move.x?"width":"height"]*i.move[l];p(e.children).every(function(e){var t=e.getBoundingClientRect(),o=e.ownerDocument.defaultView.getComputedStyle(e)["margin-"+a];return i[l]=t[a]-parseInt(o,10)-u,t[i.move.prop||r]<d})}return i}(e,s)):y(e),e})}function c(e){s.diffX=s.pageX-(s.pageX=e.pageX),s.diffY=s.pageY-(s.pageY=e.pageY),s.diffSumX+=s.diffX,s.diffSumY+=s.diffY,s.target.scrollLeft=s.scrollX+=s.diffX,s.target.scrollTop=s.scrollY+=s.diffY,(Math.abs(s.diffSumX)>t||Math.abs(s.diffSumY)>t)&&(s.target.style.pointerEvents="none")}function u(e){var t=s.diffX||s.diffY;document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",u),document.body.style.cursor="",y(s.target),t&&w(s.target,{x:s.scrollX+s.diffX*o,y:s.scrollY+s.diffY*o}),s.target.style.pointerEvents="",s.target=null}function y(e){var t=e.target||e;if("resize"===e.type||"load"===e.type)return p("["+v+"]").forEach(y);if(t.hasAttribute&&t.hasAttribute(v)){var o={left:t.scrollLeft,up:t.scrollTop};o.right=t.scrollWidth-t.clientWidth-o.left,o.down=t.scrollHeight-t.clientHeight-o.up;var n=o.left||o.right||o.up||o.down?"grab":"";i(t,"scroll.change",o),e.type||(t.style.cursor="-webkit-"+n,t.style.cursor=n),t.id&&p("["+a+"]").forEach(function(e){e.getAttribute(a)===t.id&&(e.disabled=!o[e.value])})}}function w(t,e){var o=e.x,n=e.y,r=Math.min(.99,t.getAttribute(v))||f,i=s.animate=Math.floor(Date.now()*Math.random()).toString(16),l=Math.max(0,Math.min(o,t.scrollWidth-t.clientWidth)),a=Math.max(0,Math.min(n,t.scrollHeight-t.clientHeight)),c=h?1:l-t.scrollLeft,u=h?1:a-t.scrollTop,d=function(){var e;s.animate===i&&(Math.round(c)||Math.round(u))&&(t.scrollLeft=l-Math.round(c*=r),t.scrollTop=a-Math.round(u*=r),e=d,(window.requestAnimationFrame||window.setTimeout)(e))};d()}return m(v,"mousedown",function(e){for(var t=e.target;t;t=t.parentElement)!e.defaultPrevented&&t.hasAttribute&&t.hasAttribute(v)&&(e.preventDefault(),s.pageX=e.pageX,s.pageY=e.pageY,s.diffSumX=0,s.diffSumY=0,s.scrollX=t.scrollLeft,s.scrollY=t.scrollTop,s.animate=s.diffX=s.diffY=0,s.target=t,document.body.style.cursor=t.style.cursor="-webkit-grabbing",document.body.style.cursor=t.style.cursor="grabbing",document.addEventListener("mousemove",c),document.addEventListener("mouseup",u))}),m(v,"wheel",function(){return s.animate=!1},{passive:!0}),m(v,"load",y),m(v,"click",function(e){if(e.defaultPrevented)return;for(var t=e.target;t;t=t.parentElement){var o=document.getElementById(t.getAttribute(a));if(o&&i(o,"scroll.click",{move:t.value}))return n(o,t.value)}}),n}); | ||
/*! @nrk/core-scroll v3.1.0 - Copyright (c) 2017-2018 NRK */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.coreScroll=t()}(this,function(){"use strict";var e="undefined"!=typeof window,r=(e&&/(android)/i.test(navigator.userAgent),e&&/iPad|iPhone|iPod/.test(String(navigator.platform)),function(e){void 0===e&&(e=!1);try{window.addEventListener("test",null,{get passive(){e=!0}})}catch(e){}return e}());function m(e,t,o,n){(void 0===n&&(n=!1),"undefined"==typeof window||window[e=e+"-"+t])||(r||"object"!=typeof n||(n=Boolean(n.capture)),("resize"===t||"load"===t?window:document).addEventListener(window[e]=t,o,n))}var l="prevent_recursive_dispatch_maximum_callstack";function i(e,t,o){void 0===o&&(o={});var n,r=""+l+t;if(e[r])return!0;e[r]=!0,"function"==typeof window.CustomEvent?n=new window.CustomEvent(t,{bubbles:!0,cancelable:!0,detail:o}):(n=document.createEvent("CustomEvent")).initCustomEvent(t,!0,!0,o);var i=e.dispatchEvent(n);return e[r]=null,i}function p(e,t){if(void 0===t&&(t=document),e){if(e.nodeType)return[e];if("string"==typeof e)return[].slice.call(t.querySelectorAll(e));if(e.length)return[].slice.call(e)}return[]}var s={},a="data-core-scroll",v="data-@nrk/core-scroll-3.1.0".replace(/\W+/g,"-"),g={up:{y:-1,prop:"top"},down:{y:1,prop:"bottom"},left:{x:-1},right:{x:1}},t=10,f=.8,o=20,n=/INPUT|TEXTAREA|SELECT/,h=e&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion)").matches;function u(e,t,d){void 0===t&&(t=""),void 0===d&&(d={});var s="object"==typeof t?t:{move:t},f="x"in s||"y"in s||s.move;return p(e).map(function(e){var o,n,r,i,l,a,u,c;return e.hasAttribute(v)||(e.setAttribute(v,s.friction||""),m(v,"resize",(l=y,a=d.resizeMs||500,function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var o=this,n=Date.now();u&&n<u+a?(clearTimeout(c),c=setTimeout(function(){u=n,l.apply(o,e)},a)):(u=n,l.apply(o,e))})),m(v,"scroll",(o=y,n=d.scrollMs||500,function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r=e,i||(i=setTimeout(function(){o.apply(this,r),i=null},n))}),!0),function(e){document.getElementById(v)||document.head.insertAdjacentHTML("beforeend",'<style id="'+v+'">['+v+"]::-webkit-scrollbar{display:none}</style>");e.style.overflow="scroll",e.style.willChange="scroll-position",e.style.webkitOverflowScrolling="touch";var t=e.offsetWidth-e.clientWidth,o=e.offsetHeight-e.clientHeight;e.style.marginRight="-"+t+"px",e.style.marginBottom="-"+o+"px",e.style.maxHeight="calc(100% + "+o+"px)"}(e)),f?w(e,function(e,t){var o=t.x,n=t.y,r=t.move,i={x:o,y:n,move:g[r]};"number"!=typeof i.x&&(i.x=e.scrollLeft);"number"!=typeof i.y&&(i.y=e.scrollTop);if(i.move){var l=i.move.x?"x":"y",a=i.move.x?"left":"top",u=e.getBoundingClientRect(),c=u[a]-e[i.move.x?"scrollLeft":"scrollTop"],d=u[a]+u[i.move.x?"width":"height"]*i.move[l];p(e.children).every(function(e){var t=e.getBoundingClientRect(),o=e.ownerDocument.defaultView.getComputedStyle(e)["margin-"+a];return i[l]=t[a]-parseInt(o,10)-c,t[i.move.prop||r]<d})}return i}(e,s)):y(e),e})}function c(e){s.diffX=s.pageX-(s.pageX=e.pageX),s.diffY=s.pageY-(s.pageY=e.pageY),s.diffSumX+=s.diffX,s.diffSumY+=s.diffY,s.target.scrollLeft=s.scrollX+=s.diffX,s.target.scrollTop=s.scrollY+=s.diffY,(Math.abs(s.diffSumX)>t||Math.abs(s.diffSumY)>t)&&(s.target.style.pointerEvents="none")}function d(e){var t=s.diffX||s.diffY;document.removeEventListener("mousemove",c),document.removeEventListener("mouseup",d),document.body.style.cursor="",y(s.target),t&&w(s.target,{x:s.scrollX+s.diffX*o,y:s.scrollY+s.diffY*o}),s.target.style.pointerEvents="",s.target=null}function y(e){var t=e.target||e;if("resize"===e.type||"load"===e.type)return p("["+v+"]").forEach(y);if(t.hasAttribute&&t.hasAttribute(v)){var o={left:t.scrollLeft,up:t.scrollTop};o.right=t.scrollWidth-t.clientWidth-o.left,o.down=t.scrollHeight-t.clientHeight-o.up;var n=o.left||o.right||o.up||o.down?"grab":"";i(t,"scroll.change",o),e.type||(t.style.cursor="-webkit-"+n,t.style.cursor=n),t.id&&p("["+a+"]").forEach(function(e){e.getAttribute(a)===t.id&&(e.disabled=!o[e.value])})}}function w(t,e){var o=e.x,n=e.y,r=Math.min(.99,t.getAttribute(v))||f,i=s.animate=Math.floor(Date.now()*Math.random()).toString(16),l=Math.max(0,Math.min(o,t.scrollWidth-t.clientWidth)),a=Math.max(0,Math.min(n,t.scrollHeight-t.clientHeight)),u=h?1:l-t.scrollLeft,c=h?1:a-t.scrollTop,d=function(){var e;s.animate===i&&(Math.round(u)||Math.round(c))&&(t.scrollLeft=l-Math.round(u*=r),t.scrollTop=a-Math.round(c*=r),e=d,(window.requestAnimationFrame||window.setTimeout)(e))};d()}return m(v,"mousedown",function(e){for(var t=e.target;t;t=t.parentElement){if("true"===t.contentEditable||n.test(t.nodeName))return;!e.defaultPrevented&&t.hasAttribute&&t.hasAttribute(v)&&(e.preventDefault(),s.pageX=e.pageX,s.pageY=e.pageY,s.diffSumX=0,s.diffSumY=0,s.scrollX=t.scrollLeft,s.scrollY=t.scrollTop,s.animate=s.diffX=s.diffY=0,s.target=t,document.body.style.cursor=t.style.cursor="-webkit-grabbing",document.body.style.cursor=t.style.cursor="grabbing",document.addEventListener("mousemove",c),document.addEventListener("mouseup",d))}}),m(v,"wheel",function(){return s.animate=!1},{passive:!0}),m(v,"load",y),m(v,"click",function(e){if(e.defaultPrevented)return;for(var t=e.target;t;t=t.parentElement){var o=document.getElementById(t.getAttribute(a));if(o&&i(o,"scroll.click",{move:t.value}))return u(o,t.value)}}),u}); | ||
//# sourceMappingURL=core-scroll.min.js.map |
@@ -9,3 +9,3 @@ 'use strict'; | ||
var name = "@nrk/core-scroll"; | ||
var version = "3.0.2"; | ||
var version = "3.1.0"; | ||
@@ -161,2 +161,3 @@ var IS_BROWSER = typeof window !== 'undefined'; | ||
var VELOCITY = 20; | ||
var NEEDS_MOUSEDOWN = /INPUT|TEXTAREA|SELECT/; | ||
@@ -193,2 +194,3 @@ // https://css-tricks.com/introduction-reduced-motion-media-query/ | ||
for (var el = event.target; el; el = el.parentElement) { | ||
if (el.contentEditable === 'true' || NEEDS_MOUSEDOWN.test(el.nodeName)) { return } // No dragging when user clicks input fields | ||
if (!event.defaultPrevented && el.hasAttribute && el.hasAttribute(UUID)) { | ||
@@ -195,0 +197,0 @@ event.preventDefault(); // Prevent text selection and enable nesting |
@@ -5,3 +5,3 @@ { | ||
"author": "NRK <opensource@nrk.no> (https://www.nrk.no/)", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "core-scroll.cjs.js", |
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
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
106803
954
0