%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 18.217.37.129 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/js/landing/ui/field/ |
Upload File : |
;(function() { "use strict"; BX.namespace("BX.Landing.UI.Field"); var isArray = BX.Landing.Utils.isArray; /** * Implements interface for works with button group field in editor * * @extends {BX.Landing.UI.Field.BaseField} * * @param {object} data * @constructor */ BX.Landing.UI.Field.ButtonGroup = function(data) { this.items = "items" in data && data.items ? data.items : []; BX.Landing.UI.Field.BaseField.apply(this, arguments); this.layout.classList.add("landing-ui-field-button-group"); this.frame = typeof data.frame === "object" ? data.frame : null; this.format = typeof data.format === "function" ? data.format : (function() {}); this.postfix = typeof data.postfix === "string" ? data.postfix : ""; this.property = typeof data.property === "string" ? data.property : ""; this.multiple = typeof data.multiple === "boolean" ? data.multiple : false; this.changeHandler = typeof data.onChange === "function" ? data.onChange : (function() {}); this.elements = []; this.buttons = new BX.Landing.UI.Collection.ButtonCollection(); this.value = this.getValue(); this.onButtonClick = this.onButtonClick.bind(this); this.input.innerHTML = ""; this.items.forEach(function(item) { var button = this.createButtonByItem(item); this.buttons.add(button); this.input.appendChild(button.layout); }, this); if (this.content) { this.setValue(this.content, true); } if (this.frame) { this.onFrameLoad(); } }; BX.Landing.UI.Field.ButtonGroup.prototype = { constructor: BX.Landing.UI.Field.ButtonGroup, __proto__: BX.Landing.UI.Field.BaseField.prototype, superClass: BX.Landing.UI.Field.BaseField, onFrameLoad: function() { this.elements = [].slice.call(this.frame.document.querySelectorAll(this.selector)); if (this.elements.length) { this.items.some(function(item) { if (this.elements[0].classList.contains(item.value)) { this.buttons.getByValue(item.value).activate(); return !this.multiple; } }, this); } }, createButtonByItem: function (item) { return new BX.Landing.UI.Button.BaseButton( item.id || item.value, { html: item.name, active: item.active, attrs: { value: item.value, title: item.title ? BX.Landing.Utils.escapeText(item.title) : null, }, onClick: this.onButtonClick, } ); }, onButtonClick: function(event) { var button = this.buttons.getByNode(event.currentTarget); var value = button.layout.value; if (this.multiple) { if (button.isActive()) { button.deactivate(); } else { button.activate(); } } else { this.deactivateAll(); button.activate(); } this.onChange(value); }, /** * Handles change event */ onChange: function(value) { if (!this.multiple) { this.changeHandler(value, this.items, this.postfix, this.property); } else { this.elements.forEach(function(element) { element.classList.toggle(value); }, this); this.changeHandler(); } this.onValueChangeHandler(this); }, /** * Checks that field is changed * @return {boolean} */ isChanged: function() { return this.value !== this.getValue(); }, /** * Sets field value value * @param value * @param {boolean} [preventEvent = false] */ setValue: function(value, preventEvent) { this.deactivateAll(); if (this.multiple) { value = isArray(value) ? value : [value]; value.forEach(function(val) { var button = this.buttons.getByValue(val); if (button) { button.activate(); } }, this); } else { var button = this.buttons.getByValue(value); if (button) { button.activate(); } } if (!preventEvent) { this.onChange(value); } }, /** * Deactivates all buttons */ deactivateAll: function() { this.buttons.forEach(function(button) { button.deactivate(); }); }, /** * Gets field value * @return {?string} */ getValue: function() { var button = this.buttons.getActive(); if (button) { return button.layout.value; } return null; } } })();