Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scrollfeatures

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scrollfeatures - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

74

dist/scrollfeatures.js

@@ -37,6 +37,6 @@ 'use strict';

value: function getInstance(scrollTarget, options) {
if (!scrollTarget.scrollEvents) {
if (!scrollTarget.scrollFeatures) {
return new ScrollFeatures(scrollTarget, options);
}
return scrollTarget.scrollEvents;
return scrollTarget.scrollFeatures;
}

@@ -46,3 +46,3 @@ }, {

value: function hasInstance(scrollTarget) {
return typeof scrollTarget.scrollEvents !== 'undefined';
return typeof scrollTarget.scrollFeatures !== 'undefined';
}

@@ -106,3 +106,3 @@ }, {

if (ScrollFeatures.hasScrollTarget(scrollTarget)) {
if (ScrollFeatures.hasInstance(scrollTarget)) {
var _ret;

@@ -115,3 +115,3 @@

scrollTarget.scrollEvents = _this;
scrollTarget.scrollFeatures = _this;
_this._scrollTarget = scrollTarget;

@@ -125,3 +125,2 @@ _this.options = options;

_this.init();
return _this;

@@ -133,2 +132,3 @@ }

value: function init() {
var _this2 = this;

@@ -152,6 +152,8 @@ this._destroyed = false;

this.getScrollPosition = this._scrollTarget === window ? (0, _delegatejs2.default)(this, this._getWindowScrollPosition) : (0, _delegatejs2.default)(this, this._getElementScrollPosition);
this.getScrollPosition = (0, _delegatejs2.default)(this, this._scrollTarget === window ? this._getWindowScrollPosition : this._getElementScrollPosition);
this.onResize = (0, _delegatejs2.default)(this, function () {
return _this2.trigger(ScrollFeatures.EVENT_SCROLL_RESIZE);
});
this.onScroll = (0, _delegatejs2.default)(this, this.onScroll);
this.onResize = (0, _delegatejs2.default)(this, this.onResize);
this.onNextFrame = (0, _delegatejs2.default)(this, this.onNextFrame);

@@ -163,2 +165,3 @@

this._canScrollX = this.clientWidth < this.scrollWidth;
if (this._scrollTarget !== window) {

@@ -171,7 +174,5 @@ var style = window.getComputedStyle(this._scrollTarget);

if (this._scrollTarget.addEventListener) {
// this._scrollTarget.addEventListener('mousewheel', this.onScroll, Can.passiveEvents ? { passive: true } : false);
this._scrollTarget.addEventListener('scroll', this.onScroll, false);
this._scrollTarget.addEventListener('resize', this.onResize, false);
} else if (this._scrollTarget.attachEvent) {
// this._scrollTarget.attachEvent('onmousewheel', this.onScroll);
this._scrollTarget.attachEvent('scroll', this.onScroll);

@@ -182,12 +183,2 @@ this._scrollTarget.attachEvent('resize', this.onResize);

}, {
key: 'update',
value: function update() {
var scrollY = this._scrollY;
var scrollX = this._scrollX;
this.updateScrollPosition();
if (scrollY !== this.y || scrollX !== this.x) {
this.trigger(ScrollFeatures.EVENT_SCROLL_PROGRESS);
}
}
}, {
key: 'destroy',

@@ -201,7 +192,5 @@ value: function destroy() {

if (this._scrollTarget.addEventListener) {
// this._scrollTarget.removeEventListener('mousewheel', this.onScroll);
this._scrollTarget.removeEventListener('scroll', this.onScroll);
this._scrollTarget.removeEventListener('resize', this.onResize);
} else if (this._scrollTarget.attachEvent) {
// this._scrollTarget.detachEvent('onmousewheel', this.onScroll);
this._scrollTarget.detachEvent('scroll', this.onScroll);

@@ -222,3 +211,2 @@ this._scrollTarget.detachEvent('resize', this.onResize);

value: function updateScrollPosition() {
this._scrollY = this.scrollY;

@@ -244,7 +232,2 @@ this._scrollX = this.scrollX;

}, {
key: 'onResize',
value: function onResize() {
this.trigger(ScrollFeatures.EVENT_SCROLL_RESIZE);
}
}, {
key: 'onScroll',

@@ -277,3 +260,3 @@ value: function onScroll() {

value: function onNextFrame() {
var _this2 = this;
var _this3 = this;

@@ -308,3 +291,3 @@ // this._lastSpeed = this.speedY;

this._nextTimeout = setTimeout(function () {
_this2.onNextFrame();
_this3.onNextFrame();
}, 1000 / 60);

@@ -390,14 +373,2 @@ }

}, {
key: 'attributes',
get: function get() {
return {
y: this.y,
x: this.x,
speedY: this.speedY,
speedX: this.speedX,
directionY: this.directionY,
directionX: this.directionX
};
}
}, {
key: 'scrollTarget',

@@ -428,2 +399,12 @@ get: function get() {

}, {
key: 'canScrollY',
get: function get() {
return this._canScrollY;
}
}, {
key: 'canScrollX',
get: function get() {
return this._canScrollX;
}
}, {
key: 'scrollY',

@@ -473,3 +454,2 @@ get: function get() {

ScrollFeatures.hasScrollTarget = ScrollFeatures.hasInstance;
ScrollFeatures.UP = -1;

@@ -490,2 +470,5 @@ ScrollFeatures.DOWN = 1;

var _animationFrame = null;
var Can = function () {

@@ -499,3 +482,6 @@ function Can() {

get: function get() {
return !!(window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame);
if (_animationFrame === null) {
_animationFrame = !!(window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame);
}
return _animationFrame;
}

@@ -502,0 +488,0 @@ }]);

@@ -1,1 +0,1 @@

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.ScrollFeatures=t()}}(function(){return function t(e,i,n){function r(s,l){if(!i[s]){if(!e[s]){var c="function"==typeof require&&require;if(!l&&c)return c(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var h=i[s]={exports:{}};e[s][0].call(h.exports,function(t){var i=e[s][1][t];return r(i?i:t)},h,h.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)r(n[s]);return r}({1:[function(t,e){var i=function(t,e){var i=arguments.length<=2?[]:[].slice.call(arguments,2);return function(){return e.apply(t,arguments.length?i.slice().concat([].slice.call(arguments)):i)}};e.exports=i},{}],2:[function(t,e,i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=e.target,r=e.currentTarget;n(this,t),this._eventMap={},this._destroyed=!1,this._target=i||this,this._currentTarget=r||this,this.on=this.bind=this.addEventListener=this.addListener,this.off=this.unbind=this.removeEventListener=this.removeListener,this.once=this.one=this.addListenerOnce,this.emit=this.trigger=this.dispatchEvent=this.dispatch}return t.prototype.addListener=function(t,e){var i=this.getListener(t);return i?-1===i.indexOf(e)&&i.push(e):this._eventMap[t]=[e],this},t.prototype.addListenerOnce=function(t,e){var i=this,n=function(r){e(r),i.off(t,n),e=null,n=null};return this.on(t,n)},t.prototype.removeListener=function(t,e){if(!e)return this.removeAllListener(t);var i=this.getListener(t);if(i){var n=i.indexOf(e);n>-1&&(i=i.splice(n,1),i.length||delete this._eventMap[t])}return this},t.prototype.removeAllListener=function(t){var e=this.getListener(t);return e&&(this._eventMap[t].length=0,delete this._eventMap[t]),this},t.prototype.hasListener=function(t){return null!==this.getListener(t)},t.prototype.hasListeners=function(){return null!==this._eventMap&&void 0!==this._eventMap&&!r(this._eventMap)},t.prototype.dispatch=function(t,e){var i=this.getListener(t);if(i){e=e||{},e.type=t,e.target=e.target||this._target,e.currentTarget=e.currentTarget||this._currentTarget;for(var n=-1;++n<i.length;)i[n](e)}return this},t.prototype.getListener=function(t){var e=this._eventMap?this._eventMap[t]:null;return e||null},t.prototype.destroy=function(){if(this._eventMap){for(var t in this._eventMap)this.removeAllListener(t);this._eventMap=null}return this._destroyed=!0,this},t}();i["default"]=o,e.exports=i["default"]},{}],3:[function(t,e){"use strict";var i=/(auto|scroll)/,n=function(t){if(!(t instanceof HTMLElement))return window;for(;t.parentNode;){if(t.parentNode===document.body)return window;var e=window.getComputedStyle(t.parentNode,null);if(i.test(e.getPropertyValue("overflow")+e.getPropertyValue("overflow-y")+e.getPropertyValue("overflow-x")))return t.parentNode;t=t.parentNode}return window};e.exports=n},{}],4:[function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(i,"__esModule",{value:!0});var l=function m(t,e,i){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var r=Object.getPrototypeOf(t);return null===r?void 0:m(r,e,i)}if("value"in n)return n.value;var o=n.get;return void 0===o?void 0:o.call(i)},c=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),a=t("delegatejs"),h=n(a),u=t("eventdispatcher"),d=n(u),f=t("./scroll-parent"),g=n(f),_=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?window:arguments[0],i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(r(this,e),e.hasScrollTarget(t)){var n;return n=e.getInstance(t),o(s,n)}var s=o(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,{target:t}));return t.scrollEvents=s,s._scrollTarget=t,s.options=i,p.animationFrame&&e.unprefixAnimationFrame(),s.init(),s}return s(e,t),c(e,null,[{key:"getInstance",value:function(t,i){return t.scrollEvents?t.scrollEvents:new e(t,i)}},{key:"hasInstance",value:function(t){return"undefined"!=typeof t.scrollEvents}},{key:"getScrollParent",value:function(t){return g["default"](t)}},{key:"unprefixAnimationFrame",value:function(){window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,window.cancelAnimationFrame=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame)}},{key:"directionToString",value:function(t){switch(t){case e.UP:return"up";case e.DOWN:return"down";case e.NONE:return"none";case e.LEFT:return"left";case e.RIGHT:return"right"}}},{key:"windowScrollY",get:function(){return window.pageYOffset||window.scrollY||0}},{key:"windowScrollX",get:function(){return window.pageXOffset||window.scrollX||0}},{key:"documentHeight",get:function(){return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)}},{key:"documentWidth",get:function(){return Math.max(document.body.scrollWidth,document.body.offsetWidth,document.documentElement.clientWidth,document.documentElement.scrollWidth,document.documentElement.offsetWidth)}}]),c(e,[{key:"init",value:function(){if(this._destroyed=!1,this._scrollY=0,this._scrollX=0,this._speedY=0,this._speedX=0,this._lastSpeed=0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this._stopFrames=3,this._currentStopFrames=0,this._firstRender=!0,this._directionY=e.NONE,this._directionX=e.NONE,this._scrolling=!1,this._canScrollY=!1,this._canScrollX=!1,this.getScrollPosition=this._scrollTarget===window?h["default"](this,this._getWindowScrollPosition):h["default"](this,this._getElementScrollPosition),this.onScroll=h["default"](this,this.onScroll),this.onResize=h["default"](this,this.onResize),this.onNextFrame=h["default"](this,this.onNextFrame),this.updateScrollPosition(),this._canScrollY=this.clientHeight<this.scrollHeight,this._canScrollX=this.clientWidth<this.scrollWidth,this._scrollTarget!==window){var t=window.getComputedStyle(this._scrollTarget);this._canScrollY="hidden"!==t["overflow-y"],this._canScrollX="hidden"!==t["overflow-x"]}this._scrollTarget.addEventListener?(this._scrollTarget.addEventListener("scroll",this.onScroll,!1),this._scrollTarget.addEventListener("resize",this.onResize,!1)):this._scrollTarget.attachEvent&&(this._scrollTarget.attachEvent("scroll",this.onScroll),this._scrollTarget.attachEvent("resize",this.onResize))}},{key:"update",value:function(){var t=this._scrollY,i=this._scrollX;this.updateScrollPosition(),(t!==this.y||i!==this.x)&&this.trigger(e.EVENT_SCROLL_PROGRESS)}},{key:"destroy",value:function(){this._destroyed||(this._cancelNextFrame(),l(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this._scrollTarget.addEventListener?(this._scrollTarget.removeEventListener("scroll",this.onScroll),this._scrollTarget.removeEventListener("resize",this.onResize)):this._scrollTarget.attachEvent&&(this._scrollTarget.detachEvent("scroll",this.onScroll),this._scrollTarget.detachEvent("resize",this.onResize)),this.onResize=null,this.onScroll=null,this.getScrollPosition=null,this.onNextFrame=null,this._scrollTarget=null,this._destroyed=!0)}},{key:"updateScrollPosition",value:function(){this._scrollY=this.scrollY,this._scrollX=this.scrollX}},{key:"_getWindowScrollPosition",value:function(){return{y:e.windowScrollY,x:e.windowScrollX}}},{key:"_getElementScrollPosition",value:function(){return{y:this._scrollTarget.scrollTop,x:this._scrollTarget.scrollLeft}}},{key:"onResize",value:function(){this.trigger(e.EVENT_SCROLL_RESIZE)}},{key:"onScroll",value:function(){return this._currentStopFrames=0,this._firstRender&&(this._firstRender=!1,this.y>1||this.x>1)?(this.updateScrollPosition(),void this.trigger(e.EVENT_SCROLL_PROGRESS)):void(this._scrolling||(this._scrolling=!0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this.trigger(e.EVENT_SCROLL_START),p.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this.onNextFrame()))}},{key:"onNextFrame",value:function(){var t=this;this._speedY=this._scrollY-this.scrollY,this._speedX=this._scrollX-this.scrollX;var i=+this.speedY+ +this.speedX;return this._scrolling&&0===i&&this._currentStopFrames++>this._stopFrames?void this.onScrollStop():(this.updateScrollPosition(),this._lastDirectionY!==this.directionY&&this.trigger("scroll:"+e.directionToString(this.directionY)),this._lastDirectionX!==this.directionX&&this.trigger("scroll:"+e.directionToString(this.directionX)),this._lastDirectionY=this.directionY,this._lastDirectionX=this.directionX,this.trigger(e.EVENT_SCROLL_PROGRESS),void(p.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this._nextTimeout=setTimeout(function(){t.onNextFrame()},1e3/60)))}},{key:"onScrollStop",value:function(){this._scrolling=!1,this.updateScrollPosition(),this.trigger(e.EVENT_SCROLL_STOP),this._canScrollY&&(this.y<=0?this.trigger(e.EVENT_SCROLL_MIN):this.y+this.clientHeight>=this.scrollHeight&&this.trigger(e.EVENT_SCROLL_MAX)),this._canScrollX&&(this.x<=0?this.trigger(e.EVENT_SCROLL_MIN):this.x+this.clientWidth>=this.scrollWidth&&this.trigger(e.EVENT_SCROLL_MAX)),this._currentStopFrames=0,this._cancelNextFrame()}},{key:"_cancelNextFrame",value:function(){p.animationFrame?(window.cancelAnimationFrame(this.nextFrameID),this.nextFrameID=-1):clearTimeout(this._nextTimeout)}},{key:"destroyed",get:function(){return this._destroyed}},{key:"scrollPosition",get:function(){return this.getScrollPosition()}},{key:"directionY",get:function(){return!this._canScrollY||0===this.speedY&&!this._scrolling?this._directionY=e.NONE:this.speedY>0?this._directionY=e.UP:this.speedY<0&&(this._directionY=e.DOWN),this._directionY}},{key:"directionX",get:function(){return!this._canScrollX||0===this.speedX&&!this._scrolling?this._directionX=e.NONE:this.speedX>0?this._directionX=e.LEFT:this.speedX<0&&(this._directionX=e.RIGHT),this._directionX}},{key:"attributes",get:function(){return{y:this.y,x:this.x,speedY:this.speedY,speedX:this.speedX,directionY:this.directionY,directionX:this.directionX}}},{key:"scrollTarget",get:function(){return this._scrollTarget}},{key:"delta",get:function(){return this.directionY}},{key:"scrolling",get:function(){return this._scrolling}},{key:"speedY",get:function(){return this._speedY}},{key:"speedX",get:function(){return this._speedX}},{key:"scrollY",get:function(){return this.scrollPosition.y}},{key:"y",get:function(){return this.scrollY}},{key:"scrollX",get:function(){return this.scrollPosition.x}},{key:"x",get:function(){return this.scrollX}},{key:"clientHeight",get:function(){return this._scrollTarget===window?window.innerHeight:this._scrollTarget.clientHeight}},{key:"clientWidth",get:function(){return this._scrollTarget===window?window.innerWidth:this._scrollTarget.clientWidth}},{key:"scrollHeight",get:function(){return this._scrollTarget===window?e.documentHeight:this._scrollTarget.scrollHeight}},{key:"scrollWidth",get:function(){return this._scrollTarget===window?e.documentWidth:this._scrollTarget.scrollWidth}}]),e}(d["default"]);_.hasScrollTarget=_.hasInstance,_.UP=-1,_.DOWN=1,_.NONE=0,_.RIGHT=2,_.LEFT=-2,_.EVENT_SCROLL_PROGRESS="scroll:progress",_.EVENT_SCROLL_START="scroll:start",_.EVENT_SCROLL_STOP="scroll:stop",_.EVENT_SCROLL_DOWN="scroll:down",_.EVENT_SCROLL_UP="scroll:up",_.EVENT_SCROLL_MIN="scroll:min",_.EVENT_SCROLL_MAX="scroll:max",_.EVENT_SCROLL_RESIZE="scroll:resize",i["default"]=_;var p=function(){function t(){r(this,t)}return c(t,null,[{key:"animationFrame",get:function(){return!!(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)}}]),t}();e.exports=i["default"]},{"./scroll-parent":3,delegatejs:1,eventdispatcher:2}]},{},[4])(4)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.ScrollFeatures=t()}}(function(){return function t(e,i,n){function r(s,l){if(!i[s]){if(!e[s]){var c="function"==typeof require&&require;if(!l&&c)return c(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var u=i[s]={exports:{}};e[s][0].call(u.exports,function(t){var i=e[s][1][t];return r(i?i:t)},u,u.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)r(n[s]);return r}({1:[function(t,e){var i=function(t,e){var i=arguments.length<=2?[]:[].slice.call(arguments,2);return function(){return e.apply(t,arguments.length?i.slice().concat([].slice.call(arguments)):i)}};e.exports=i},{}],2:[function(t,e,i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}Object.defineProperty(i,"__esModule",{value:!0});var o=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=e.target,r=e.currentTarget;n(this,t),this._eventMap={},this._destroyed=!1,this._target=i||this,this._currentTarget=r||this,this.on=this.bind=this.addEventListener=this.addListener,this.off=this.unbind=this.removeEventListener=this.removeListener,this.once=this.one=this.addListenerOnce,this.emit=this.trigger=this.dispatchEvent=this.dispatch}return t.prototype.addListener=function(t,e){var i=this.getListener(t);return i?-1===i.indexOf(e)&&i.push(e):this._eventMap[t]=[e],this},t.prototype.addListenerOnce=function(t,e){var i=this,n=function(r){e(r),i.off(t,n),e=null,n=null};return this.on(t,n)},t.prototype.removeListener=function(t,e){if(!e)return this.removeAllListener(t);var i=this.getListener(t);if(i){var n=i.indexOf(e);n>-1&&(i=i.splice(n,1),i.length||delete this._eventMap[t])}return this},t.prototype.removeAllListener=function(t){var e=this.getListener(t);return e&&(this._eventMap[t].length=0,delete this._eventMap[t]),this},t.prototype.hasListener=function(t){return null!==this.getListener(t)},t.prototype.hasListeners=function(){return null!==this._eventMap&&void 0!==this._eventMap&&!r(this._eventMap)},t.prototype.dispatch=function(t,e){var i=this.getListener(t);if(i){e=e||{},e.type=t,e.target=e.target||this._target,e.currentTarget=e.currentTarget||this._currentTarget;for(var n=-1;++n<i.length;)i[n](e)}return this},t.prototype.getListener=function(t){var e=this._eventMap?this._eventMap[t]:null;return e||null},t.prototype.destroy=function(){if(this._eventMap){for(var t in this._eventMap)this.removeAllListener(t);this._eventMap=null}return this._destroyed=!0,this},t}();i["default"]=o,e.exports=i["default"]},{}],3:[function(t,e){"use strict";var i=/(auto|scroll)/,n=function(t){if(!(t instanceof HTMLElement))return window;for(;t.parentNode;){if(t.parentNode===document.body)return window;var e=window.getComputedStyle(t.parentNode,null);if(i.test(e.getPropertyValue("overflow")+e.getPropertyValue("overflow-y")+e.getPropertyValue("overflow-x")))return t.parentNode;t=t.parentNode}return window};e.exports=n},{}],4:[function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(i,"__esModule",{value:!0});var l=function w(t,e,i){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,e);if(void 0===n){var r=Object.getPrototypeOf(t);return null===r?void 0:w(r,e,i)}if("value"in n)return n.value;var o=n.get;return void 0===o?void 0:o.call(i)},c=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),a=t("delegatejs"),u=n(a),h=t("eventdispatcher"),d=n(h),f=t("./scroll-parent"),g=n(f),_=function(t){function e(){var t=arguments.length<=0||void 0===arguments[0]?window:arguments[0],i=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(r(this,e),e.hasInstance(t)){var n;return n=e.getInstance(t),o(s,n)}var s=o(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,{target:t}));return t.scrollFeatures=s,s._scrollTarget=t,s.options=i,m.animationFrame&&e.unprefixAnimationFrame(),s.init(),s}return s(e,t),c(e,null,[{key:"getInstance",value:function(t,i){return t.scrollFeatures?t.scrollFeatures:new e(t,i)}},{key:"hasInstance",value:function(t){return"undefined"!=typeof t.scrollFeatures}},{key:"getScrollParent",value:function(t){return g["default"](t)}},{key:"unprefixAnimationFrame",value:function(){window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,window.cancelAnimationFrame=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame)}},{key:"directionToString",value:function(t){switch(t){case e.UP:return"up";case e.DOWN:return"down";case e.NONE:return"none";case e.LEFT:return"left";case e.RIGHT:return"right"}}},{key:"windowScrollY",get:function(){return window.pageYOffset||window.scrollY||0}},{key:"windowScrollX",get:function(){return window.pageXOffset||window.scrollX||0}},{key:"documentHeight",get:function(){return Math.max(document.body.scrollHeight,document.body.offsetHeight,document.documentElement.clientHeight,document.documentElement.scrollHeight,document.documentElement.offsetHeight)}},{key:"documentWidth",get:function(){return Math.max(document.body.scrollWidth,document.body.offsetWidth,document.documentElement.clientWidth,document.documentElement.scrollWidth,document.documentElement.offsetWidth)}}]),c(e,[{key:"init",value:function(){var t=this;if(this._destroyed=!1,this._scrollY=0,this._scrollX=0,this._speedY=0,this._speedX=0,this._lastSpeed=0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this._stopFrames=3,this._currentStopFrames=0,this._firstRender=!0,this._directionY=e.NONE,this._directionX=e.NONE,this._scrolling=!1,this._canScrollY=!1,this._canScrollX=!1,this.getScrollPosition=u["default"](this,this._scrollTarget===window?this._getWindowScrollPosition:this._getElementScrollPosition),this.onResize=u["default"](this,function(){return t.trigger(e.EVENT_SCROLL_RESIZE)}),this.onScroll=u["default"](this,this.onScroll),this.onNextFrame=u["default"](this,this.onNextFrame),this.updateScrollPosition(),this._canScrollY=this.clientHeight<this.scrollHeight,this._canScrollX=this.clientWidth<this.scrollWidth,this._scrollTarget!==window){var i=window.getComputedStyle(this._scrollTarget);this._canScrollY="hidden"!==i["overflow-y"],this._canScrollX="hidden"!==i["overflow-x"]}this._scrollTarget.addEventListener?(this._scrollTarget.addEventListener("scroll",this.onScroll,!1),this._scrollTarget.addEventListener("resize",this.onResize,!1)):this._scrollTarget.attachEvent&&(this._scrollTarget.attachEvent("scroll",this.onScroll),this._scrollTarget.attachEvent("resize",this.onResize))}},{key:"destroy",value:function(){this._destroyed||(this._cancelNextFrame(),l(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"destroy",this).call(this),this._scrollTarget.addEventListener?(this._scrollTarget.removeEventListener("scroll",this.onScroll),this._scrollTarget.removeEventListener("resize",this.onResize)):this._scrollTarget.attachEvent&&(this._scrollTarget.detachEvent("scroll",this.onScroll),this._scrollTarget.detachEvent("resize",this.onResize)),this.onResize=null,this.onScroll=null,this.getScrollPosition=null,this.onNextFrame=null,this._scrollTarget=null,this._destroyed=!0)}},{key:"updateScrollPosition",value:function(){this._scrollY=this.scrollY,this._scrollX=this.scrollX}},{key:"_getWindowScrollPosition",value:function(){return{y:e.windowScrollY,x:e.windowScrollX}}},{key:"_getElementScrollPosition",value:function(){return{y:this._scrollTarget.scrollTop,x:this._scrollTarget.scrollLeft}}},{key:"onScroll",value:function(){return this._currentStopFrames=0,this._firstRender&&(this._firstRender=!1,this.y>1||this.x>1)?(this.updateScrollPosition(),void this.trigger(e.EVENT_SCROLL_PROGRESS)):void(this._scrolling||(this._scrolling=!0,this._lastDirectionY=e.NONE,this._lastDirectionX=e.NONE,this.trigger(e.EVENT_SCROLL_START),m.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this.onNextFrame()))}},{key:"onNextFrame",value:function(){var t=this;this._speedY=this._scrollY-this.scrollY,this._speedX=this._scrollX-this.scrollX;var i=+this.speedY+ +this.speedX;return this._scrolling&&0===i&&this._currentStopFrames++>this._stopFrames?void this.onScrollStop():(this.updateScrollPosition(),this._lastDirectionY!==this.directionY&&this.trigger("scroll:"+e.directionToString(this.directionY)),this._lastDirectionX!==this.directionX&&this.trigger("scroll:"+e.directionToString(this.directionX)),this._lastDirectionY=this.directionY,this._lastDirectionX=this.directionX,this.trigger(e.EVENT_SCROLL_PROGRESS),void(m.animationFrame?this.nextFrameID=window.requestAnimationFrame(this.onNextFrame):this._nextTimeout=setTimeout(function(){t.onNextFrame()},1e3/60)))}},{key:"onScrollStop",value:function(){this._scrolling=!1,this.updateScrollPosition(),this.trigger(e.EVENT_SCROLL_STOP),this._canScrollY&&(this.y<=0?this.trigger(e.EVENT_SCROLL_MIN):this.y+this.clientHeight>=this.scrollHeight&&this.trigger(e.EVENT_SCROLL_MAX)),this._canScrollX&&(this.x<=0?this.trigger(e.EVENT_SCROLL_MIN):this.x+this.clientWidth>=this.scrollWidth&&this.trigger(e.EVENT_SCROLL_MAX)),this._currentStopFrames=0,this._cancelNextFrame()}},{key:"_cancelNextFrame",value:function(){m.animationFrame?(window.cancelAnimationFrame(this.nextFrameID),this.nextFrameID=-1):clearTimeout(this._nextTimeout)}},{key:"destroyed",get:function(){return this._destroyed}},{key:"scrollPosition",get:function(){return this.getScrollPosition()}},{key:"directionY",get:function(){return!this._canScrollY||0===this.speedY&&!this._scrolling?this._directionY=e.NONE:this.speedY>0?this._directionY=e.UP:this.speedY<0&&(this._directionY=e.DOWN),this._directionY}},{key:"directionX",get:function(){return!this._canScrollX||0===this.speedX&&!this._scrolling?this._directionX=e.NONE:this.speedX>0?this._directionX=e.LEFT:this.speedX<0&&(this._directionX=e.RIGHT),this._directionX}},{key:"scrollTarget",get:function(){return this._scrollTarget}},{key:"delta",get:function(){return this.directionY}},{key:"scrolling",get:function(){return this._scrolling}},{key:"speedY",get:function(){return this._speedY}},{key:"speedX",get:function(){return this._speedX}},{key:"canScrollY",get:function(){return this._canScrollY}},{key:"canScrollX",get:function(){return this._canScrollX}},{key:"scrollY",get:function(){return this.scrollPosition.y}},{key:"y",get:function(){return this.scrollY}},{key:"scrollX",get:function(){return this.scrollPosition.x}},{key:"x",get:function(){return this.scrollX}},{key:"clientHeight",get:function(){return this._scrollTarget===window?window.innerHeight:this._scrollTarget.clientHeight}},{key:"clientWidth",get:function(){return this._scrollTarget===window?window.innerWidth:this._scrollTarget.clientWidth}},{key:"scrollHeight",get:function(){return this._scrollTarget===window?e.documentHeight:this._scrollTarget.scrollHeight}},{key:"scrollWidth",get:function(){return this._scrollTarget===window?e.documentWidth:this._scrollTarget.scrollWidth}}]),e}(d["default"]);_.UP=-1,_.DOWN=1,_.NONE=0,_.RIGHT=2,_.LEFT=-2,_.EVENT_SCROLL_PROGRESS="scroll:progress",_.EVENT_SCROLL_START="scroll:start",_.EVENT_SCROLL_STOP="scroll:stop",_.EVENT_SCROLL_DOWN="scroll:down",_.EVENT_SCROLL_UP="scroll:up",_.EVENT_SCROLL_MIN="scroll:min",_.EVENT_SCROLL_MAX="scroll:max",_.EVENT_SCROLL_RESIZE="scroll:resize",i["default"]=_;var p=null,m=function(){function t(){r(this,t)}return c(t,null,[{key:"animationFrame",get:function(){return null===p&&(p=!!(window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame)),p}}]),t}();e.exports=i["default"]},{"./scroll-parent":3,delegatejs:1,eventdispatcher:2}]},{},[4])(4)});
{
"name": "scrollfeatures",
"version": "1.0.1",
"version": "1.0.2",
"description": "Performant Custom Scroll Features and Events",

@@ -5,0 +5,0 @@ "main": "dist/scrollfeatures.js",

@@ -8,10 +8,10 @@ import delegate from 'delegatejs';

static getInstance(scrollTarget, options) {
if (!scrollTarget.scrollEvents) {
if (!scrollTarget.scrollFeatures) {
return new ScrollFeatures(scrollTarget, options);
}
return scrollTarget.scrollEvents;
return scrollTarget.scrollFeatures;
}
static hasInstance(scrollTarget) {
return (typeof scrollTarget.scrollEvents !== 'undefined');
return (typeof scrollTarget.scrollFeatures !== 'undefined');
}

@@ -23,4 +23,2 @@

static hasScrollTarget = ScrollFeatures.hasInstance;
static get windowScrollY() {

@@ -82,3 +80,3 @@ return (window.pageYOffset || window.scrollY || 0);

if (ScrollFeatures.hasScrollTarget(scrollTarget)) {
if (ScrollFeatures.hasInstance(scrollTarget)) {
return ScrollFeatures.getInstance(scrollTarget);

@@ -89,3 +87,3 @@ }

scrollTarget.scrollEvents = this;
scrollTarget.scrollFeatures = this;
this._scrollTarget = scrollTarget;

@@ -99,3 +97,2 @@ this.options = options;

this.init();
}

@@ -122,6 +119,6 @@

this.getScrollPosition = (this._scrollTarget === window) ? delegate(this, this._getWindowScrollPosition) : delegate(this, this._getElementScrollPosition);
this.getScrollPosition = delegate(this, (this._scrollTarget === window ? this._getWindowScrollPosition : this._getElementScrollPosition ));
this.onResize = delegate(this, () => this.trigger(ScrollFeatures.EVENT_SCROLL_RESIZE));
this.onScroll = delegate(this, this.onScroll);
this.onResize = delegate(this, this.onResize);
this.onNextFrame = delegate(this, this.onNextFrame);

@@ -133,2 +130,3 @@

this._canScrollX = this.clientWidth < this.scrollWidth;
if (this._scrollTarget !== window) {

@@ -141,7 +139,5 @@ var style = window.getComputedStyle(this._scrollTarget);

if (this._scrollTarget.addEventListener) {
// this._scrollTarget.addEventListener('mousewheel', this.onScroll, Can.passiveEvents ? { passive: true } : false);
this._scrollTarget.addEventListener('scroll', this.onScroll, false);
this._scrollTarget.addEventListener('resize', this.onResize, false);
} else if (this._scrollTarget.attachEvent) {
// this._scrollTarget.attachEvent('onmousewheel', this.onScroll);
this._scrollTarget.attachEvent('scroll', this.onScroll);

@@ -152,13 +148,2 @@ this._scrollTarget.attachEvent('resize', this.onResize);

update() {
var scrollY = this._scrollY;
var scrollX = this._scrollX;
this.updateScrollPosition();
if (scrollY !== this.y || scrollX !== this.x) {
this.trigger(ScrollFeatures.EVENT_SCROLL_PROGRESS);
}
}
get destroyed() {

@@ -168,3 +153,2 @@ return this._destroyed;

destroy() {

@@ -177,7 +161,5 @@ if (!this._destroyed) {

if (this._scrollTarget.addEventListener) {
// this._scrollTarget.removeEventListener('mousewheel', this.onScroll);
this._scrollTarget.removeEventListener('scroll', this.onScroll);
this._scrollTarget.removeEventListener('resize', this.onResize);
} else if (this._scrollTarget.attachEvent) {
// this._scrollTarget.detachEvent('onmousewheel', this.onScroll);
this._scrollTarget.detachEvent('scroll', this.onScroll);

@@ -198,3 +180,2 @@ this._scrollTarget.detachEvent('resize', this.onResize);

updateScrollPosition() {
this._scrollY = this.scrollY;

@@ -236,13 +217,2 @@ this._scrollX = this.scrollX;

get attributes() {
return {
y: this.y,
x: this.x,
speedY: this.speedY,
speedX: this.speedX,
directionY: this.directionY,
directionX: this.directionX
};
}
get scrollTarget() {

@@ -268,3 +238,12 @@ return this._scrollTarget;

get canScrollY() {
return this._canScrollY;
}
get canScrollX() {
return this._canScrollX;
}
get scrollY() {

@@ -318,7 +297,3 @@ return this.scrollPosition.y;

onResize() {
this.trigger(ScrollFeatures.EVENT_SCROLL_RESIZE);
}
onScroll() {

@@ -421,6 +396,11 @@ this._currentStopFrames = 0;

var _animationFrame = null;
class Can {
static get animationFrame() {
return !!(window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame);
};
if(_animationFrame === null){
_animationFrame = !!(window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame);
}
return _animationFrame;
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc