![]() 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/MultiSelectMenu.js ***/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("../css/multiselectmenu.css"); var _ACore = _interopRequireDefault(require("../ACore")); var _SelectMenu = _interopRequireDefault(require("./SelectMenu2")); var _EventEmitter = _interopRequireDefault(require("absol/src/HTML5/EventEmitter")); var _PositionTracker = _interopRequireDefault(require("./PositionTracker")); require("./SelectBoxItem"); var _SelectListBox = require("./SelectListBox"); var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP")); var _ResizeSystem = _interopRequireDefault(require("absol/src/HTML5/ResizeSystem")); var _SelectBox = require("./SelectBox"); var _LanguageSystem = _interopRequireDefault(require("absol/src/HTML5/LanguageSystem")); var _ = _ACore.default._; var $ = _ACore.default.$; /*** * @augments SelectBox * @augments PositionTracker * @constructor */ function MultiSelectMenu() { this.on('click', this.eventHandler.click); /*** * * @type {SelectListBox} */ this.$selectlistBox = _({ tag: 'selectlistbox', props: { anchor: [1, 6, 2, 5], displayValue: _SelectListBox.VALUE_HIDDEN }, on: { preupdateposition: this.eventHandler.preUpdateListPosition, pressitem: this.eventHandler.selectListBoxPressItem } }); this.$itemCtn = $('.as-multi-select-menu-item-ctn', this); this.$attachhook = $('attachhook', this).on('attached', this.eventHandler.attached); _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; this.strictValue = true; } MultiSelectMenu.tag = 'MultiSelectMenu'.toLowerCase(); MultiSelectMenu.render = function () { return _({ class: ['as-multi-select-menu'], extendEvent: ['change', 'add', 'remove', 'activevaluechange'], attr: { tabindex: '1' }, child: [{ attr: { 'data-ml-key': 'txt_select_value' }, class: ['as-multi-select-menu-item-ctn', 'as-bscroller'] }, { tag: 'button', class: 'as-multi-select-menu-toggle-btn', child: 'dropdown-ico' }, 'attachhook'] }); }; MultiSelectMenu.prototype._requireItem = function (n) { var itemElt; while (this.$items.length < n) { itemElt = (0, _SelectBox.requireItem)(this); this.$itemCtn.addChild(itemElt); this.$items.push(itemElt); } while (this.$items.length > n) { itemElt = this.$items.pop(); this.$itemCtn.removeChild(itemElt); (0, _SelectBox.releaseItem)(itemElt); } }; MultiSelectMenu.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 */ MultiSelectMenu.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) { if (typeof this.orderly === 'function') { itemHolders.sort(this.orderly); } else { itemHolders.sort(function (a, b) { return a.idx - b.idx; }); } } return itemHolders.map(function (holder) { return holder.item; }); }; MultiSelectMenu.prototype._updateItems = function () { this.viewItemsByValues(this._values); }; MultiSelectMenu.prototype.viewItemsByValues = function (values) { var cBound = this.getBoundingClientRect(); var items = this._getItemsByValues(values); 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); } }; MultiSelectMenu.property = {}; MultiSelectMenu.property.disabled = _SelectMenu.default.property.disabled; MultiSelectMenu.property.hidden = _SelectMenu.default.property.hidden; MultiSelectMenu.property.isFocus = _SelectMenu.default.property.isFocus; MultiSelectMenu.property.readOnly = _SelectMenu.default.property.readOnly; MultiSelectMenu.prototype.init = function (props) { props = props || []; Object.keys(props).forEach(function (key) { if (props[key] === undefined) delete props[key]; }); this.super(props); }; MultiSelectMenu.prototype._updateFocusItem = function () { for (var i = 0; i < this.$items.length; ++i) { this.$items[i].active = this.$items[i].value == this._activeValue; } }; MultiSelectMenu.prototype.init = _SelectMenu.default.prototype.init; MultiSelectMenu.prototype._implicit = function (values) { if (values === null || values === undefined) values = []; if (!(values instanceof Array)) { values = [values]; } values = values.filter(function (value) { var type = typeof value; return type === 'string' || type === 'number' || type === "boolean" || value === null || value === undefined; }).reduce(function (ac, cr) { if (!ac.dict[cr]) { ac.dict[cr] = true; ac.result.push(cr); } return ac; }, { result: [], dict: {} }).result; return values; }; MultiSelectMenu.prototype._explicit = function (values) { var selectListBoxElt = this.$selectlistBox; var strictValue = this.strictValue; values = values.filter(function (value) { if (!strictValue) return true; var cts = selectListBoxElt.findItemsByValue(value); if (cts && cts.length > 0) return true; return false; }); return values; }; MultiSelectMenu.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; } }; MultiSelectMenu.property.values = { set: function (values) { values = this._implicit(values); this._values = values; this.$selectlistBox.values = values; this._updateItems(); }, get: function () { return this._explicit(this._values); } }; MultiSelectMenu.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; } }; MultiSelectMenu.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'); } }; MultiSelectMenu.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'); } }; MultiSelectMenu.property.activeValue = { set: function (value) { this._activeValue = value; if (this.itemFocusable) { this._updateFocusItem(); //todo } }, get: function () { return this._activeValue; } }; MultiSelectMenu.property.strictValue = { set: function (value) { if (value) { this.attr('data-strict-value', null); } else { this.attr('data-strict-value', 'false'); } }, get: function () { var data = this.attr('data-strict-value'); return !data || data != 'false' && data !== '0'; } }; MultiSelectMenu.eventHandler = Object.assign({}, _SelectMenu.default.eventHandler); MultiSelectMenu.eventHandler.attached = function () { var maxHeightStyle = this.getComputedStyleValue('max-height') || 'none'; if (maxHeightStyle.match(/[0-9-]+px/)) { this.addStyle('--multi-select-menu-max-height', maxHeightStyle); this.addStyle('max-height', 'unset'); } else if (maxHeightStyle !== 'none') { console.warn('Can not adapt max-height:', maxHeightStyle); } }; MultiSelectMenu.eventHandler.click = function (event) { if (this.disabled) return; if ((event.target === this || event.target === this.$itemCtn) && !this.disableClickToFocus && !this.readOnly) { this.isFocus = !this.isFocus; } }; MultiSelectMenu.eventHandler.bodyClick = function (event) { if (!_EventEmitter.default.hitElement(this.$selectlistBox, event) && event.target !== this && event.target !== this.$itemCtn) { this.isFocus = false; } }; MultiSelectMenu.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._values = currentValues.slice(); 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); }; MultiSelectMenu.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); } } }; MultiSelectMenu.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(MultiSelectMenu); var _default = MultiSelectMenu; exports.default = _default;