Comparing version 2.1.0 to 2.1.1
@@ -1,260 +0,2 @@ | ||
/** | ||
* @class `Viewport` | ||
* A a scrollable container containing multiple observers | ||
* that are checked each time the viewport is manipulated (scrolled, resized, mutated) | ||
*/ | ||
function Viewport(container) { | ||
var _this = this; | ||
this.container = container; | ||
this.observers = []; | ||
this.lastY = 0; | ||
var element = this.element = container === document.body ? window : container; | ||
var scheduled = false; | ||
var throttle = window.requestAnimationFrame || function (callback) { | ||
return setTimeout(callback, 1000 / 60); | ||
}; | ||
var handler = this.handler = function () { | ||
if (!scheduled) { | ||
scheduled = true; | ||
throttle(function () { | ||
var state = _this.getState(); | ||
_this.checkObservers(state); | ||
_this.lastY = state.y; | ||
scheduled = false; | ||
}); | ||
} | ||
}; | ||
element.addEventListener('scroll', handler); | ||
element.addEventListener('resize', handler); | ||
if (window.MutationObserver) { | ||
addEventListener('DOMContentLoaded', function () { | ||
var mutationObserver = _this.mutationObserver = new MutationObserver(handler); | ||
mutationObserver.observe(container, { attributes: true, childList: true, subtree: true }); | ||
}); | ||
} | ||
} | ||
Viewport.prototype = { | ||
addObserver: function addObserver(observer) { | ||
var observers = this.observers; | ||
observers.indexOf(observer) === -1 && observers.push(observer); | ||
}, | ||
removeObserver: function removeObserver(observer) { | ||
var observers = this.observers; | ||
var index = observers.indexOf(observer); | ||
index > -1 && observers.splice(index, 1); | ||
}, | ||
checkObservers: function checkObservers(state) { | ||
var observers = this.observers; | ||
for (var i = observers.length; i--;) { | ||
observers[i].check(state); | ||
} | ||
}, | ||
getState: function getState() { | ||
var element = this.element, | ||
lastY = this.lastY; | ||
var width = void 0, | ||
height = void 0, | ||
y = void 0; | ||
if (element === window) { | ||
width = element.innerWidth; | ||
height = element.innerHeight; | ||
y = element.pageYOffset; | ||
} else { | ||
width = element.offsetWidth; | ||
height = element.offsetHeight; | ||
y = element.scrollTop; | ||
} | ||
var yDirection = lastY < y ? 'down' : 'up'; | ||
return { width: width, height: height, y: y, yDirection: yDirection }; | ||
}, | ||
destroy: function destroy() { | ||
var element = this.element, | ||
handler = this.handler, | ||
mutationObserver = this.mutationObserver; | ||
element.removeEventListener('scroll', handler); | ||
element.removeEventListener('resize', handler); | ||
mutationObserver && mutationObserver.disconnect(); | ||
} | ||
}; | ||
/** | ||
* When adding a new observer, the manager checks if the viewport | ||
* already exists so they share common event listeners. | ||
*/ | ||
var viewports = []; | ||
function addViewportObserver(observer) { | ||
var container = observer.container; | ||
var index = getViewportIndexForContainer(container); | ||
var viewport = void 0; | ||
if (index > -1) { | ||
viewport = viewports[index]; | ||
} else { | ||
viewport = new Viewport(container); | ||
viewports.push(viewport); | ||
} | ||
viewport.addObserver(observer); | ||
return viewport; | ||
} | ||
function removeViewportObserver(observer) { | ||
var index = getViewportIndexForContainer(observer.container); | ||
var viewport = viewports[index]; | ||
if (viewport) { | ||
viewport.removeObserver(observer); | ||
if (!viewport.observers.length) { | ||
viewport.destroy(); | ||
viewports.splice(index, 1); | ||
} | ||
} | ||
} | ||
function getViewportIndexForContainer(container) { | ||
for (var i = viewports.length; i--;) { | ||
if (viewports[i].container === container) { | ||
return i; | ||
} | ||
} | ||
} | ||
/** | ||
* @interface Observer | ||
* Each type of observer implements these options/methods | ||
*/ | ||
function Observer(opts) { | ||
this.offset = ~~opts.offset || 0; | ||
this.container = opts.container || document.body; | ||
this.once = Boolean(opts.once); | ||
return this.activate(); | ||
} | ||
Observer.prototype = { | ||
activate: function activate() { | ||
return addViewportObserver(this); | ||
}, | ||
destroy: function destroy() { | ||
removeViewportObserver(this); | ||
} | ||
}; | ||
function ObserverInterface(Subclass) { | ||
Subclass.prototype = Object.create(Observer.prototype); | ||
Subclass.prototype.constructor = Subclass; | ||
return Subclass; | ||
} | ||
var PositionObserver = ObserverInterface(function PositionObserver() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
if (!(this instanceof PositionObserver)) { | ||
return new (Function.prototype.bind.apply(PositionObserver, [null].concat(Array.prototype.slice.call(arguments))))(); | ||
} | ||
this.onTop = opts.onTop; | ||
this.onBottom = opts.onBottom; | ||
this.onMaximized = opts.onMaximized; | ||
this._wasTop = true; | ||
this._wasBottom = false; | ||
var viewport = Observer.call(this, opts); | ||
this.check(viewport.getState()); | ||
}); | ||
PositionObserver.prototype.check = function (viewportState) { | ||
var onBottom = this.onBottom, | ||
onTop = this.onTop, | ||
onMaximized = this.onMaximized, | ||
_wasTop = this._wasTop, | ||
_wasBottom = this._wasBottom, | ||
container = this.container, | ||
offset = this.offset, | ||
once = this.once; | ||
var scrollHeight = container.scrollHeight; | ||
var height = viewportState.height, | ||
y = viewportState.y; | ||
var atTop = y - offset <= 0; | ||
var atBottom = scrollHeight > height && height + y + offset >= scrollHeight; | ||
var untriggered = false; | ||
if (onBottom && !_wasBottom && atBottom) { | ||
onBottom.call(this, container, viewportState); | ||
} else if (onTop && !_wasTop && atTop) { | ||
onTop.call(this, container, viewportState); | ||
} else if (onMaximized && scrollHeight === height) { | ||
onMaximized.call(this, container, viewportState); | ||
} else { | ||
untriggered = true; | ||
} | ||
if (once && !untriggered) { | ||
this.destroy(); | ||
} | ||
this._wasTop = atTop; | ||
this._wasBottom = atBottom; | ||
}; | ||
function isElementInViewport(element, offset, viewportState) { | ||
var rect = element.getBoundingClientRect(); | ||
return !!(rect.width && rect.height) && rect.top < viewportState.height + offset && rect.bottom > 0 - offset && rect.left < viewportState.width + offset && rect.right > 0 - offset; | ||
} | ||
function isElementInDOM(element) { | ||
return element && element.parentNode; | ||
} | ||
var ElementObserver = ObserverInterface(function ElementObserver(element) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!(this instanceof ElementObserver)) { | ||
return new (Function.prototype.bind.apply(ElementObserver, [null].concat(Array.prototype.slice.call(arguments))))(); | ||
} | ||
this.element = element; | ||
this.onEnter = opts.onEnter; | ||
this.onExit = opts.onExit; | ||
this._didEnter = false; | ||
var viewport = Observer.call(this, opts); | ||
if (isElementInDOM(element)) { | ||
this.check(viewport.getState()); | ||
} | ||
}); | ||
ElementObserver.prototype.check = function (viewportState) { | ||
var onEnter = this.onEnter, | ||
onExit = this.onExit, | ||
element = this.element, | ||
offset = this.offset, | ||
once = this.once, | ||
_didEnter = this._didEnter; | ||
if (!isElementInDOM(element)) { | ||
this.destroy(); | ||
} else if (onEnter && !_didEnter && isElementInViewport(element, offset, viewportState)) { | ||
this._didEnter = true; | ||
onEnter.call(this, element, viewportState); | ||
once && this.destroy(); | ||
} else if (onExit && _didEnter && !isElementInViewport(element, offset, viewportState)) { | ||
this._didEnter = false; | ||
onExit.call(this, element, viewportState); | ||
once && this.destroy(); | ||
} | ||
}; | ||
export { PositionObserver, ElementObserver }; | ||
function t(t){var e=this;this.container=t,this.observers=[],this.lastY=0;var n=this.element=t===document.body?window:t,i=!1,o=window.requestAnimationFrame||function(t){return setTimeout(t,1e3/60)},r=this.handler=function(){i||(i=!0,o(function(){var t=e.getState();e.checkObservers(t),e.lastY=t.y,i=!1}))};n.addEventListener("scroll",r),n.addEventListener("resize",r),window.MutationObserver&&addEventListener("DOMContentLoaded",function(){(e.mutationObserver=new MutationObserver(r)).observe(t,{attributes:!0,childList:!0,subtree:!0})})}t.prototype={addObserver:function(t){var e=this.observers;-1===e.indexOf(t)&&e.push(t)},removeObserver:function(t){var e=this.observers,n=e.indexOf(t);n>-1&&e.splice(n,1)},checkObservers:function(t){for(var e=this.observers,n=e.length;n--;)e[n].check(t)},getState:function(){var t,e,n,i=this.element;return i===window?(t=i.innerWidth,e=i.innerHeight,n=i.pageYOffset):(t=i.offsetWidth,e=i.offsetHeight,n=i.scrollTop),{width:t,height:e,y:n,yDirection:this.lastY<n?"down":"up"}},destroy:function(){var t=this.element,e=this.handler,n=this.mutationObserver;t.removeEventListener("scroll",e),t.removeEventListener("resize",e),n&&n.disconnect()}};var e=[];function n(t){for(var n=e.length;n--;)if(e[n].container===t)return n}function i(t){return this.offset=~~t.offset||0,this.container=t.container||document.body,this.once=Boolean(t.once),this.activate()}function o(t){return t.prototype=Object.create(i.prototype),t.prototype.constructor=t,t}i.prototype={activate:function(){return(s=n(r=(i=this).container))>-1?o=e[s]:(o=new t(r),e.push(o)),o.addObserver(i),o;var i,o,r,s},destroy:function(){var t,i,o;i=n((t=this).container),(o=e[i])&&(o.removeObserver(t),o.observers.length||(o.destroy(),e.splice(i,1)))}};var r=o(function t(e){for(var n=arguments.length,o=Array(n);n--;)o[n]=arguments[n];if(void 0===e&&(e={}),!(this instanceof t))return new(Function.prototype.bind.apply(t,[null].concat(o)));this.onTop=e.onTop,this.onBottom=e.onBottom,this.onMaximized=e.onMaximized,this._wasTop=!0,this._wasBottom=!1;var r=i.call(this,e);this.check(r.getState())});function s(t){return t&&t.parentNode}r.prototype.check=function(t){var e=this.onBottom,n=this.onTop,i=this.onMaximized,o=this._wasTop,r=this.container,s=this.offset,h=this.once,a=r.scrollHeight,c=t.height,d=t.y,u=d-s<=0,v=a>c&&c+d+s>=a,l=!1;e&&!this._wasBottom&&v?e.call(this,r,t):n&&!o&&u?n.call(this,r,t):i&&a===c?i.call(this,r,t):l=!0,h&&!l&&this.destroy(),this._wasTop=u,this._wasBottom=v};var h=o(function t(e,n){for(var o=arguments.length,r=Array(o);o--;)r[o]=arguments[o];if(void 0===n&&(n={}),!(this instanceof t))return new(Function.prototype.bind.apply(t,[null].concat(r)));this.element=e,this.onEnter=n.onEnter,this.onExit=n.onExit,this._didEnter=!1;var h=i.call(this,n);s(e)&&this.check(h.getState())});h.prototype.check=function(t){var e=this.onEnter,n=this.onExit,i=this.element,o=this.offset,r=this.once,h=this._didEnter;if(!s(i))return this.destroy();var a=function(t,e,n){var i=t.getBoundingClientRect();return!(!i.width||!i.height)&&i.top<n.height+e&&i.bottom>0-e&&i.left<n.width+e&&i.right>0-e}(i,o,t);!h&&a?(this._didEnter=!0,e&&(e.call(this,i,t),r&&this.destroy())):h&&!a&&(this._didEnter=!1,n&&(n.call(this,i,t),r&&this.destroy()))};export{r as PositionObserver,h as ElementObserver}; | ||
//# sourceMappingURL=viewprt.es.js.map |
@@ -1,271 +0,2 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.Viewprt = global.Viewprt || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
/** | ||
* @class `Viewport` | ||
* A a scrollable container containing multiple observers | ||
* that are checked each time the viewport is manipulated (scrolled, resized, mutated) | ||
*/ | ||
function Viewport(container) { | ||
var _this = this; | ||
this.container = container; | ||
this.observers = []; | ||
this.lastY = 0; | ||
var element = this.element = container === document.body ? window : container; | ||
var scheduled = false; | ||
var throttle = window.requestAnimationFrame || function (callback) { | ||
return setTimeout(callback, 1000 / 60); | ||
}; | ||
var handler = this.handler = function () { | ||
if (!scheduled) { | ||
scheduled = true; | ||
throttle(function () { | ||
var state = _this.getState(); | ||
_this.checkObservers(state); | ||
_this.lastY = state.y; | ||
scheduled = false; | ||
}); | ||
} | ||
}; | ||
element.addEventListener('scroll', handler); | ||
element.addEventListener('resize', handler); | ||
if (window.MutationObserver) { | ||
addEventListener('DOMContentLoaded', function () { | ||
var mutationObserver = _this.mutationObserver = new MutationObserver(handler); | ||
mutationObserver.observe(container, { attributes: true, childList: true, subtree: true }); | ||
}); | ||
} | ||
} | ||
Viewport.prototype = { | ||
addObserver: function addObserver(observer) { | ||
var observers = this.observers; | ||
observers.indexOf(observer) === -1 && observers.push(observer); | ||
}, | ||
removeObserver: function removeObserver(observer) { | ||
var observers = this.observers; | ||
var index = observers.indexOf(observer); | ||
index > -1 && observers.splice(index, 1); | ||
}, | ||
checkObservers: function checkObservers(state) { | ||
var observers = this.observers; | ||
for (var i = observers.length; i--;) { | ||
observers[i].check(state); | ||
} | ||
}, | ||
getState: function getState() { | ||
var element = this.element, | ||
lastY = this.lastY; | ||
var width = void 0, | ||
height = void 0, | ||
y = void 0; | ||
if (element === window) { | ||
width = element.innerWidth; | ||
height = element.innerHeight; | ||
y = element.pageYOffset; | ||
} else { | ||
width = element.offsetWidth; | ||
height = element.offsetHeight; | ||
y = element.scrollTop; | ||
} | ||
var yDirection = lastY < y ? 'down' : 'up'; | ||
return { width: width, height: height, y: y, yDirection: yDirection }; | ||
}, | ||
destroy: function destroy() { | ||
var element = this.element, | ||
handler = this.handler, | ||
mutationObserver = this.mutationObserver; | ||
element.removeEventListener('scroll', handler); | ||
element.removeEventListener('resize', handler); | ||
mutationObserver && mutationObserver.disconnect(); | ||
} | ||
}; | ||
/** | ||
* When adding a new observer, the manager checks if the viewport | ||
* already exists so they share common event listeners. | ||
*/ | ||
var viewports = []; | ||
function addViewportObserver(observer) { | ||
var container = observer.container; | ||
var index = getViewportIndexForContainer(container); | ||
var viewport = void 0; | ||
if (index > -1) { | ||
viewport = viewports[index]; | ||
} else { | ||
viewport = new Viewport(container); | ||
viewports.push(viewport); | ||
} | ||
viewport.addObserver(observer); | ||
return viewport; | ||
} | ||
function removeViewportObserver(observer) { | ||
var index = getViewportIndexForContainer(observer.container); | ||
var viewport = viewports[index]; | ||
if (viewport) { | ||
viewport.removeObserver(observer); | ||
if (!viewport.observers.length) { | ||
viewport.destroy(); | ||
viewports.splice(index, 1); | ||
} | ||
} | ||
} | ||
function getViewportIndexForContainer(container) { | ||
for (var i = viewports.length; i--;) { | ||
if (viewports[i].container === container) { | ||
return i; | ||
} | ||
} | ||
} | ||
/** | ||
* @interface Observer | ||
* Each type of observer implements these options/methods | ||
*/ | ||
function Observer(opts) { | ||
this.offset = ~~opts.offset || 0; | ||
this.container = opts.container || document.body; | ||
this.once = Boolean(opts.once); | ||
return this.activate(); | ||
} | ||
Observer.prototype = { | ||
activate: function activate() { | ||
return addViewportObserver(this); | ||
}, | ||
destroy: function destroy() { | ||
removeViewportObserver(this); | ||
} | ||
}; | ||
function ObserverInterface(Subclass) { | ||
Subclass.prototype = Object.create(Observer.prototype); | ||
Subclass.prototype.constructor = Subclass; | ||
return Subclass; | ||
} | ||
var PositionObserver = ObserverInterface(function PositionObserver() { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
if (!(this instanceof PositionObserver)) { | ||
return new (Function.prototype.bind.apply(PositionObserver, [null].concat(Array.prototype.slice.call(arguments))))(); | ||
} | ||
this.onTop = opts.onTop; | ||
this.onBottom = opts.onBottom; | ||
this.onMaximized = opts.onMaximized; | ||
this._wasTop = true; | ||
this._wasBottom = false; | ||
var viewport = Observer.call(this, opts); | ||
this.check(viewport.getState()); | ||
}); | ||
PositionObserver.prototype.check = function (viewportState) { | ||
var onBottom = this.onBottom, | ||
onTop = this.onTop, | ||
onMaximized = this.onMaximized, | ||
_wasTop = this._wasTop, | ||
_wasBottom = this._wasBottom, | ||
container = this.container, | ||
offset = this.offset, | ||
once = this.once; | ||
var scrollHeight = container.scrollHeight; | ||
var height = viewportState.height, | ||
y = viewportState.y; | ||
var atTop = y - offset <= 0; | ||
var atBottom = scrollHeight > height && height + y + offset >= scrollHeight; | ||
var untriggered = false; | ||
if (onBottom && !_wasBottom && atBottom) { | ||
onBottom.call(this, container, viewportState); | ||
} else if (onTop && !_wasTop && atTop) { | ||
onTop.call(this, container, viewportState); | ||
} else if (onMaximized && scrollHeight === height) { | ||
onMaximized.call(this, container, viewportState); | ||
} else { | ||
untriggered = true; | ||
} | ||
if (once && !untriggered) { | ||
this.destroy(); | ||
} | ||
this._wasTop = atTop; | ||
this._wasBottom = atBottom; | ||
}; | ||
function isElementInViewport(element, offset, viewportState) { | ||
var rect = element.getBoundingClientRect(); | ||
return !!(rect.width && rect.height) && rect.top < viewportState.height + offset && rect.bottom > 0 - offset && rect.left < viewportState.width + offset && rect.right > 0 - offset; | ||
} | ||
function isElementInDOM(element) { | ||
return element && element.parentNode; | ||
} | ||
var ElementObserver = ObserverInterface(function ElementObserver(element) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (!(this instanceof ElementObserver)) { | ||
return new (Function.prototype.bind.apply(ElementObserver, [null].concat(Array.prototype.slice.call(arguments))))(); | ||
} | ||
this.element = element; | ||
this.onEnter = opts.onEnter; | ||
this.onExit = opts.onExit; | ||
this._didEnter = false; | ||
var viewport = Observer.call(this, opts); | ||
if (isElementInDOM(element)) { | ||
this.check(viewport.getState()); | ||
} | ||
}); | ||
ElementObserver.prototype.check = function (viewportState) { | ||
var onEnter = this.onEnter, | ||
onExit = this.onExit, | ||
element = this.element, | ||
offset = this.offset, | ||
once = this.once, | ||
_didEnter = this._didEnter; | ||
if (!isElementInDOM(element)) { | ||
this.destroy(); | ||
} else if (onEnter && !_didEnter && isElementInViewport(element, offset, viewportState)) { | ||
this._didEnter = true; | ||
onEnter.call(this, element, viewportState); | ||
once && this.destroy(); | ||
} else if (onExit && _didEnter && !isElementInViewport(element, offset, viewportState)) { | ||
this._didEnter = false; | ||
onExit.call(this, element, viewportState); | ||
once && this.destroy(); | ||
} | ||
}; | ||
exports.PositionObserver = PositionObserver; | ||
exports.ElementObserver = ElementObserver; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
function t(t){var e=this;this.container=t,this.observers=[],this.lastY=0;var n=this.element=t===document.body?window:t,i=!1,o=window.requestAnimationFrame||function(t){return setTimeout(t,1e3/60)},r=this.handler=function(){i||(i=!0,o(function(){var t=e.getState();e.checkObservers(t),e.lastY=t.y,i=!1}))};n.addEventListener("scroll",r),n.addEventListener("resize",r),window.MutationObserver&&addEventListener("DOMContentLoaded",function(){(e.mutationObserver=new MutationObserver(r)).observe(t,{attributes:!0,childList:!0,subtree:!0})})}t.prototype={addObserver:function(t){var e=this.observers;-1===e.indexOf(t)&&e.push(t)},removeObserver:function(t){var e=this.observers,n=e.indexOf(t);n>-1&&e.splice(n,1)},checkObservers:function(t){for(var e=this.observers,n=e.length;n--;)e[n].check(t)},getState:function(){var t,e,n,i=this.element;return i===window?(t=i.innerWidth,e=i.innerHeight,n=i.pageYOffset):(t=i.offsetWidth,e=i.offsetHeight,n=i.scrollTop),{width:t,height:e,y:n,yDirection:this.lastY<n?"down":"up"}},destroy:function(){var t=this.element,e=this.handler,n=this.mutationObserver;t.removeEventListener("scroll",e),t.removeEventListener("resize",e),n&&n.disconnect()}};var e=[];function n(t){for(var n=e.length;n--;)if(e[n].container===t)return n}function i(t){return this.offset=~~t.offset||0,this.container=t.container||document.body,this.once=Boolean(t.once),this.activate()}function o(t){return t.prototype=Object.create(i.prototype),t.prototype.constructor=t,t}i.prototype={activate:function(){return(s=n(r=(i=this).container))>-1?o=e[s]:(o=new t(r),e.push(o)),o.addObserver(i),o;var i,o,r,s},destroy:function(){var t,i,o;i=n((t=this).container),(o=e[i])&&(o.removeObserver(t),o.observers.length||(o.destroy(),e.splice(i,1)))}};var r=o(function t(e){for(var n=arguments.length,o=Array(n);n--;)o[n]=arguments[n];if(void 0===e&&(e={}),!(this instanceof t))return new(Function.prototype.bind.apply(t,[null].concat(o)));this.onTop=e.onTop,this.onBottom=e.onBottom,this.onMaximized=e.onMaximized,this._wasTop=!0,this._wasBottom=!1;var r=i.call(this,e);this.check(r.getState())});function s(t){return t&&t.parentNode}r.prototype.check=function(t){var e=this.onBottom,n=this.onTop,i=this.onMaximized,o=this._wasTop,r=this.container,s=this.offset,h=this.once,a=r.scrollHeight,c=t.height,d=t.y,v=d-s<=0,u=a>c&&c+d+s>=a,l=!1;e&&!this._wasBottom&&u?e.call(this,r,t):n&&!o&&v?n.call(this,r,t):i&&a===c?i.call(this,r,t):l=!0,h&&!l&&this.destroy(),this._wasTop=v,this._wasBottom=u};var h=o(function t(e,n){for(var o=arguments.length,r=Array(o);o--;)r[o]=arguments[o];if(void 0===n&&(n={}),!(this instanceof t))return new(Function.prototype.bind.apply(t,[null].concat(r)));this.element=e,this.onEnter=n.onEnter,this.onExit=n.onExit,this._didEnter=!1;var h=i.call(this,n);s(e)&&this.check(h.getState())});h.prototype.check=function(t){var e=this.onEnter,n=this.onExit,i=this.element,o=this.offset,r=this.once,h=this._didEnter;if(!s(i))return this.destroy();var a=function(t,e,n){var i=t.getBoundingClientRect();return!(!i.width||!i.height)&&i.top<n.height+e&&i.bottom>0-e&&i.left<n.width+e&&i.right>0-e}(i,o,t);!h&&a?(this._didEnter=!0,e&&(e.call(this,i,t),r&&this.destroy())):h&&!a&&(this._didEnter=!1,n&&(n.call(this,i,t),r&&this.destroy()))},exports.PositionObserver=r,exports.ElementObserver=h; | ||
//# sourceMappingURL=viewprt.js.map |
{ | ||
"name": "viewprt", | ||
"version": "2.1.0", | ||
"description": "tiny, high performance viewport position & intersection observer", | ||
"version": "2.1.1", | ||
"description": "Tiny, high performance viewport position & intersection observer", | ||
"author": "Garth Poitras <garth22@gmail.com>", | ||
"license": "MIT", | ||
"source": "src/index.js", | ||
"main": "dist/viewprt.js", | ||
"module": "dist/viewprt.es.js", | ||
"jsnext:main": "dist/viewprt.es.js", | ||
"browser": "dist/viewprt.umd.js", | ||
"files": [ | ||
"dist/viewprt.js", | ||
"dist/viewprt.es.js" | ||
"dist" | ||
], | ||
@@ -28,8 +28,10 @@ "keywords": [ | ||
"scripts": { | ||
"dev": "rollup --config --watch", | ||
"build": "rollup --config", | ||
"lint": "eslint src test --fix", | ||
"test:js": "yarn build && mocha --require test/helpers/env.js", | ||
"test": "yarn lint && yarn test:js", | ||
"prepublish": "yarn build", | ||
"build": "microbundle", | ||
"build-dev": "microbundle --compress false", | ||
"dev": "microbundle watch", | ||
"test": "npm run clean && npm run format && npm run lint && npm run build-dev && npm run test:js", | ||
"format": "flt format", | ||
"lint": "flt lint", | ||
"test:js": "flt test **/*.test.js --require test/helpers/env.js", | ||
"prepublish": "npm run build", | ||
"clean": "rm -rf dist", | ||
@@ -39,23 +41,7 @@ "demo": "open demos/index.html" | ||
"devDependencies": { | ||
"babel-preset-es2015": "^6.24.1", | ||
"eslint": "^3.19.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-node": "^4.2.2", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"jsdom": "^10.1.0", | ||
"mocha": "^3.4.1", | ||
"rewire": "^2.5.2", | ||
"rollup": "^0.41.6", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-watch": "^3.2.2" | ||
}, | ||
"eslintConfig": { | ||
"extends": "standard", | ||
"env": { | ||
"browser": true, | ||
"mocha": true | ||
} | ||
"flt": "^0.2.2", | ||
"jsdom": "^11.6.1", | ||
"microbundle": "^0.4.3", | ||
"rewire": "^3.0.2" | ||
} | ||
} |
# viewprt [![Build Status](https://travis-ci.org/gpoitch/viewprt.svg)](https://travis-ci.org/gpoitch/viewprt) | ||
A tiny, high performance viewport position & intersection observation tool. You can watch when elements enter & exit the viewport, or when the viewport itself is at the bottom or top. Use this as a building block for things such as lazy loaders, infinite scrollers, etc. | ||
A tiny, high performance viewport position & intersection observation tool. You can watch when elements enter & exit the viewport, or when the viewport itself is at the bottom or top. Use this as a building block for things such as lazy loaders, infinite scrollers, etc. | ||
#### [Demo](https://rawgit.com/gpoitch/viewprt/master/demos/index.html) | ||
#### [Demo](https://rawgit.com/gpoitch/viewprt/master/demos/index.html) | ||
#### [Dist](https://unpkg.com/viewprt/dist/) | ||
### Install | ||
```bash | ||
yarn add viewprt | ||
npm i viewprt | ||
``` | ||
### API | ||
Create new observers and any time its container is scrolled, resized, or mutated, the appropriate callbacks will be triggered when the condition is met. | ||
@@ -24,7 +27,7 @@ | ||
// options (defaults) | ||
container: document.body, // the viewport container element | ||
offset: 0, // offset from the edge of the viewport in pixels | ||
once: false, // if true, observer is detroyed after first callback is triggered | ||
onEnter (element, viewportState) {}, // callback when the element enters the viewport | ||
onExit (element, viewportState) {} // callback when the element exits the viewport | ||
container: document.body, // the viewport container element | ||
offset: 0, // offset from the edge of the viewport in pixels | ||
once: false, // if true, observer is detroyed after first callback is triggered | ||
onEnter(element, viewportState) {}, // callback when the element enters the viewport | ||
onExit(element, viewportState) {} // callback when the element exits the viewport | ||
}) | ||
@@ -35,8 +38,8 @@ | ||
// options (defaults) | ||
container: document.body, // the viewport container element | ||
offset: 0, // offset from the edge of the viewport in pixels | ||
once: false, // if true, observer is detroyed after first callback is triggered | ||
onBottom (container, viewportState) {}, // callback when the viewport reaches the bottom | ||
onTop (container, viewportState) {}, // callback when the viewport reaches the top | ||
onMaximized (container, viewportState) {} // callback when the viewport and container are the same size | ||
container: document.body, // the viewport container element | ||
offset: 0, // offset from the edge of the viewport in pixels | ||
once: false, // if true, observer is detroyed after first callback is triggered | ||
onBottom(container, viewportState) {}, // callback when the viewport reaches the bottom | ||
onTop(container, viewportState) {}, // callback when the viewport reaches the top | ||
onMaximized(container, viewportState) {} // callback when the viewport and container are the same size | ||
}) | ||
@@ -54,9 +57,11 @@ | ||
## Build | ||
```bash | ||
yarn build | ||
npm run build | ||
``` | ||
## Test | ||
```bash | ||
yarn test | ||
npm test | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
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
49251
4
8
65
43
1