![]() 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-tutor/js/scriptor/UserScrollIfNeed.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _BaseCommand = _interopRequireDefault(require("./BaseCommand")); var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP")); var _Dom = _interopRequireWildcard(require("absol/src/HTML5/Dom")); var _TACData = _interopRequireDefault(require("./TACData")); var _TutorNameManager = _interopRequireDefault(require("./TutorNameManager")); var _Core = require("../dom/Core"); var _Icon = require("../dom/Icon"); var _Tooltip = _interopRequireDefault(require("absol-acomp/js/Tooltip")); var _TCommand = require("../engine/TCommand"); var _TutorEngine = _interopRequireDefault(require("./TutorEngine")); var _UserBaseAction = _interopRequireDefault(require("./UserBaseAction")); var _BaseState = _interopRequireDefault(require("./BaseState")); /*** * @extends BaseState * @constructor */ function StateBeforeScroll() { _BaseState.default.apply(this, arguments); } _OOP.default.mixClass(StateBeforeScroll, _BaseState.default); StateBeforeScroll.prototype.onStart = function () { this.command.scrollerElt = this.command.findVScroller(this.command.elt); if (!this.command.scrollerElt) { this.goto('finish'); return; } this.scrollDir = this.command.findScrollDir(this.command.elt, this.command.scrollerElt); if (this.scrollDir.dy === 0) { this.goto('finish'); return; } this.command.highlightElt(this.command.elt); this.goto('begin_scrolling'); }; /*** * @extends BaseState * @constructor */ function StateBeginScrolling() { _BaseState.default.apply(this, arguments); this.checkIdx = -1; this.pointerLock = false; this.currentDir = 0; } _OOP.default.mixClass(StateBeginScrolling, _BaseState.default); StateBeginScrolling.prototype.onStart = function () { this.command.scrollerElt.addEventListener('scroll', this.ev_scroll); document.addEventListener('scroll', this.ev_scroll); this.command.scrollerElt.classList.add('atr-scroll-only'); document.body.addEventListener('pointerdown', this.ev_pointerDown); document.body.addEventListener('touchstart', this.ev_pointerDown); document.body.addEventListener('pointerup', this.ev_pointerUp); document.body.addEventListener('pointercancel', this.ev_pointerUp); document.body.addEventListener('touchend', this.ev_pointerUp); this.scrollDir = this.command.findScrollDir(this.command.elt, this.command.scrollerElt); this.prevScrollTop = this.command.scrollerElt.scrollTop; this.command._showScroll(this.command.scrollerElt, this.scrollDir); this.command.onlyClickTo(this.command.scrollerElt); }; StateBeginScrolling.prototype.onStop = function () { this.command.scrollerElt.removeEventListener('scroll', this.ev_scroll); document.removeEventListener('scroll', this.ev_scroll); this.command.scrollerElt.classList.remove('atr-scroll-only'); if (this.checkIdx > 0) clearTimeout(this.checkIdx); document.body.removeEventListener('pointerdown', this.ev_pointerDown); document.body.removeEventListener('touchstart', this.ev_pointerDown); document.body.removeEventListener('pointerup', this.ev_pointerUp); document.body.removeEventListener('pointercancel', this.ev_pointerUp); document.body.removeEventListener('touchend', this.ev_pointerUp); }; StateBeginScrolling.prototype.delayCheck = function () { if (this.checkIdx > 0) { clearTimeout(this.checkIdx); } var thisC = this.command; var vScroller = this.command.scrollerElt; this.checkIdx = setTimeout(function () { this.checkIdx = -1; var currentDir = thisC.findScrollDir(this.command.elt, vScroller); this.currentDir = currentDir; var pointerLock = this.pointerLock; if (currentDir.dy === 0 || !vScroller) { thisC._showScrollTooltip(null); thisC._prevTootipDir.dy = 0; if (!pointerLock) { this.goto('finish'); } } else { thisC._showScroll(vScroller, currentDir); if (thisC._prevTootipDir.dy !== currentDir.dy) { thisC._showScrollTooltip(vScroller, currentDir.dy > 0 ? this.command.args.scrollUpMessage : this.command.args.scrollDownMessage, currentDir); } thisC._prevTootipDir.dy = currentDir.dy; } }.bind(this), 100); }; StateBeginScrolling.prototype.ev_scroll = function (event) { this.command._updateToastPosition(); this.currentDir = this.command.findScrollDir(this.command.elt, this.command.scrollerElt); var vScroller = this.command.scrollerElt; if (vScroller.scrollTop > this.prevScrollTop) { if (this.currentDir.dy > 0) { this.command.hadWrongAction = true; } } else if (vScroller.scrollTop < this.prevScrollTop) { if (this.currentDir.dy < 0) { this.command.hadWrongAction = true; } } this.prevScrollTop = this.command.scrollerElt.scrollTop; this.delayCheck(); }; StateBeginScrolling.prototype.ev_pointerUp = function () { this.pointerLock = true; }; StateBeginScrolling.prototype.ev_pointerDown = function () { this.pointerLock = false; }; /*** * @extends BaseState * @constructor */ function StateShowMessage() { _BaseState.default.apply(this, arguments); } _OOP.default.mixClass(StateShowMessage, _BaseState.default); StateShowMessage.prototype.onStart = function () { this.currentDir = this.command.findScrollDir(this.command.elt, this.command.scrollerElt); if (this.currentDir.dy === 0) { this.goto('finish'); } else { this.command.showDelayToast(this.args.message).then(function () { this.goto('user_begin'); }.bind(this)); } }; /*** * @extends BaseCommand * @constructor */ function UserScrollIfNeed() { _BaseCommand.default.apply(this, arguments); this._prevTootipDir = { dy: 0, dx: 0 }; } (0, _TCommand.inheritCommand)(UserScrollIfNeed, _UserBaseAction.default); UserScrollIfNeed.prototype.name = 'userScrollIfNeed'; UserScrollIfNeed.prototype.argNames = ['eltPath', 'message', 'scrollUpMessage', 'scrollDownMessage', 'offset', 'delta']; UserScrollIfNeed.prototype.stateClasses['user_begin'] = StateBeforeScroll; UserScrollIfNeed.prototype.stateClasses['begin_scrolling'] = StateBeginScrolling; UserScrollIfNeed.prototype.stateClasses['show_message'] = StateShowMessage; UserScrollIfNeed.prototype.$scrollBarIcon = (0, _Core.$)(_Icon.ScrollBarIco.cloneNode(true)); UserScrollIfNeed.prototype.$scrollBarIconCtn = (0, _Core._)({ class: 'atr-scroll-icon-ctn', child: UserScrollIfNeed.prototype.$scrollBarIcon }); /*** * @type {Tooltip} */ UserScrollIfNeed.prototype.$scrollTooltip = (0, _Core._)({ tag: _Tooltip.default.tag, class: 'atr-scroll-tooltip', child: { class: 'atr-explain-text' } }); UserScrollIfNeed.prototype.$scrollTooltipText = (0, _Core.$)('.atr-explain-text', UserScrollIfNeed.prototype.$scrollTooltip); UserScrollIfNeed.prototype._showScroll = function (elt, dir) { this.$scrollBarIcon.removeClass('atr-down').removeClass('atr-up').removeStyle('transform'); this.$scrollBarIconCtn.removeStyle('left').removeStyle('top'); if (elt && !this.$scrollBarIconCtn.parentElement) document.body.appendChild(this.$scrollBarIconCtn);else if (!elt && this.$scrollBarIconCtn.parentElement) { this.$scrollBarIconCtn.remove(); return; } if (!dir) return; var bound = elt.getBoundingClientRect(); var iconBound = this.$scrollBarIconCtn.getBoundingClientRect(); if (dir.dy) { this.$scrollBarIconCtn.addStyle('left', bound.right - 17 - iconBound.width - 5 + 'px'); if (dir.dy > 0) { this.$scrollBarIcon.addClass('atr-up'); this.$scrollBarIconCtn.addStyle('top', bound.top + 'px'); } else { this.$scrollBarIcon.addClass('atr-down'); this.$scrollBarIconCtn.addStyle('top', bound.bottom - iconBound.height - 5 + 'px'); } } }; UserScrollIfNeed.prototype._showScrollTooltip = function (scroller, message, dir) { if (!message || !scroller || !dir || !dir.dy) { this.$scrollTooltip.remove(); return; } if (!this.$scrollTooltip.parentElement) document.body.appendChild(this.$scrollTooltip); var sBound = scroller.getBoundingClientRect(); var messageElt = this.md2HTMLElements(message); this.$scrollTooltipText.clearChild().addChild(messageElt); this.$scrollTooltip.addStyle('visibility', 'hidden'); var tBound = this.$scrollTooltip.getBoundingClientRect(); if (dir.dy > 0) { this.$scrollTooltip.removeClass('top').addClass('bottom'); this.$scrollTooltip.addStyle({ left: sBound.left + sBound.width / 2 - tBound.width / 2 + 'px', top: sBound.top + 'px', visibility: 'visible' }); } else { this.$scrollTooltip.removeClass('bottom').addClass('top'); this.$scrollTooltip.addStyle({ left: sBound.left + sBound.width / 2 - tBound.width / 2 + 'px', top: sBound.bottom - tBound.height - 40 + 'px', visibility: 'visible' }); } }; UserScrollIfNeed.prototype.findVScroller = function (elt, dY) { var parent = elt.parentElement; var overflowStyle; while (parent) { overflowStyle = window.getComputedStyle(parent)['overflow']; if ((overflowStyle === 'auto' || overflowStyle === 'hidden auto' || overflowStyle === 'scroll' || parent.tagName === 'HTML') && parent.clientHeight < parent.scrollHeight) { return parent; } parent = parent.parentElement; } }; UserScrollIfNeed.prototype.findScrollDir = function (elt, scroller) { var outBound; if (scroller) { outBound = scroller.getBoundingClientRect(); } else { outBound = (0, _Dom.traceOutBoundingClientRect)(elt); } var bound = elt.getBoundingClientRect(); var dx = 0; var dy = 0; if (outBound.height < bound.height * 1.2 && (true || outBound.height * 1.2 > bound.height)) { var delta = outBound.height * this.args.delta; var outStart = outBound.top + delta; var outEnd = outBound.bottom - delta; var outX = outStart + this.args.offset * (outEnd - outStart); var x = bound.top + this.args.offset * bound.height; if (Math.abs(x - outX) > delta) { if (outX < x) { dy = -1; } else { dy = 1; } } } else if (outBound.bottom < bound.bottom !== outBound.top > bound.top) { if (outBound.bottom < bound.bottom) { dy = -1; } else if (outBound.top > bound.top) { dy = 1; } } if (outBound.right < bound.right !== outBound.left > bound.left) { if (outBound.right < bound.right) { dx = -1; } else if (outBound.left > bound.left) { dx = 1; } } return { dx: dx, dy: dy }; }; UserScrollIfNeed.prototype.onStop = function () { this._showScroll(null); _BaseCommand.default.prototype.onStop.apply(this, arguments); this.$scrollBarIconCtn.remove(); this.$scrollTooltip.remove(); }; _TutorEngine.default.installClass(UserScrollIfNeed); _TutorNameManager.default.addAsync('userScrollIfNeed'); _TACData.default.define('userScrollIfNeed', { type: 'function', args: [{ name: 'eltPath', type: '(string|AElement)' }, { name: 'message', type: 'string' }, { name: 'scrollUpMessage', type: 'string' }, { name: 'scrollDownMessage', type: 'string' }, { name: 'offset', type: 'number(0->1)' }, { name: 'delta', type: 'number(0->1)' }], desc: "Yêu cầu người dùng scroll, hiện giờ chỉ hỗ trợ scroll dọc" }); var _default = UserScrollIfNeed; exports.default = _default;