![]() 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/MSelectBox.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeItem = makeItem; exports.requireBoxItem = requireBoxItem; exports.releaseBoxItem = releaseBoxItem; exports.default = void 0; require("../../css/mselectbox.css"); var _MSelectMenu = _interopRequireDefault(require("./MSelectMenu")); var _Core = _interopRequireDefault(require("./Core")); var _MListModal = _interopRequireWildcard(require("./MListModal")); /*global absol*/ var _ = _Core.default._; var $ = _Core.default.$; var boxItemPool = []; function closeBoxItem(event) { var thisSB = this.$parent; if (!thisSB) return; var itemValue = this.value; var index = thisSB.values.indexOf(itemValue); if (index >= 0) { thisSB.values = thisSB.values.slice(0, index).concat(thisSB.values.slice(index + 1)); thisSB.emit('remove', { type: 'remove', values: thisSB.values, target: thisSB, itemElt: this, value: this.value, itemData: this.data }, thisSB); thisSB.emit('change', { type: 'change', values: thisSB.values, target: thisSB }, thisSB); } } /** * @returns {MSelectListItem} */ function makeItem() { return _({ tag: 'selectboxitem', on: { close: closeBoxItem } }); } function requireBoxItem($parent) { var item; if (boxItemPool.length > 0) { item = boxItemPool.pop(); } else { item = makeItem(); } item.$parent = $parent; return item; } function releaseBoxItem(item) { item.$parent = null; boxItemPool.push(item); } /*** * @extends Element * @constructor */ function MSelectBox() { this._isFocus = false; this._values = []; this._orderly = false; this._itemsByValue = {}; this.$boxItems = []; this.$selectlist = _('mlistmodal'); this.$selectlist.displayValue = _MListModal.VALUE_HIDDEN; this.$selectlist.on('pressitem', this.eventHandler.pressItem, true).on('pressout', this.eventHandler.pressOut).on('pressclose', this.eventHandler.pressOut); this.on('click', this.eventHandler.click); this.$attachhook = $('attachhook', this).on('error', this.eventHandler.attached); this._values = []; this.orderly = false; this.items = []; this.values = []; } MSelectBox.tag = 'MSelectBox'.toLowerCase(); MSelectBox.render = function () { return _({ tag: 'bscroller', class: ['absol-selectbox', 'absol-bscroller', 'am-select-box'], extendEvent: ['change', 'add', 'remove', 'minwidthchange'], attr: { tabindex: '1' }, child: 'attachhook' }, true); }; MSelectBox.prototype.getRecommendWith = function () { return this.$selectlist.estimateSize.textWidth + 60; }; MSelectBox.prototype._dictByValue = _MSelectMenu.default.prototype._dictByValue; MSelectBox.property = {}; MSelectBox.property.disabled = _MSelectMenu.default.property.disabled; MSelectBox.property.hidden = _MSelectMenu.default.property.hidden; MSelectBox.property.enableSearch = _MSelectMenu.default.property.enableSearch; MSelectBox.prototype.init = function (props) { props = props || []; Object.keys(props).forEach(function (key) { if (props[key] === undefined) delete props[key]; }); this.super(props); }; MSelectBox.prototype._requireBoxItems = function (n) { var boxItemElt; while (this.$boxItems.length < n) { boxItemElt = requireBoxItem(this); this.$boxItems.push(boxItemElt); this.addChild(boxItemElt); } while (this.$boxItems.length > n) { boxItemElt = this.$boxItems.pop(); boxItemElt.selfRemove(); releaseBoxItem(boxItemElt); } }; MSelectBox.prototype._sortValuesIfNeed = function (values) { if (this._orderly) { var thisMB = this; values.sort(function (a, b) { var aItem = thisMB._itemsByValue[a]; var bItem = thisMB._itemsByValue[b]; if (!aItem) return 1; if (!bItem) return -1; return aItem.__index__ - bItem.__index__; }); } }; MSelectBox.prototype._assignBoxItems = function (values) { var n = values.length; var item; var value; for (var i = 0; i < n; ++i) { value = values[i]; item = this._itemsByValue[value]; this.$boxItems[i].data = item || { text: 'error' }; } }; MSelectBox.prototype._updateValues = function () { this.viewItemsByValues(this._values); }; MSelectBox.prototype.viewItemsByValues = function (values) { this._requireBoxItems(values.length); this._assignBoxItems(values); }; MSelectBox.prototype.querySelectedItems = function () { return Array.prototype.map.call(this.$holderItem.childNodes, function (e) { return e.data; }); }; MSelectBox.property.isFocus = _MSelectMenu.default.property.isFocus; /*** * * @type {MSelectBox} */ MSelectBox.property.items = { set: function (items) { items = items || []; items.forEach(function (item, i) { item.__index__ = i; }); this._items = items; this._itemsByValue = this._dictByValue(items); this.$selectlist.items = items; this.addStyle('--item-min-width', this.$selectlist.estimateSize.textWidth + 60 + 'px'); this._sortValuesIfNeed(this._values); this._updateValues(); }, get: function () { return this._items; } }; MSelectBox.property.values = { set: function (values) { values = values || []; values = values instanceof Array ? values : [values]; values = values.slice(); this._values = values; this.$selectlist.values = values; this._sortValuesIfNeed(this._values); this._updateValues(); }, get: function () { return this._values || []; } }; MSelectBox.property.orderly = { set: function (value) { this._orderly = !!value; this._sortValuesIfNeed(this._values); this._updateValues(); }, get: function () { return !!this._orderly; } }; /*** * * @type {MSelectBox} */ MSelectBox.eventHandler = {}; MSelectBox.eventHandler.pressOut = _MSelectMenu.default.eventHandler.pressOut; MSelectBox.eventHandler.attached = _MSelectMenu.default.eventHandler.attached; MSelectBox.eventHandler.click = function (event) { if (event.target == this) { this.isFocus = !this.isFocus; } }; MSelectBox.eventHandler.pressItem = function (event) { this.values.push(event.value); this._sortValuesIfNeed(this._values); this._updateValues(); this.$selectlist.values = this.values; this.emit('add', { type: 'add', itemData: event.itemElt.data, value: event.value, values: this.values }, this); this.emit('change', { type: 'change', values: this.values, target: this }, this); this.isFocus = false; }; _Core.default.install('MSelectBox'.toLowerCase(), MSelectBox); var _default = MSelectBox; exports.default = _default;