Socket
Socket
Sign inDemoInstall

@webcreate/infinite-ajax-scroll

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webcreate/infinite-ajax-scroll - npm Package Compare versions

Comparing version 3.0.0-beta.2 to 3.0.0-beta.4

2

CHANGELOG.md

@@ -97,3 +97,3 @@ Changelog

[Unreleased]: https://github.com/webcreate/infinite-ajax-scroll/compare/v2.3.1...3.x
[Unreleased]: https://github.com/webcreate/infinite-ajax-scroll/compare/v2.3.1...master
[2.3.1]: https://github.com/webcreate/infinite-ajax-scroll/compare/v2.3.0...v2.3.1

@@ -100,0 +100,0 @@ [2.3.0]: https://github.com/webcreate/infinite-ajax-scroll/compare/v2.2.3...v2.3.0

/**
* Infinite Ajax Scroll v3.0.0-beta.2
* Infinite Ajax Scroll v3.0.0-beta.4
* Turn your existing pagination into infinite scrolling pages with ease

@@ -24,3 +24,4 @@ *

spinner: false,
logger: true
logger: true,
loadOnScroll: true
};

@@ -234,3 +235,5 @@

Assert.singleElement(this.options.element, 'spinner.element');
if (this.options.element !== undefined) {
Assert.singleElement(this.options.element, 'spinner.element');
}

@@ -405,5 +408,7 @@ this.element = $(this.options.element)[0]; // @todo should we really cache this?

var loaded = function (event) {
// @todo event.xhr.response.title only works in case of responseType = "document"
url = event.url;
title = event.xhr.response.title;
if (event.xhr.response) {
title = event.xhr.response.title;
}
};

@@ -459,2 +464,3 @@

var InfiniteAjaxScroll = function InfiniteAjaxScroll(container, options) {
var this$1 = this;
if ( options === void 0 ) options = {};

@@ -482,6 +488,15 @@

this.paused = false;
this.loadOnScroll = this.options.loadOnScroll;
this.pageIndex = this.sentinel() ? 0 : -1;
this.lastDistance = null;
this.on('hit', this.next);
this.on('hit', function () {
if (!this$1.loadOnScroll) {
return;
}
this$1.next();
});
// initialize extensions
this.pagination = new Pagination(this, this.options.pagination);

@@ -496,3 +511,3 @@ this.spinner = new Spinner(this, this.options.spinner);

if (this.options.bind) {
// @todo on document.ready?
// @todo on document.ready? (window.addEventListener('DOMContentLoaded'))
this.bind();

@@ -544,2 +559,4 @@ }

.then(function (result) {
this$1.pageIndex = event.pageIndex;
if (!result) {

@@ -551,3 +568,2 @@ this$1.emitter.emit('last');

this$1.pageIndex = event.pageIndex;
this$1.resume();

@@ -653,2 +669,10 @@ })

InfiniteAjaxScroll.prototype.enableLoadOnScroll = function enableLoadOnScroll () {
this.loadOnScroll = true;
};
InfiniteAjaxScroll.prototype.disableLoadOnScroll = function disableLoadOnScroll () {
this.loadOnScroll = false;
};
InfiniteAjaxScroll.prototype.measure = function measure () {

@@ -667,5 +691,7 @@ if (this.paused) {

if (distance <= 0) {
if (distance <= 0 && (this.lastDistance === null || this.lastDistance > 0)) {
this.emitter.emit('hit', {distance: distance});
}
this.lastDistance = distance;
};

@@ -672,0 +698,0 @@

/**
* Infinite Ajax Scroll v3.0.0-beta.2
* Infinite Ajax Scroll v3.0.0-beta.4
* Turn your existing pagination into infinite scrolling pages with ease

@@ -245,3 +245,3 @@ *

var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

@@ -696,3 +696,4 @@ /**

spinner: false,
logger: true
logger: true,
loadOnScroll: true
};

@@ -866,2 +867,4 @@

var tinyEmitter = E;
var TinyEmitter = E;
tinyEmitter.TinyEmitter = TinyEmitter;

@@ -973,3 +976,5 @@ var lastResponse = document;

Assert.singleElement(this.options.element, 'spinner.element');
if (this.options.element !== undefined) {
Assert.singleElement(this.options.element, 'spinner.element');
}

@@ -1144,5 +1149,7 @@ this.element = tealight(this.options.element)[0]; // @todo should we really cache this?

var loaded = function (event) {
// @todo event.xhr.response.title only works in case of responseType = "document"
url = event.url;
title = event.xhr.response.title;
if (event.xhr.response) {
title = event.xhr.response.title;
}
};

@@ -1198,2 +1205,3 @@

var InfiniteAjaxScroll = function InfiniteAjaxScroll(container, options) {
var this$1 = this;
if ( options === void 0 ) options = {};

@@ -1221,6 +1229,15 @@

this.paused = false;
this.loadOnScroll = this.options.loadOnScroll;
this.pageIndex = this.sentinel() ? 0 : -1;
this.lastDistance = null;
this.on('hit', this.next);
this.on('hit', function () {
if (!this$1.loadOnScroll) {
return;
}
this$1.next();
});
// initialize extensions
this.pagination = new Pagination(this, this.options.pagination);

@@ -1235,3 +1252,3 @@ this.spinner = new Spinner(this, this.options.spinner);

if (this.options.bind) {
// @todo on document.ready?
// @todo on document.ready? (window.addEventListener('DOMContentLoaded'))
this.bind();

@@ -1283,2 +1300,4 @@ }

.then(function (result) {
this$1.pageIndex = event.pageIndex;
if (!result) {

@@ -1290,3 +1309,2 @@ this$1.emitter.emit('last');

this$1.pageIndex = event.pageIndex;
this$1.resume();

@@ -1392,2 +1410,10 @@ })

InfiniteAjaxScroll.prototype.enableLoadOnScroll = function enableLoadOnScroll () {
this.loadOnScroll = true;
};
InfiniteAjaxScroll.prototype.disableLoadOnScroll = function disableLoadOnScroll () {
this.loadOnScroll = false;
};
InfiniteAjaxScroll.prototype.measure = function measure () {

@@ -1406,5 +1432,7 @@ if (this.paused) {

if (distance <= 0) {
if (distance <= 0 && (this.lastDistance === null || this.lastDistance > 0)) {
this.emitter.emit('hit', {distance: distance});
}
this.lastDistance = distance;
};

@@ -1411,0 +1439,0 @@

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.InfiniteAjaxScroll=e()}(this,function(){"use strict";function t(t){return"object"==typeof window.Node?t instanceof window.Node:null!==t&&"object"==typeof t&&"number"==typeof t.nodeType&&"string"==typeof t.nodeName}function e(e,n){if(void 0===n&&(n=document),e instanceof Array)return e.filter(t);if(t(e))return[e];if(o=Object.prototype.toString.call(i=e),"object"==typeof window.NodeList?i instanceof window.NodeList:null!==i&&"object"==typeof i&&"number"==typeof i.length&&/^\[object (HTMLCollection|NodeList|Object)\]$/.test(o)&&(0===i.length||t(i[0])))return Array.prototype.slice.call(e);var i,o;if("string"==typeof e)try{var r=n.querySelectorAll(e);return Array.prototype.slice.call(r)}catch(t){return[]}return[]}var n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},l=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e,o=n.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&n.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!o&&!r)return!1;for(e in t);return void 0===e||n.call(t,e)},a=function(t,e){o&&"__proto__"===e.name?o(t,e.name,{enumerable:!0,configurable:!0,value:e.newValue,writable:!0}):t[e.name]=e.newValue},c=function(t,e){if("__proto__"===e){if(!n.call(t,e))return;if(r)return r(t,e).value}return t[e]},u=function t(){var e,n,i,o,r,u,d=arguments,p=arguments[0],h=1,f=arguments.length,m=!1;for("boolean"==typeof p&&(m=p,p=arguments[1]||{},h=2),(null==p||"object"!=typeof p&&"function"!=typeof p)&&(p={});f>h;++h)if(null!=(e=d[h]))for(n in e)i=c(p,n),p!==(o=c(e,n))&&(m&&o&&(l(o)||(r=s(o)))?(r?(r=!1,u=i&&s(i)?i:[]):u=i&&l(i)?i:{},a(p,{name:n,newValue:t(m,u,o)})):void 0!==o&&a(p,{name:n,newValue:o}));return p},d="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},p="Expected a function",h=NaN,f="[object Symbol]",m=/^\s+|\s+$/g,y=/^[-+]0x[0-9a-f]+$/i,g=/^0b[01]+$/i,v=/^0o[0-7]+$/i,b=parseInt,w="object"==typeof self&&self&&self.Object===Object&&self,x="object"==typeof d&&d&&d.Object===Object&&d||w||Function("return this")(),j=Object.prototype.toString,C=Math.max,T=Math.min,I=function(){return x.Date.now()};function O(t,e,n){var i,o,r,s,l,a,c=0,u=!1,d=!1,h=!0;if("function"!=typeof t)throw new TypeError(p);function f(e){var n=i,r=o;return i=o=void 0,c=e,s=t.apply(r,n)}function m(t){var n=t-a;return void 0===a||n>=e||0>n||d&&t-c>=r}function y(){var t=I();if(m(t))return g(t);l=setTimeout(y,function(t){var n=e-(t-a);return d?T(n,r-(t-c)):n}(t))}function g(t){return l=void 0,h&&i?f(t):(i=o=void 0,s)}function v(){var t=I(),n=m(t);if(i=arguments,o=this,a=t,n){if(void 0===l)return function(t){return c=t,l=setTimeout(y,e),u?f(t):s}(a);if(d)return l=setTimeout(y,e),f(a)}return void 0===l&&(l=setTimeout(y,e)),s}return e=E(e)||0,S(n)&&(u=!!n.leading,r=(d="maxWait"in n)?C(E(n.maxWait)||0,e):r,h="trailing"in n?!!n.trailing:h),v.cancel=function(){void 0!==l&&clearTimeout(l),c=0,i=a=o=l=void 0},v.flush=function(){return void 0===l?s:g(I())},v}function S(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function E(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&j.call(t)==f}(t))return h;if(S(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=S(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(m,"");var n=g.test(t);return n||v.test(t)?b(t.slice(2),n?2:8):y.test(t)?h:+t}var P=function(t,e,n){var i=!0,o=!0;if("function"!=typeof t)throw new TypeError(p);return S(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),O(t,e,{leading:i,maxWait:e,trailing:o})},L={item:void 0,next:void 0,pagination:void 0,responseType:"document",bind:!0,scrollContainer:window,spinner:!1,logger:!0},F=function(t,n){var i=e(t);if(i.length>1)throw Error('Expected single element for "'+n+'"');if(0===i.length)throw Error('Element "'+t+'" not found for "'+n+'"')};function H(t){if(t!==window)return{x:t.scrollLeft,y:t.scrollTop};var e=void 0!==window.pageXOffset,n="CSS1Compat"===(document.compatMode||"");return{x:e?window.pageXOffset:n?document.documentElement.scrollLeft:document.body.scrollLeft,y:e?window.pageYOffset:n?document.documentElement.scrollTop:document.body.scrollTop}}function A(t){var e;if(t!==window)e=t.getBoundingClientRect();else{var n=document.documentElement,i=document.body;e={top:0,left:0,right:n.clientWidth||i.clientWidth,width:n.clientWidth||i.clientWidth,bottom:n.clientHeight||i.clientHeight,height:n.clientHeight||i.clientHeight}}return e}var N={y:0,x:0,deltaY:0,deltaX:0};function _(t){var e=H(t);return e.deltaY=e.y-(N?N.y:e.y),e.deltaX=e.x-(N?N.x:e.x),N=e,e}function B(){var t=_(this.scrollContainer);this.emitter.emit("scrolled",{scroll:t}),this.measure()}function D(){var t=_(this.scrollContainer);this.emitter.emit("resized",{scroll:t}),this.measure()}function M(){}M.prototype={on:function(t,e,n){var i=this.e||(this.e={});return(i[t]||(i[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){var i=this;function o(){i.off(t,o),e.apply(n,arguments)}return o._=e,this.on(t,o,n)},emit:function(t){for(var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),i=0,o=n.length;o>i;i++)n[i].fn.apply(n[i].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),i=n[t],o=[];if(i&&e)for(var r=0,s=i.length;s>r;r++)i[r].fn!==e&&i[r].fn._!==e&&o.push(i[r]);return o.length?n[t]=o:delete n[t],this}};var R=M,q=document;function W(t){var n=this,i=e(n.options.next,q)[0];if(i)return n.load(i.href).then(function(t){var i=e(n.options.next,q=t.xhr.response)[0];return n.append(t.items).then(function(){return!!i})})}var X={element:void 0,hide:!1};var k=function(t,e){this.options=u({},X,function(t){return"string"==typeof t?t={element:t,hide:!0}:"boolean"==typeof t&&(t={element:void 0,hide:t}),t}(e)),this.options.hide&&(F(this.options.element,"pagination.element"),t.on("binded",this.hide.bind(this)),t.on("unbinded",this.restore.bind(this)))};k.prototype.hide=function(){var t=e(this.options.element)[0];this.originalDisplayStyle=window.getComputedStyle(t).display,t.style.display="none"},k.prototype.restore=function(){e(this.options.element)[0].style.display=this.originalDisplayStyle};var $={element:void 0,delay:600,show:function(t){t.style.opacity="1"},hide:function(t){t.style.opacity="0"}};var z=function(t,n){!1!==n&&(this.ias=t,this.options=u({},$,function(t){return"string"==typeof t&&(t={element:t}),t}(n)),F(this.options.element,"spinner.element"),this.element=e(this.options.element)[0],this.hideFn=this.options.hide,this.showFn=this.options.show,t.on("binded",this.bind.bind(this)),t.on("binded",this.hide.bind(this)))};z.prototype.bind=function(){var t,e,n=this,i=this.ias;i.on("next",function(){t=+new Date,n.show()}),i.on("last",function(){n.hide()}),i.on("append",function(i){e=Math.max(0,n.options.delay-(+new Date-t));var o=i.appendFn;i.appendFn=function(t,i,r){return new Promise(function(s){setTimeout(function(){Promise.resolve(n.hide()).then(function(){o(t,i,r),s()})},e)})}})},z.prototype.show=function(){return Promise.resolve(this.showFn(this.element))},z.prototype.hide=function(){return Promise.resolve(this.hideFn(this.element))};var V={hit:function(){console.log("Hit scroll threshold")},binded:function(){console.log("Binded event handlers")},unbinded:function(){console.log("Unbinded event handlers")},next:function(t){console.log("Next page triggered [pageIndex="+t.pageIndex+"]")},load:function(t){console.log("Start loading "+t.url)},loaded:function(){console.log("Finished loading")},append:function(){console.log("Start appending items")},appended:function(t){console.log("Finished appending "+t.items.length+" item(s)")},last:function(){console.log("No more pages left to load")},page:function(t){console.log("Page changed [pageIndex="+t.pageIndex+"]")}};var Y=function(t,e){if(!1!==e){var n=function(t){return!0===t&&(t=V),t}(e);Object.keys(n).forEach(function(e){t.on(e,n[e])})}};var G,U,J=function(t){this.ias=t,this.pageBreaks=[],this.currentPageIndex=t.pageIndex,this.currentScrollTop=0,t.on("binded",this.binded.bind(this)),t.on("next",this.next.bind(this)),t.on("scrolled",this.scrolled.bind(this)),t.on("resized",this.scrolled.bind(this))};function K(t,e,n){var i=n?n.nextSibling:null,o=document.createDocumentFragment();t.forEach(function(t){o.appendChild(t)}),e.insertBefore(o,i)}J.prototype.binded=function(){this.ias.sentinel()&&this.pageBreaks.push({pageIndex:this.currentPageIndex,url:""+document.location,title:document.title,sentinel:this.ias.sentinel()})},J.prototype.next=function(t){var e,n,i=this,o=function(t){e=t.url,n=t.xhr.response.title};this.ias.once("loaded",o),this.ias.once("appended",function(){i.pageBreaks.push({pageIndex:t.pageIndex,url:e,title:n,sentinel:i.ias.sentinel()}),i.update(),i.ias.off("loaded",o)})},J.prototype.scrolled=function(t){this.update(t.scroll.y)},J.prototype.update=function(t){this.currentScrollTop=t||this.currentScrollTop;var e=function(t,e,n){for(var i=e+A(n).height,o=t.length-1;o>=0;o--)if(i>t[o].sentinel.getBoundingClientRect().bottom+e)return t[Math.min(o+1,t.length-1)];return t[0]}(this.pageBreaks,this.currentScrollTop,this.ias.scrollContainer);e&&e.pageIndex!==this.currentPageIndex&&(this.ias.emitter.emit("page",e),this.currentPageIndex=e.pageIndex)};var Q=function(t,n){void 0===n&&(n={}),F(t,"container"),this.container=e(t)[0],this.options=u({},L,n),this.emitter=new R,this.scrollContainer=this.options.scrollContainer,this.options.scrollContainer!==window&&(F(this.options.scrollContainer,"options.scrollContainer"),this.scrollContainer=e(this.options.scrollContainer)[0]),this.nextHandler=W,"function"==typeof this.options.next&&(this.nextHandler=this.options.next),this.binded=!1,this.paused=!1,this.pageIndex=this.sentinel()?0:-1,this.on("hit",this.next),this.pagination=new k(this,this.options.pagination),this.spinner=new z(this,this.options.spinner),this.logger=new Y(this,this.options.logger),this.paging=new J(this),this.on("binded",this.measure),this.options.bind&&this.bind()};return Q.prototype.bind=function(){this.binded||(G=P(B,200).bind(this),U=P(D,200).bind(this),this.scrollContainer.addEventListener("scroll",G),this.scrollContainer.addEventListener("resize",U),this.binded=!0,this.emitter.emit("binded"))},Q.prototype.unbind=function(){this.binded&&(this.scrollContainer.removeEventListener("resize",U),this.scrollContainer.removeEventListener("scroll",G),this.binded=!1,this.emitter.emit("unbinded"))},Q.prototype.next=function(){var t=this;this.pause();var e={pageIndex:this.pageIndex+1};this.emitter.emit("next",e),Promise.resolve(this.nextHandler(e.pageIndex)).then(function(n){n?(t.pageIndex=e.pageIndex,t.resume()):t.emitter.emit("last")})},Q.prototype.load=function(t){var n=this;return new Promise(function(i,o){var r=new XMLHttpRequest;r.onreadystatechange=function(){if(r.readyState===XMLHttpRequest.DONE)if(200===r.status){var s=r.response;"document"===n.options.responseType&&(s=e(n.options.item,r.response)),n.emitter.emit("loaded",{items:s,url:t,xhr:r}),i({items:s,url:t,xhr:r})}else console.error("Request failed"),o(r)};var s=t+(/\?/.test(t)?"&":"?")+(new Date).getTime();r.open("GET",s,!0),r.responseType=n.options.responseType,r.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.emitter.emit("load",{url:t,xhr:r}),r.send()})},Q.prototype.append=function(t,e){var n=this,i={items:t,parent:e=e||n.container,appendFn:K};n.emitter.emit("append",i);return new Promise(function(o){window.requestAnimationFrame(function(){Promise.resolve(i.appendFn(i.items,i.parent,n.sentinel())).then(function(){o({items:t,parent:e})})})}).then(function(t){n.emitter.emit("appended",t)})},Q.prototype.sentinel=function(){var t=e(this.options.item,this.container);return t.length?t[t.length-1]:null},Q.prototype.pause=function(){this.paused=!0},Q.prototype.resume=function(){this.paused=!1,this.measure()},Q.prototype.measure=function(){if(!this.paused){var t,e,n,i,o,r=0,s=this.sentinel();s&&(t=s,n=H(e=this.scrollContainer),i=A(e),o=t.getBoundingClientRect(),r=n.y+o.bottom-i.top-(n.y+i.height)),r>0||this.emitter.emit("hit",{distance:r})}},Q.prototype.on=function(t,e){this.emitter.on(t,e,this),"binded"===t&&this.binded&&e.bind(this)()},Q.prototype.off=function(t,e){this.emitter.off(t,e,this)},Q.prototype.once=function(t,e){this.emitter.once(t,e,this),"binded"===t&&this.binded&&e.bind(this)()},Q});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.InfiniteAjaxScroll=e()}(this,function(){"use strict";function t(t){return"object"==typeof window.Node?t instanceof window.Node:null!==t&&"object"==typeof t&&"number"==typeof t.nodeType&&"string"==typeof t.nodeName}function e(e,n){if(void 0===n&&(n=document),e instanceof Array)return e.filter(t);if(t(e))return[e];if(o=Object.prototype.toString.call(i=e),"object"==typeof window.NodeList?i instanceof window.NodeList:null!==i&&"object"==typeof i&&"number"==typeof i.length&&/^\[object (HTMLCollection|NodeList|Object)\]$/.test(o)&&(0===i.length||t(i[0])))return Array.prototype.slice.call(e);var i,o;if("string"==typeof e)try{var r=n.querySelectorAll(e);return Array.prototype.slice.call(r)}catch(t){return[]}return[]}var n=Object.prototype.hasOwnProperty,i=Object.prototype.toString,o=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===i.call(t)},l=function(t){if(!t||"[object Object]"!==i.call(t))return!1;var e,o=n.call(t,"constructor"),r=t.constructor&&t.constructor.prototype&&n.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!o&&!r)return!1;for(e in t);return void 0===e||n.call(t,e)},a=function(t,e){o&&"__proto__"===e.name?o(t,e.name,{enumerable:!0,configurable:!0,value:e.newValue,writable:!0}):t[e.name]=e.newValue},c=function(t,e){if("__proto__"===e){if(!n.call(t,e))return;if(r)return r(t,e).value}return t[e]},u=function t(){var e,n,i,o,r,u,d=arguments,p=arguments[0],h=1,f=arguments.length,m=!1;for("boolean"==typeof p&&(m=p,p=arguments[1]||{},h=2),(null==p||"object"!=typeof p&&"function"!=typeof p)&&(p={});f>h;++h)if(null!=(e=d[h]))for(n in e)i=c(p,n),p!==(o=c(e,n))&&(m&&o&&(l(o)||(r=s(o)))?(r?(r=!1,u=i&&s(i)?i:[]):u=i&&l(i)?i:{},a(p,{name:n,newValue:t(m,u,o)})):void 0!==o&&a(p,{name:n,newValue:o}));return p},d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},p="Expected a function",h=NaN,f="[object Symbol]",m=/^\s+|\s+$/g,y=/^[-+]0x[0-9a-f]+$/i,g=/^0b[01]+$/i,v=/^0o[0-7]+$/i,b=parseInt,w="object"==typeof self&&self&&self.Object===Object&&self,x="object"==typeof d&&d&&d.Object===Object&&d||w||Function("return this")(),O=Object.prototype.toString,j=Math.max,S=Math.min,T=function(){return x.Date.now()};function C(t,e,n){var i,o,r,s,l,a,c=0,u=!1,d=!1,h=!0;if("function"!=typeof t)throw new TypeError(p);function f(e){var n=i,r=o;return i=o=void 0,c=e,s=t.apply(r,n)}function m(t){var n=t-a;return void 0===a||n>=e||0>n||d&&t-c>=r}function y(){var t=T();if(m(t))return g(t);l=setTimeout(y,function(t){var n=e-(t-a);return d?S(n,r-(t-c)):n}(t))}function g(t){return l=void 0,h&&i?f(t):(i=o=void 0,s)}function v(){var t=T(),n=m(t);if(i=arguments,o=this,a=t,n){if(void 0===l)return function(t){return c=t,l=setTimeout(y,e),u?f(t):s}(a);if(d)return l=setTimeout(y,e),f(a)}return void 0===l&&(l=setTimeout(y,e)),s}return e=E(e)||0,I(n)&&(u=!!n.leading,r=(d="maxWait"in n)?j(E(n.maxWait)||0,e):r,h="trailing"in n?!!n.trailing:h),v.cancel=function(){void 0!==l&&clearTimeout(l),c=0,i=a=o=l=void 0},v.flush=function(){return void 0===l?s:g(T())},v}function I(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function E(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return!!t&&"object"==typeof t}(t)&&O.call(t)==f}(t))return h;if(I(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=I(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(m,"");var n=g.test(t);return n||v.test(t)?b(t.slice(2),n?2:8):y.test(t)?h:+t}var P=function(t,e,n){var i=!0,o=!0;if("function"!=typeof t)throw new TypeError(p);return I(n)&&(i="leading"in n?!!n.leading:i,o="trailing"in n?!!n.trailing:o),C(t,e,{leading:i,maxWait:e,trailing:o})},L={item:void 0,next:void 0,pagination:void 0,responseType:"document",bind:!0,scrollContainer:window,spinner:!1,logger:!0,loadOnScroll:!0},D=function(t,n){var i=e(t);if(i.length>1)throw Error('Expected single element for "'+n+'"');if(0===i.length)throw Error('Element "'+t+'" not found for "'+n+'"')};function F(t){if(t!==window)return{x:t.scrollLeft,y:t.scrollTop};var e=void 0!==window.pageXOffset,n="CSS1Compat"===(document.compatMode||"");return{x:e?window.pageXOffset:n?document.documentElement.scrollLeft:document.body.scrollLeft,y:e?window.pageYOffset:n?document.documentElement.scrollTop:document.body.scrollTop}}function H(t){var e;if(t!==window)e=t.getBoundingClientRect();else{var n=document.documentElement,i=document.body;e={top:0,left:0,right:n.clientWidth||i.clientWidth,width:n.clientWidth||i.clientWidth,bottom:n.clientHeight||i.clientHeight,height:n.clientHeight||i.clientHeight}}return e}var A={y:0,x:0,deltaY:0,deltaX:0};function N(t){var e=F(t);return e.deltaY=e.y-(A?A.y:e.y),e.deltaX=e.x-(A?A.x:e.x),A=e,e}function _(){var t=N(this.scrollContainer);this.emitter.emit("scrolled",{scroll:t}),this.measure()}function B(){var t=N(this.scrollContainer);this.emitter.emit("resized",{scroll:t}),this.measure()}function M(){}M.prototype={on:function(t,e,n){var i=this.e||(this.e={});return(i[t]||(i[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){var i=this;function o(){i.off(t,o),e.apply(n,arguments)}return o._=e,this.on(t,o,n)},emit:function(t){for(var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),i=0,o=n.length;o>i;i++)n[i].fn.apply(n[i].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),i=n[t],o=[];if(i&&e)for(var r=0,s=i.length;s>r;r++)i[r].fn!==e&&i[r].fn._!==e&&o.push(i[r]);return o.length?n[t]=o:delete n[t],this}};var R=M;R.TinyEmitter=M;var q=document;function W(t){var n=this,i=e(n.options.next,q)[0];if(i)return n.load(i.href).then(function(t){var i=e(n.options.next,q=t.xhr.response)[0];return n.append(t.items).then(function(){return!!i})})}var X={element:void 0,hide:!1};var k=function(t,e){this.options=u({},X,function(t){return"string"==typeof t?t={element:t,hide:!0}:"boolean"==typeof t&&(t={element:void 0,hide:t}),t}(e)),this.options.hide&&(D(this.options.element,"pagination.element"),t.on("binded",this.hide.bind(this)),t.on("unbinded",this.restore.bind(this)))};k.prototype.hide=function(){var t=e(this.options.element)[0];this.originalDisplayStyle=window.getComputedStyle(t).display,t.style.display="none"},k.prototype.restore=function(){e(this.options.element)[0].style.display=this.originalDisplayStyle};var $={element:void 0,delay:600,show:function(t){t.style.opacity="1"},hide:function(t){t.style.opacity="0"}};var z=function(t,n){!1!==n&&(this.ias=t,this.options=u({},$,function(t){return"string"==typeof t&&(t={element:t}),t}(n)),void 0!==this.options.element&&D(this.options.element,"spinner.element"),this.element=e(this.options.element)[0],this.hideFn=this.options.hide,this.showFn=this.options.show,t.on("binded",this.bind.bind(this)),t.on("binded",this.hide.bind(this)))};z.prototype.bind=function(){var t,e,n=this,i=this.ias;i.on("next",function(){t=+new Date,n.show()}),i.on("last",function(){n.hide()}),i.on("append",function(i){e=Math.max(0,n.options.delay-(+new Date-t));var o=i.appendFn;i.appendFn=function(t,i,r){return new Promise(function(s){setTimeout(function(){Promise.resolve(n.hide()).then(function(){o(t,i,r),s()})},e)})}})},z.prototype.show=function(){return Promise.resolve(this.showFn(this.element))},z.prototype.hide=function(){return Promise.resolve(this.hideFn(this.element))};var V={hit:function(){console.log("Hit scroll threshold")},binded:function(){console.log("Binded event handlers")},unbinded:function(){console.log("Unbinded event handlers")},next:function(t){console.log("Next page triggered [pageIndex="+t.pageIndex+"]")},load:function(t){console.log("Start loading "+t.url)},loaded:function(){console.log("Finished loading")},append:function(){console.log("Start appending items")},appended:function(t){console.log("Finished appending "+t.items.length+" item(s)")},last:function(){console.log("No more pages left to load")},page:function(t){console.log("Page changed [pageIndex="+t.pageIndex+"]")}};var Y=function(t,e){if(!1!==e){var n=function(t){return!0===t&&(t=V),t}(e);Object.keys(n).forEach(function(e){t.on(e,n[e])})}};var G,U,J=function(t){this.ias=t,this.pageBreaks=[],this.currentPageIndex=t.pageIndex,this.currentScrollTop=0,t.on("binded",this.binded.bind(this)),t.on("next",this.next.bind(this)),t.on("scrolled",this.scrolled.bind(this)),t.on("resized",this.scrolled.bind(this))};function K(t,e,n){var i=n?n.nextSibling:null,o=document.createDocumentFragment();t.forEach(function(t){o.appendChild(t)}),e.insertBefore(o,i)}J.prototype.binded=function(){this.ias.sentinel()&&this.pageBreaks.push({pageIndex:this.currentPageIndex,url:""+document.location,title:document.title,sentinel:this.ias.sentinel()})},J.prototype.next=function(t){var e,n,i=this,o=function(t){e=t.url,t.xhr.response&&(n=t.xhr.response.title)};this.ias.once("loaded",o),this.ias.once("appended",function(){i.pageBreaks.push({pageIndex:t.pageIndex,url:e,title:n,sentinel:i.ias.sentinel()}),i.update(),i.ias.off("loaded",o)})},J.prototype.scrolled=function(t){this.update(t.scroll.y)},J.prototype.update=function(t){this.currentScrollTop=t||this.currentScrollTop;var e=function(t,e,n){for(var i=e+H(n).height,o=t.length-1;o>=0;o--)if(i>t[o].sentinel.getBoundingClientRect().bottom+e)return t[Math.min(o+1,t.length-1)];return t[0]}(this.pageBreaks,this.currentScrollTop,this.ias.scrollContainer);e&&e.pageIndex!==this.currentPageIndex&&(this.ias.emitter.emit("page",e),this.currentPageIndex=e.pageIndex)};var Q=function(t,n){var i=this;void 0===n&&(n={}),D(t,"container"),this.container=e(t)[0],this.options=u({},L,n),this.emitter=new R,this.scrollContainer=this.options.scrollContainer,this.options.scrollContainer!==window&&(D(this.options.scrollContainer,"options.scrollContainer"),this.scrollContainer=e(this.options.scrollContainer)[0]),this.nextHandler=W,"function"==typeof this.options.next&&(this.nextHandler=this.options.next),this.binded=!1,this.paused=!1,this.loadOnScroll=this.options.loadOnScroll,this.pageIndex=this.sentinel()?0:-1,this.lastDistance=null,this.on("hit",function(){i.loadOnScroll&&i.next()}),this.pagination=new k(this,this.options.pagination),this.spinner=new z(this,this.options.spinner),this.logger=new Y(this,this.options.logger),this.paging=new J(this),this.on("binded",this.measure),this.options.bind&&this.bind()};return Q.prototype.bind=function(){this.binded||(G=P(_,200).bind(this),U=P(B,200).bind(this),this.scrollContainer.addEventListener("scroll",G),this.scrollContainer.addEventListener("resize",U),this.binded=!0,this.emitter.emit("binded"))},Q.prototype.unbind=function(){this.binded&&(this.scrollContainer.removeEventListener("resize",U),this.scrollContainer.removeEventListener("scroll",G),this.binded=!1,this.emitter.emit("unbinded"))},Q.prototype.next=function(){var t=this;this.pause();var e={pageIndex:this.pageIndex+1};this.emitter.emit("next",e),Promise.resolve(this.nextHandler(e.pageIndex)).then(function(n){t.pageIndex=e.pageIndex,n?t.resume():t.emitter.emit("last")})},Q.prototype.load=function(t){var n=this;return new Promise(function(i,o){var r=new XMLHttpRequest;r.onreadystatechange=function(){if(r.readyState===XMLHttpRequest.DONE)if(200===r.status){var s=r.response;"document"===n.options.responseType&&(s=e(n.options.item,r.response)),n.emitter.emit("loaded",{items:s,url:t,xhr:r}),i({items:s,url:t,xhr:r})}else console.error("Request failed"),o(r)};var s=t+(/\?/.test(t)?"&":"?")+(new Date).getTime();r.open("GET",s,!0),r.responseType=n.options.responseType,r.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.emitter.emit("load",{url:t,xhr:r}),r.send()})},Q.prototype.append=function(t,e){var n=this,i={items:t,parent:e=e||n.container,appendFn:K};n.emitter.emit("append",i);return new Promise(function(o){window.requestAnimationFrame(function(){Promise.resolve(i.appendFn(i.items,i.parent,n.sentinel())).then(function(){o({items:t,parent:e})})})}).then(function(t){n.emitter.emit("appended",t)})},Q.prototype.sentinel=function(){var t=e(this.options.item,this.container);return t.length?t[t.length-1]:null},Q.prototype.pause=function(){this.paused=!0},Q.prototype.resume=function(){this.paused=!1,this.measure()},Q.prototype.enableLoadOnScroll=function(){this.loadOnScroll=!0},Q.prototype.disableLoadOnScroll=function(){this.loadOnScroll=!1},Q.prototype.measure=function(){if(!this.paused){var t,e,n,i,o,r=0,s=this.sentinel();s&&(t=s,n=F(e=this.scrollContainer),i=H(e),o=t.getBoundingClientRect(),r=n.y+o.bottom-i.top-(n.y+i.height)),r>0||null!==this.lastDistance&&0>=this.lastDistance||this.emitter.emit("hit",{distance:r}),this.lastDistance=r}},Q.prototype.on=function(t,e){this.emitter.on(t,e,this),"binded"===t&&this.binded&&e.bind(this)()},Q.prototype.off=function(t,e){this.emitter.off(t,e,this)},Q.prototype.once=function(t,e){this.emitter.once(t,e,this),"binded"===t&&this.binded&&e.bind(this)()},Q});
{
"name": "@webcreate/infinite-ajax-scroll",
"version": "3.0.0-beta.2",
"version": "3.0.0-beta.4",
"title": "Infinite Ajax Scroll",

@@ -46,12 +46,12 @@ "description": "Turn your existing pagination into infinite scrolling pages with ease",

"tealight": "^0.3.6",
"tiny-emitter": "^2.0.2"
"tiny-emitter": "^2.1.0"
},
"devDependencies": {
"cypress": "^3.1.4",
"eslint": "^5.8.0",
"eslint-plugin-cypress": "^2.1.2",
"cypress": "^3.3.2",
"eslint": "^5.16.0",
"eslint-plugin-cypress": "^2.2.1",
"http-server": "^0.11.1",
"rollup": "^0.66.6",
"rollup-plugin-buble": "^0.19.4",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-buble": "^0.19.8",
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^3.4.0",

@@ -58,0 +58,0 @@ "rollup-plugin-terser": "^3.0.0"

@@ -9,2 +9,4 @@ <p align="center">

**Note: You're viewing the 3.x branch which is in development. See the [2.x](https://github.com/webcreate/infinite-ajax-scroll/tree/2.x) branch for the latest stable version.**
Turn your existing pagination into infinite scrolling pages with ease.

@@ -60,2 +62,5 @@

```javascript
// import if you use the NPM package
import InfiniteAjaxScroll from '@webcreate/infinite-ajax-scroll';
let ias = new InfiniteAjaxScroll('.container', {

@@ -62,0 +67,0 @@ item: '.item',

@@ -9,3 +9,4 @@ export default {

spinner: false,
logger: true
logger: true,
loadOnScroll: true
};

@@ -41,6 +41,15 @@ import $ from 'tealight';

this.paused = false;
this.loadOnScroll = this.options.loadOnScroll;
this.pageIndex = this.sentinel() ? 0 : -1;
this.lastDistance = null;
this.on('hit', this.next);
this.on('hit', () => {
if (!this.loadOnScroll) {
return;
}
this.next();
});
// initialize extensions
this.pagination = new Pagination(this, this.options.pagination);

@@ -55,3 +64,3 @@ this.spinner = new Spinner(this, this.options.spinner);

if (this.options.bind) {
// @todo on document.ready?
// @todo on document.ready? (window.addEventListener('DOMContentLoaded'))
this.bind();

@@ -101,2 +110,4 @@ }

.then((result) => {
this.pageIndex = event.pageIndex;
if (!result) {

@@ -108,3 +119,2 @@ this.emitter.emit('last');

this.pageIndex = event.pageIndex;
this.resume();

@@ -210,2 +220,10 @@ })

enableLoadOnScroll() {
this.loadOnScroll = true;
}
disableLoadOnScroll() {
this.loadOnScroll = false;
}
measure() {

@@ -224,5 +242,7 @@ if (this.paused) {

if (distance <= 0) {
if (distance <= 0 && (this.lastDistance === null || this.lastDistance > 0)) {
this.emitter.emit('hit', {distance});
}
this.lastDistance = distance;
}

@@ -229,0 +249,0 @@

@@ -53,5 +53,7 @@ import {getRootRect} from "./dimensions";

let loaded = (event) => {
// @todo event.xhr.response.title only works in case of responseType = "document"
url = event.url;
title = event.xhr.response.title
if (event.xhr.response) {
title = event.xhr.response.title
}
};

@@ -58,0 +60,0 @@

@@ -36,3 +36,5 @@ import $ from 'tealight';

Assert.singleElement(this.options.element, 'spinner.element');
if (this.options.element !== undefined) {
Assert.singleElement(this.options.element, 'spinner.element');
}

@@ -39,0 +41,0 @@ this.element = $(this.options.element)[0]; // @todo should we really cache this?

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