![]() 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/MBottomTabbar.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("../../css/mbottomtabbar.css"); var _Core = _interopRequireDefault(require("./Core")); var _Dom = _interopRequireDefault(require("absol/src/HTML5/Dom")); var _stringGenerate = require("absol/src/String/stringGenerate"); var _ = _Core.default._; var $ = _Core.default.$; function MBottomTabbar() { this._items = []; this.$row = $('.am-bottom-tabbar-content-row', this); this.$itemDict = {}; this.$line = $('.am-bottom-tabbar-line', this); this.$attachhook = _('attachhook').addTo(this); this.$attachhook.requestUpdateSize = this.updateSize.bind(this); this.$attachhook.on('error', function () { _Dom.default.addToResizeSystem(this); }); this.$activeItem = null; this.$subActiveItem = null; } MBottomTabbar.tag = 'MBottomTabbar'.toLowerCase(); MBottomTabbar.render = function () { return _({ class: 'am-bottom-tabbar', extendEvent: 'change', child: ['.am-bottom-tabbar-line', { class: 'am-bottom-tabbar-content', child: '.am-bottom-tabbar-content-row' }] }); }; MBottomTabbar.prototype.getItemEltByValue = function (value) { return this.$itemDict[value]; }; MBottomTabbar.prototype.modifyItem = function (itemValue, propertyName, newValue) { if (this.$itemDict[itemValue]) this.$itemDict[itemValue].data[propertyName] = newValue; }; MBottomTabbar.prototype.getItem = function (itemValue) { if (this.$itemDict[itemValue]) return this.$itemDict[itemValue].data; return null; }; MBottomTabbar.prototype.updateSize = function () { this.updateLinePosition(); }; MBottomTabbar.prototype.notifyChange = function () { this.emit('change', { target: this, value: this._value }, this); }; MBottomTabbar.prototype.updateLinePosition = function () { if (this.$activeItem) { var bound = this.getBoundingClientRect(); var iBound = this.$activeItem.getBoundingClientRect(); this.$line.addStyle({ width: iBound.width + 'px', left: iBound.left - bound.left + 'px' }); } else { this.$line.addStyle('width', '0'); } }; MBottomTabbar.prototype._makeSubItem = function (data, parentElt) { var self = this; var itemElt = _({ class: 'am-bottom-tabbar-item', child: [data.icon, '.am-bottom-tabbar-item-counter'], props: { parentItemElt: parentElt } }); itemElt.attr('tabindex', 1); this.$itemDict[data.value] = itemElt; var counterElt = $('.am-bottom-tabbar-item-counter', itemElt); var counter = data.counter; if (!data.__bindCounter__) { Object.defineProperties(data, { __dataBinding__: { value: true, writable: false, enumerable: false }, counter: { set: function (value) { counter = value; if (value >= 0) { if (value > 9) { counterElt.innerHTML = '9+'; } else if (value > 0) { counterElt.innerHTML = value; } else { counterElt.innerHTML = ''; } } else { if (value) counterElt.innerHTML = value + "";else counterElt.innerHTML = ''; } if (parentElt.$subItems && parentElt.data) { parentElt.data.counter = parentElt.data.items.reduce(function (ac, cr) { return ac + (cr.counter || 0); }, 0); } }, get: function () { return counter; } } }); } data.counter = counter; itemElt.data = data; function onPress() { if (self._value !== data.value) { parentElt.lastSubValue = data.value; self.value = data.value; self.notifyChange(); } } itemElt.on('touchstart', onPress, true); itemElt.on('pointerdown', onPress, true); return itemElt; }; MBottomTabbar.prototype._makeItem = function (data) { var self = this; var itemElt = _({ class: 'am-bottom-tabbar-item', child: [data.icon, '.am-bottom-tabbar-item-counter'] }); itemElt.attr('tabindex', 1); if (!('value' in data)) data.value = (0, _stringGenerate.randomIdent)(); this.$itemDict[data.value] = itemElt; var subItemCtn; var counterElt = $('.am-bottom-tabbar-item-counter', itemElt); var counter = data.counter; if (data.items && data.items.length > 0) { itemElt.lastSubValue = data.items[0].value; itemElt.$subItems = data.items.map(function (sItem) { return this._makeSubItem(sItem, itemElt); }.bind(this)); counter = data.items.reduce(function (ac, cr) { return ac + (cr.counter || 0); }, 0); subItemCtn = _({ class: 'am-bottom-tabbar-sub-item-ctn', child: { class: 'am-bottom-tabbar-sub-item-box', child: itemElt.$subItems } }); var lastTimeFocus = 0; var isTouch; function onPress(event) { isTouch = event.type === 'touchstart'; lastTimeFocus = new Date().getTime(); subItemCtn.addClass('am-prepare-appear'); // self.addChildAfter(subItemCtn, null); document.body.appendChild(subItemCtn); setTimeout(function () { subItemCtn.removeClass('am-prepare-appear').addClass('am-appear'); }, 3); itemElt.off('touchstart', onPress).off('mousedown', onPress); setTimeout(function () { itemElt.on('touchstart', onRepress) // .on('mousedown', onRepress) .on('blur', onRepress); }, 100); } function onRepress(event) { if (isTouch && event.type === 'mousedown') return; subItemCtn.removeClass('am-appear').addClass('am-prepare-disappear'); setTimeout(function () { subItemCtn.removeClass('am-prepare-disappear').remove(); }, 205); itemElt.off('touchstart', onRepress) // .off('mousedown', onRepress) .off('blur', onRepress); setTimeout(function () { itemElt.on('touchstart', onPress); // .on('mousedown', onPress); }, 100); } itemElt.on('touchstart', onPress); // .on('mousedown', onPress); } if (!data.__bindCounter__) { Object.defineProperties(data, { __dataBinding__: { value: true, writable: false, enumerable: false }, counter: { set: function (value) { counter = value; if (value >= 0) { if (value > 9) { counterElt.innerHTML = '9+'; } else if (value > 0) { counterElt.innerHTML = value; } else { counterElt.innerHTML = ''; } } else { if (value) counterElt.innerHTML = value + "";else counterElt.innerHTML = ''; } }, get: function () { return counter; } } }); } data.counter = counter; itemElt.data = data; itemElt.on('click', function () { if (data.items && data.items.length > 0) { if (self.$itemDict[self._value] && self.$itemDict[self._value].parentItemElt !== itemElt) { self.value = itemElt.lastSubValue; self.notifyChange(); } } else if (self._value !== data.value) { self.value = data.value; self.notifyChange(); } }); return itemElt; }; MBottomTabbar.property = {}; /** * @type {MBottomTabbar} */ MBottomTabbar.property.items = { set: function (items) { items = items || []; this._items = items; this.$row.clearChild(); this.$itemDict = {}; this.$activeItem = null; this.$itemDict = {}; for (var i = 0; i < items.length; ++i) { this._makeItem(items[i]).addTo(this.$row); } if (items && items.length > 0) { if (this.$itemDict[this._value]) { this.value = this._value; } else { this.value = items[0].value; } } }, get: function () { return this._items; } }; /** * @type {MBottomTabbar} */ MBottomTabbar.property.value = { set: function (value) { this._value = value; if (this.$activeItem) { this.$activeItem.removeClass('am-active'); this.$activeItem = null; } if (this.$subActiveItem) { this.$subActiveItem.removeClass('am-active'); this.$subActiveItem = null; } this.$activeItem = this.$itemDict[value]; if (this.$activeItem && this.$activeItem.parentItemElt) { this.$subActiveItem = this.$activeItem; this.$activeItem = this.$activeItem.parentItemElt; } if (this.$activeItem) { this.$activeItem.addClass('am-active'); } if (this.$subActiveItem) { this.$subActiveItem.addClass('am-active'); } this.updateLinePosition(); }, get: function () { return this._value; } }; _Core.default.install(MBottomTabbar); var _default = MBottomTabbar; exports.default = _default;