UNPKG

7.06 kBJavaScriptView Raw
1(function (global, factory) {
2 if (typeof define === "function" && define.amd) {
3 define(["exports", "../../globals/js/settings", "../../globals/js/misc/mixin", "../../globals/js/mixins/create-component", "../../globals/js/mixins/init-component-by-search", "../../globals/js/mixins/handles", "../../globals/js/misc/on"], factory);
4 } else if (typeof exports !== "undefined") {
5 factory(exports, require("../../globals/js/settings"), require("../../globals/js/misc/mixin"), require("../../globals/js/mixins/create-component"), require("../../globals/js/mixins/init-component-by-search"), require("../../globals/js/mixins/handles"), require("../../globals/js/misc/on"));
6 } else {
7 var mod = {
8 exports: {}
9 };
10 factory(mod.exports, global.settings, global.mixin, global.createComponent, global.initComponentBySearch, global.handles, global.on);
11 global.numberInput = mod.exports;
12 }
13})(this, function (_exports, _settings, _mixin2, _createComponent, _initComponentBySearch, _handles, _on) {
14 "use strict";
15
16 Object.defineProperty(_exports, "__esModule", {
17 value: true
18 });
19 _exports.default = void 0;
20 _settings = _interopRequireDefault(_settings);
21 _mixin2 = _interopRequireDefault(_mixin2);
22 _createComponent = _interopRequireDefault(_createComponent);
23 _initComponentBySearch = _interopRequireDefault(_initComponentBySearch);
24 _handles = _interopRequireDefault(_handles);
25 _on = _interopRequireDefault(_on);
26
27 function _interopRequireDefault(obj) {
28 return obj && obj.__esModule ? obj : {
29 default: obj
30 };
31 }
32
33 function _typeof(obj) {
34 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
35 _typeof = function _typeof(obj) {
36 return typeof obj;
37 };
38 } else {
39 _typeof = function _typeof(obj) {
40 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
41 };
42 }
43
44 return _typeof(obj);
45 }
46
47 function _classCallCheck(instance, Constructor) {
48 if (!(instance instanceof Constructor)) {
49 throw new TypeError("Cannot call a class as a function");
50 }
51 }
52
53 function _defineProperties(target, props) {
54 for (var i = 0; i < props.length; i++) {
55 var descriptor = props[i];
56 descriptor.enumerable = descriptor.enumerable || false;
57 descriptor.configurable = true;
58 if ("value" in descriptor) descriptor.writable = true;
59 Object.defineProperty(target, descriptor.key, descriptor);
60 }
61 }
62
63 function _createClass(Constructor, protoProps, staticProps) {
64 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
65 if (staticProps) _defineProperties(Constructor, staticProps);
66 return Constructor;
67 }
68
69 function _possibleConstructorReturn(self, call) {
70 if (call && (_typeof(call) === "object" || typeof call === "function")) {
71 return call;
72 }
73
74 return _assertThisInitialized(self);
75 }
76
77 function _assertThisInitialized(self) {
78 if (self === void 0) {
79 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
80 }
81
82 return self;
83 }
84
85 function _getPrototypeOf(o) {
86 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
87 return o.__proto__ || Object.getPrototypeOf(o);
88 };
89 return _getPrototypeOf(o);
90 }
91
92 function _inherits(subClass, superClass) {
93 if (typeof superClass !== "function" && superClass !== null) {
94 throw new TypeError("Super expression must either be null or a function");
95 }
96
97 subClass.prototype = Object.create(superClass && superClass.prototype, {
98 constructor: {
99 value: subClass,
100 writable: true,
101 configurable: true
102 }
103 });
104 if (superClass) _setPrototypeOf(subClass, superClass);
105 }
106
107 function _setPrototypeOf(o, p) {
108 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
109 o.__proto__ = p;
110 return o;
111 };
112
113 return _setPrototypeOf(o, p);
114 }
115
116 var NumberInput =
117 /*#__PURE__*/
118 function (_mixin) {
119 _inherits(NumberInput, _mixin);
120 /**
121 * Number input UI.
122 * @extends CreateComponent
123 * @extends InitComponentBySearch
124 * @extends Handles
125 * @param {HTMLElement} element The element working as a number input UI.
126 */
127
128
129 function NumberInput(element, options) {
130 var _this;
131
132 _classCallCheck(this, NumberInput);
133
134 _this = _possibleConstructorReturn(this, _getPrototypeOf(NumberInput).call(this, element, options)); // Broken DOM tree is seen with up/down arrows <svg> in IE, which breaks event delegation.
135 // <svg> does not have `Element.classList` in IE11
136
137 _this.manage((0, _on.default)(_this.element.querySelector('.up-icon'), 'click', function (event) {
138 _this._handleClick(event);
139 }));
140
141 _this.manage((0, _on.default)(_this.element.querySelector('.down-icon'), 'click', function (event) {
142 _this._handleClick(event);
143 }));
144
145 return _this;
146 }
147 /**
148 * Increase/decrease number by clicking on up/down icons.
149 * @param {Event} event The event triggering this method.
150 */
151
152
153 _createClass(NumberInput, [{
154 key: "_handleClick",
155 value: function _handleClick(event) {
156 var numberInput = this.element.querySelector(this.options.selectorInput);
157 var target = event.currentTarget.getAttribute('class').split(' ');
158
159 if (target.indexOf('up-icon') >= 0) {
160 ++numberInput.value;
161 } else if (target.indexOf('down-icon') >= 0) {
162 --numberInput.value;
163 } // Programmatic change in value (including `stepUp()`/`stepDown()`) won't fire change event
164
165
166 numberInput.dispatchEvent(new CustomEvent('change', {
167 bubbles: true,
168 cancelable: false
169 }));
170 }
171 /**
172 * The map associating DOM element and number input UI instance.
173 * @member NumberInput.components
174 * @type {WeakMap}
175 */
176
177 }], [{
178 key: "options",
179
180 /**
181 * The component options.
182 * If `options` is specified in the constructor,
183 * {@linkcode NumberInput.create .create()}, or {@linkcode NumberInput.init .init()},
184 * properties in this object are overriden for the instance being create and how {@linkcode NumberInput.init .init()} works.
185 * @member NumberInput.options
186 * @type {Object}
187 * @property {string} selectorInit The CSS selector to find number input UIs.
188 * @property {string} [selectorInput] The CSS selector to find the `<input>` element.
189 */
190 get: function get() {
191 var prefix = _settings.default.prefix;
192 return {
193 selectorInit: '[data-numberinput]',
194 selectorInput: ".".concat(prefix, "--number input")
195 };
196 }
197 }]);
198
199 NumberInput.components = new WeakMap();
200 return NumberInput;
201 }((0, _mixin2.default)(_createComponent.default, _initComponentBySearch.default, _handles.default));
202
203 var _default = NumberInput;
204 _exports.default = _default;
205});
\No newline at end of file