![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-full/dist/js/ |
Upload File : |
/*** module: node_modules/absol-mobile/js/dom/MHSnapScroller.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("../../css/mhsnapscroller.css"); var _Core = _interopRequireDefault(require("./Core")); var _AElement = _interopRequireDefault(require("absol/src/HTML5/AElement")); var _ = _Core.default._; var $ = _Core.default.$; /*** * @extends AElement * @constructor */ function MHSnapScroller() { this.addClass('am-h-snap-scroller'); //still fail on iOS, disable all // this.on('touchstart', this.eventHandler.touchstart); // this.on('touchend', this.eventHandler.touchend); // this.on('scroll', this.eventHandler.scroll); this._scroll = { speed: 0, lastEventTime: 0, homeGoing: false, release: true, homeX: 0, x: 0, scrollEnded: true }; } MHSnapScroller.tag = 'MHSnapScroller'.toLowerCase(); MHSnapScroller.render = function () { return _({}); }; MHSnapScroller.prototype._findHomeX = function () { var bound = this.getBoundingClientRect(); var centerX = (bound.left + bound.right) / 2; var eBounds = Array.prototype.map.call(this.childNodes, function (elt) { return elt.getBoundingClientRect(); }).filter(function (bound) { return bound.width > 0; }); var scrollLeft = this.scrollLeft; var nearestX = Infinity; var nextX = Infinity; var childCenterX; for (var i = 0; i < eBounds.length; ++i) { childCenterX = (eBounds[i].left + eBounds[i].right) / 2; if (Math.abs(childCenterX - centerX) < Math.abs(nearestX - centerX)) { nearestX = childCenterX; } if (childCenterX - centerX >= 0 == this._scroll.speed >= 0) { if (Math.abs(childCenterX - centerX) < Math.abs(nextX - centerX)) { nextX = childCenterX; } } } if (nearestX - centerX >= 0 != this._scroll.speed >= 0 && nextX != Infinity) { nearestX = nextX; } return Math.max(0, Math.min(this.scrollWidth - this.clientWidth, scrollLeft + (nearestX - centerX))); }; MHSnapScroller.prototype.startHomeGoing = function () { if (this._scroll.homeGoing || !this._scroll.release || !this._scroll.scrollEnded) return; var homeX = this._findHomeX(); this._scroll.homeX = homeX; this._scroll.homeGoing = true; if (this._scroll.speed < 50 && this._scroll.speed >= 0) { this._scroll.speed = 50; } else if (this._scroll.speed > -50 && this._scroll.speed < 0) { this._scroll.speed = -50; } this.eventHandler.homeGoingTick(); }; MHSnapScroller.prototype.stopHomeGoing = function () { if (!this._scroll.homeGoing) return; this._scroll.homeGoing = false; }; /*** * * @type {{}|MHSnapScroller} */ MHSnapScroller.eventHandler = {}; MHSnapScroller.eventHandler.homeGoingTick = function (toFinish) { if (!this._scroll.homeGoing) return; if (toFinish === true) { this.stopHomeGoing(); return; } var last = this._scroll.lastEventTime; var now = new Date().getTime(); var dt = (now - last) / 1000; var dx = dt * this._scroll.speed; var limitDx = this._scroll.homeX - this._scroll.x; var needContinue = false; if (Math.abs(dx) >= Math.abs(limitDx) || dx * limitDx <= 0) { this._scroll.x = this._scroll.homeX; } else { this._scroll.x += dx; needContinue = true; } this.scrollLeft = this._scroll.x; if (needContinue) requestAnimationFrame(this.eventHandler.homeGoingTick);else requestAnimationFrame(this.eventHandler.homeGoingTick.bind(this, true)); }; MHSnapScroller.eventHandler.stopScroll = function () { this._scroll.scrollEnded = true; this.startHomeGoing(); }; /*** * * @param {TouchEvent} event */ MHSnapScroller.eventHandler.touchstart = function (event) { this.stopHomeGoing(); this._scroll.release = false; }; /*** * * @param {TouchEvent} event */ MHSnapScroller.eventHandler.touchend = function (event) { if (event.touches.length === 0) { this._scroll.release = true; this.startHomeGoing(); } }; MHSnapScroller.eventHandler.scroll = function () { if (this._scroll.homeGoing) return; var last = this._scroll.lastEventTime; this._scroll.scrollEnded = false; var now = new Date().getTime(); if (now - last > 100) { this._scroll.speed = 0; this._scroll.lastEventTime = now; this._scroll.x = this.scrollLeft; } else if (now > last) { this._scroll.speed = (this.scrollLeft - this._scroll.x) * 1000 / (now - last); this._scroll.lastEventTime = now; this._scroll.x = this.scrollLeft; } if (this._scroll.stopTimeout > 0) { clearTimeout(this._scroll.stopTimeout); } this._scroll.stopTimeout = setTimeout(this.eventHandler.stopScroll, 30); }; var _default = MHSnapScroller; exports.default = _default;