/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
lib/web/mage/trim-input.js
72 строки
2 KB
Alexandra Zota
ACP2E-4019: CE copyright updates for 2.4.9-beta1
11 ноя 2025, 17:53
11 ноя 2025, 17:53
f22b64f
Код
Авторство
О чём код?
/** * Copyright 2018 Adobe * All Rights Reserved. */ define([ 'jquery', 'jquery-ui-modules/widget' ], function ($) { 'use strict'; $.widget('mage.trimInput', { options: { cache: {} }, /** * Widget initialization * @private */ _create: function () { this.options.cache.input = $(this.element); this._bind(); }, /** * Event binding, will monitor change, keyup and paste events. * @private */ _bind: function () { if (this.options.cache.input.length) { this._on(this.options.cache.input, { 'change': this._trimInput, 'keyup': this._trimInput, 'paste': this._trimInput }); } }, /** * Trim value * @private */ _trimInput: function () { // Safari caret position workaround: storing carter position var caretStart, caretEnd, input; caretStart = this.options.cache.input.get(0).selectionStart; caretEnd = this.options.cache.input.get(0).selectionEnd; input = this._getInputValue().trim(); this.options.cache.input.val(input); // Safari caret position workaround: setting caret position to previously stored values if (caretStart !== null && caretEnd !== null) { this.options.cache.input.get(0).setSelectionRange(caretStart, caretEnd); } }, /** * Get input value * @returns {*} * @private */ _getInputValue: function () { return this.options.cache.input.val(); } }); return $.mage.trimInput; });