UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

108 lines (86 loc) 3.13 kB
"use strict"; var Callbacks = require("../../core/utils/callbacks"), NativeStrategy = require("./ui.scrollable.native"), Deferred = require("../../core/utils/deferred").Deferred; var STATE_RELEASED = 0, STATE_READY = 1, STATE_LOADING = 2, LOADING_HEIGHT = 80; var SlideDownNativeScrollViewStrategy = NativeStrategy.inherit({ _init: function _init(scrollView) { this.callBase(scrollView); this._$topPocket = scrollView._$topPocket; this._$bottomPocket = scrollView._$bottomPocket; this._initCallbacks(); }, _initCallbacks: function _initCallbacks() { this.pullDownCallbacks = Callbacks(); this.releaseCallbacks = Callbacks(); this.reachBottomCallbacks = Callbacks(); }, render: function render() { this.callBase(); this._renderPullDown(); this._renderBottom(); this._releaseState(); this._updateDimensions(); }, _renderPullDown: function _renderPullDown() { this._$topPocket.empty(); }, _renderBottom: function _renderBottom() { this._$bottomPocket.empty().append("<progress>"); }, _releaseState: function _releaseState() { if (this._state === STATE_RELEASED) { return; } this._state = STATE_RELEASED; }, _updateDimensions: function _updateDimensions() { this._scrollOffset = this._$container.prop("scrollHeight") - this._$container.prop("clientHeight"); this._containerSize = { height: this._$container.prop("clientHeight"), width: this._$container.prop("clientWidth") }; this._contentSize = this._componentContentSize = { height: this._$container.prop("scrollHeight"), width: this._$container.prop("scrollWidth") }; }, handleScroll: function handleScroll(e) { this.callBase(e); if (this._isReachBottom(this._lastLocation.top)) { this._reachBottom(); } }, _isReachBottom: function _isReachBottom(location) { this._scrollContent = this._$container.prop("scrollHeight") - this._$container.prop("clientHeight"); return this._reachBottomEnabled && location < -this._scrollContent + LOADING_HEIGHT; }, _reachBottom: function _reachBottom() { if (this._state === STATE_LOADING) { return; } this._state = STATE_LOADING; this.reachBottomCallbacks.fire(); }, pullDownEnable: function pullDownEnable(enabled) { this._pullDownEnabled = enabled; }, reachBottomEnable: function reachBottomEnable(enabled) { this._reachBottomEnabled = enabled; this._$bottomPocket.toggle(enabled); }, pendingRelease: function pendingRelease() { this._state = STATE_READY; }, release: function release() { var deferred = new Deferred(); this._state = STATE_RELEASED; this.releaseCallbacks.fire(); this.update(); return deferred.resolve().promise(); } }); module.exports = SlideDownNativeScrollViewStrategy;