UNPKG

este-library-oldschool

Version:

Library for github.com/steida/este.git

78 lines (70 loc) 2.09 kB
// Generated by github.com/steida/coffee2closure 900.1.18 /** @fileoverview Class to detect scrollable content reaching scroll end. Then 'load' event is dispatched. @see /demos/events/infinitescrollhandler.html */ var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.superClass_ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; goog.provide('este.events.InfiniteScrollHandler'); goog.require('este.Base'); /** @param {Element} element @param {Function} load @constructor @extends {este.Base} */ este.events.InfiniteScrollHandler = function(element, load) { this.element = element; this.load = load; este.events.InfiniteScrollHandler.superClass_.constructor.call(this); } extend(este.events.InfiniteScrollHandler, superClass); /** @enum {string} */ este.events.InfiniteScrollHandler.EventType = { LOAD: 'load' }; /** Threshold in px. @type {number} */ este.events.InfiniteScrollHandler.prototype.threshold = 0; /** @type {Element} @protected */ este.events.InfiniteScrollHandler.prototype.element = null; /** @type {Function} @protected */ este.events.InfiniteScrollHandler.prototype.load = null; /** @param {boolean} enable */ este.events.InfiniteScrollHandler.prototype.setEnabled = function(enable) { if (enable) { return this.on(this.element, 'scroll', this.onElementScroll); } else { return this.off(this.element, 'scroll', this.onElementScroll); } }; /** @param {goog.events.BrowserEvent} e @protected */ este.events.InfiniteScrollHandler.prototype.onElementScroll = function(e) { var shouldScroll; shouldScroll = this.element.scrollTop + this.element.offsetHeight >= this.element.scrollHeight - this.threshold; if (!shouldScroll) { return; } this.setEnabled(false); return this.load((function(_this) { return function() { return _this.setEnabled(true); }; })(this)); };