![]() 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-acomp/js/SelectBox.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.requireItem = requireItem; exports.releaseItem = releaseItem; exports.default = void 0; require("../css/selectbox.css"); var _ACore = _interopRequireDefault(require("../ACore")); var _SelectMenu = _interopRequireDefault(require("./SelectMenu2")); var _EventEmitter = _interopRequireDefault(require("absol/src/HTML5/EventEmitter")); var _PositionTracker = _interopRequireDefault(require("./PositionTracker")); var _SelectBoxItem = _interopRequireDefault(require("./SelectBoxItem")); var _SelectListBox = require("./SelectListBox"); var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP")); var _ResizeSystem = _interopRequireDefault(require("absol/src/HTML5/ResizeSystem")); var _ = _ACore.default._; var $ = _ACore.default.$; function pressCloseEventHandler(event) { var parentElt = this.$parent; if (!parentElt) return; parentElt.eventHandler.pressCloseItem(this, event); } function pressHandler(event) { var parentElt = this.$parent; if (!parentElt) return; parentElt.eventHandler.pressItem(this, event); } /*** * * @returns {SelectBoxItem} */ function makeItem() { return _({ tag: 'selectboxitem', on: { close: pressCloseEventHandler, press: pressHandler } }); } var itemPool = []; function requireItem($parent) { var item; if (itemPool.length > 0) { item = itemPool.pop(); } else { item = makeItem(); } item.$parent = $parent; return item; } function releaseItem(item) { item.$parent = null; itemPool.push(item); } /*** * @extends PositionTracker * @return {SelectBox} * @constructor */ function SelectBox() { this.on('click', this.eventHandler.click); this.$selectlistBox = _({ tag: 'selectlistbox', props: { anchor: [1, 6, 2, 5], displayValue: _SelectListBox.VALUE_HIDDEN }, on: { preupdateposition: this.eventHandler.preUpdateListPosition, pressitem: this.eventHandler.selectListBoxPressItem } }); _OOP.default.drillProperty(this, this.$selectlistBox, 'enableSearch'); this.$items = []; this._values = []; this.items = []; this.values = []; this.$selectlistBox.followTarget = this; this.$selectlistBox.sponsorElement = this; this.disableClickToFocus = false; this.orderly = true; this.itemFocusable = false; this._activeValue = undefined; return this; } SelectBox.tag = 'selectbox'; SelectBox.render = function () { return _({ tag: 'bscroller', class: ['absol-selectbox', 'absol-bscroller'], extendEvent: ['change', 'add', 'remove', 'activevaluechange'], attr: { tabindex: '1' } }, true); }; SelectBox.prototype._requireItem = function (n) { var itemElt; while (this.$items.length < n) { itemElt = requireItem(this); this.addChild(itemElt); this.$items.push(itemElt); } while (this.$items.length > n) { itemElt = this.$items.pop(); this.removeChild(itemElt); releaseItem(itemElt); } }; SelectBox.prototype._assignItems = function (items) { for (var i = 0; i < this.$items.length && i < items.length; ++i) { this.$items[i].data = items[i]; } }; /*** * * @param {string[] | number[]} values * @private */ SelectBox.prototype._getItemsByValues = function (values) { var selectListBoxElt = this.$selectlistBox; var itemHolders = values.reduce(function (ac, cr) { ac.push.apply(ac, selectListBoxElt.findItemsByValue(cr)); return ac; }, []); if (this.orderly) { itemHolders.sort(function (a, b) { return a.idx - b.idx; }); } return itemHolders.map(function (holder) { return holder.item; }); }; SelectBox.prototype._updateItems = function () { this.viewItemsByValues(this._values); }; SelectBox.prototype.viewItemsByValues = function (values) { var items = this._getItemsByValues(values); var cBound = this.getBoundingClientRect(); this._requireItem(items.length); this._assignItems(items); if (this.itemFocusable) { this._updateFocusItem(); } var nBound = this.getBoundingClientRect(); if (nBound.width != cBound.width || nBound.height != cBound.height) { _ResizeSystem.default.updateUp(this); } }; SelectBox.property = {}; SelectBox.property.disabled = _SelectMenu.default.property.disabled; SelectBox.property.hidden = _SelectMenu.default.property.hidden; SelectBox.property.isFocus = _SelectMenu.default.property.isFocus; SelectBox.prototype.init = function (props) { props = props || []; Object.keys(props).forEach(function (key) { if (props[key] === undefined) delete props[key]; }); this.super(props); }; SelectBox.prototype._updateFocusItem = function () { for (var i = 0; i < this.$items.length; ++i) { this.$items[i].active = this.$items[i].value == this._activeValue; } }; SelectBox.prototype.init = _SelectMenu.default.prototype.init; SelectBox.property.items = { set: function (items) { items = items || []; this.$selectlistBox.items = items; this.addStyle('--list-min-width', this.$selectlistBox._estimateWidth + 'px'); this._updateItems(); }, get: function () { return this.$selectlistBox.items; } }; SelectBox.property.values = { set: function (values) { values = values || []; values = values instanceof Array ? values : [values]; this._values = values; this.$selectlistBox.values = values; this._updateItems(); }, get: function () { return this._values || []; } }; SelectBox.property.orderly = { set: function (value) { var needUpdate = this._orderly === this._orderly; if (typeof value === 'function') { this._orderly; } else this._orderly = !!value; if (needUpdate) { this.values = this.values; } }, get: function () { return !!this._orderly; } }; SelectBox.property.disableClickToFocus = { set: function (value) { if (value) { this.addClass('as-disable-click-to-focus'); } else { this.removeClass('as-disable-click-to-focus'); } }, get: function () { return this.hasClass('as-disable-click-to-focus'); } }; SelectBox.property.itemFocusable = { set: function (value) { if (value) { this.addClass('as-item-focusable'); } else { this.removeClass('as-item-focusable'); } this._updateFocusItem(); }, get: function () { return this.hasClass('as-item-focusable'); } }; SelectBox.property.activeValue = { set: function (value) { this._activeValue = value; if (this.itemFocusable) { this._updateFocusItem(); //todo } }, get: function () { return this._activeValue; } }; SelectBox.eventHandler = Object.assign({}, _SelectMenu.default.eventHandler); SelectBox.eventHandler.click = function (event) { if (event.target === this && !this.disableClickToFocus) { this.isFocus = !this.isFocus; } }; SelectBox.eventHandler.bodyClick = function (event) { if (!_EventEmitter.default.hitElement(this.$selectlistBox, event) && event.target !== this) { this.isFocus = false; } }; SelectBox.eventHandler.selectListBoxPressItem = function (event) { var data = event.data; var currentValues = this.$selectlistBox.values; currentValues.push(data.value); this.$selectlistBox.values = currentValues; this.$selectlistBox.updatePosition(); this._activeValue = data.value; this._updateItems(); this.isFocus = false; this.emit('add', Object.assign({}, event, { type: 'add', target: this, value: data.value, data: data, itemData: data }), this); this.emit('change', Object.assign({}, event, { type: 'change', action: 'add', target: this, value: data.value, data: data, values: this.values }), this); }; SelectBox.eventHandler.pressCloseItem = function (item, event) { var value = item.value; var data = item.data; var currentValues = this.$selectlistBox.values; var index = currentValues.indexOf(value); if (index >= 0) { currentValues.splice(index, 1); } this.$selectlistBox.values = currentValues; this.$selectlistBox.updatePosition(); this._values = currentValues; this._updateItems(); this.emit('remove', Object.assign({}, event, { type: 'change', target: this, data: data, value: value, itemData: data }), this); this.emit('change', Object.assign({}, event, { type: 'change', action: 'remove', target: this, data: data, value: value, itemData: data }), this); }; SelectBox.eventHandler.pressItem = function (item, event) { var value = item.value; if (this.itemFocusable) { var prevActiveValue = this.activeValue; if (value !== prevActiveValue) { this.activeValue = value; this.emit('activevaluechange', { target: this, originEvent: event, prevActiveValue: prevActiveValue, activeValue: value }, this); } } }; SelectBox.eventHandler.pressCloseItem = function (item, event) { var value = item.value; var data = item.data; var index; index = this._values.indexOf(value); if (index >= 0) { this._values.splice(index, 1); this._updateItems(); this.$selectlistBox.values = this._values; this.emit('remove', Object.assign({}, event, { type: 'change', target: this, data: data, value: value, itemData: data }), this); this.emit('change', Object.assign({}, event, { type: 'change', action: 'remove', target: this, data: data, value: value, itemData: data }), this); } }; _ACore.default.install(SelectBox); var _default = SelectBox; exports.default = _default;