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"], 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"));
|
6 | } else {
|
7 | var mod = {
|
8 | exports: {}
|
9 | };
|
10 | factory(mod.exports, global.settings, global.mixin, global.createComponent, global.initComponentBySearch);
|
11 | global.progressIndicator = mod.exports;
|
12 | }
|
13 | })(this, function (_exports, _settings, _mixin2, _createComponent, _initComponentBySearch) {
|
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 |
|
25 | function _interopRequireDefault(obj) {
|
26 | return obj && obj.__esModule ? obj : {
|
27 | default: obj
|
28 | };
|
29 | }
|
30 |
|
31 | function _typeof(obj) {
|
32 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
33 | _typeof = function _typeof(obj) {
|
34 | return typeof obj;
|
35 | };
|
36 | } else {
|
37 | _typeof = function _typeof(obj) {
|
38 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
39 | };
|
40 | }
|
41 |
|
42 | return _typeof(obj);
|
43 | }
|
44 |
|
45 | function _classCallCheck(instance, Constructor) {
|
46 | if (!(instance instanceof Constructor)) {
|
47 | throw new TypeError("Cannot call a class as a function");
|
48 | }
|
49 | }
|
50 |
|
51 | function _defineProperties(target, props) {
|
52 | for (var i = 0; i < props.length; i++) {
|
53 | var descriptor = props[i];
|
54 | descriptor.enumerable = descriptor.enumerable || false;
|
55 | descriptor.configurable = true;
|
56 | if ("value" in descriptor) descriptor.writable = true;
|
57 | Object.defineProperty(target, descriptor.key, descriptor);
|
58 | }
|
59 | }
|
60 |
|
61 | function _createClass(Constructor, protoProps, staticProps) {
|
62 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
63 | if (staticProps) _defineProperties(Constructor, staticProps);
|
64 | return Constructor;
|
65 | }
|
66 |
|
67 | function _possibleConstructorReturn(self, call) {
|
68 | if (call && (_typeof(call) === "object" || typeof call === "function")) {
|
69 | return call;
|
70 | }
|
71 |
|
72 | return _assertThisInitialized(self);
|
73 | }
|
74 |
|
75 | function _assertThisInitialized(self) {
|
76 | if (self === void 0) {
|
77 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
78 | }
|
79 |
|
80 | return self;
|
81 | }
|
82 |
|
83 | function _getPrototypeOf(o) {
|
84 | _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
85 | return o.__proto__ || Object.getPrototypeOf(o);
|
86 | };
|
87 | return _getPrototypeOf(o);
|
88 | }
|
89 |
|
90 | function _inherits(subClass, superClass) {
|
91 | if (typeof superClass !== "function" && superClass !== null) {
|
92 | throw new TypeError("Super expression must either be null or a function");
|
93 | }
|
94 |
|
95 | subClass.prototype = Object.create(superClass && superClass.prototype, {
|
96 | constructor: {
|
97 | value: subClass,
|
98 | writable: true,
|
99 | configurable: true
|
100 | }
|
101 | });
|
102 | if (superClass) _setPrototypeOf(subClass, superClass);
|
103 | }
|
104 |
|
105 | function _setPrototypeOf(o, p) {
|
106 | _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
107 | o.__proto__ = p;
|
108 | return o;
|
109 | };
|
110 |
|
111 | return _setPrototypeOf(o, p);
|
112 | }
|
113 |
|
114 | var toArray = function toArray(arrayLike) {
|
115 | return Array.prototype.slice.call(arrayLike);
|
116 | };
|
117 |
|
118 | var ProgressIndicator =
|
119 |
|
120 | function (_mixin) {
|
121 | _inherits(ProgressIndicator, _mixin);
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | function ProgressIndicator(element, options) {
|
140 | var _this;
|
141 |
|
142 | _classCallCheck(this, ProgressIndicator);
|
143 |
|
144 | _this = _possibleConstructorReturn(this, _getPrototypeOf(ProgressIndicator).call(this, element, options));
|
145 | |
146 |
|
147 |
|
148 |
|
149 |
|
150 | _this.state = {
|
151 | |
152 |
|
153 |
|
154 |
|
155 | currentIndex: _this.getCurrent().index,
|
156 |
|
157 | |
158 |
|
159 |
|
160 |
|
161 | totalSteps: _this.getSteps().length
|
162 | };
|
163 |
|
164 | _this.addOverflowTooltip();
|
165 |
|
166 | return _this;
|
167 | }
|
168 | |
169 |
|
170 |
|
171 |
|
172 |
|
173 | _createClass(ProgressIndicator, [{
|
174 | key: "getSteps",
|
175 | value: function getSteps() {
|
176 | return toArray(this.element.querySelectorAll(this.options.selectorStepElement)).map(function (element, index) {
|
177 | return {
|
178 | element: element,
|
179 | index: index
|
180 | };
|
181 | });
|
182 | }
|
183 | |
184 |
|
185 |
|
186 |
|
187 | }, {
|
188 | key: "getCurrent",
|
189 | value: function getCurrent() {
|
190 | var currentEl = this.element.querySelector(this.options.selectorCurrent);
|
191 | return this.getSteps().filter(function (step) {
|
192 | return step.element === currentEl;
|
193 | })[0];
|
194 | }
|
195 | |
196 |
|
197 |
|
198 |
|
199 |
|
200 | }, {
|
201 | key: "setCurrent",
|
202 | value: function setCurrent() {
|
203 | var _this2 = this;
|
204 |
|
205 | var newCurrentStep = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.currentIndex;
|
206 | var changed = false;
|
207 |
|
208 | if (newCurrentStep !== this.state.currentIndex) {
|
209 | this.state.currentIndex = newCurrentStep;
|
210 | changed = true;
|
211 | }
|
212 |
|
213 | if (changed) {
|
214 | this.getSteps().forEach(function (step) {
|
215 | if (step.index < newCurrentStep) {
|
216 | _this2._updateStep({
|
217 | element: step.element,
|
218 | className: _this2.options.classComplete,
|
219 | html: _this2._getSVGComplete()
|
220 | });
|
221 | }
|
222 |
|
223 | if (step.index === newCurrentStep) {
|
224 | _this2._updateStep({
|
225 | element: step.element,
|
226 | className: _this2.options.classCurrent,
|
227 | html: _this2._getCurrentSVG()
|
228 | });
|
229 | }
|
230 |
|
231 | if (step.index > newCurrentStep) {
|
232 | _this2._updateStep({
|
233 | element: step.element,
|
234 | className: _this2.options.classIncomplete,
|
235 | html: _this2._getIncompleteSVG()
|
236 | });
|
237 | }
|
238 | });
|
239 | }
|
240 | }
|
241 | |
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 | }, {
|
250 | key: "_updateStep",
|
251 | value: function _updateStep(args) {
|
252 | var element = args.element,
|
253 | className = args.className,
|
254 | html = args.html;
|
255 |
|
256 | if (element.firstElementChild) {
|
257 | element.removeChild(element.firstElementChild);
|
258 | }
|
259 |
|
260 | if (!element.classList.contains(className)) {
|
261 | element.setAttribute('class', this.options.classStep);
|
262 | element.classList.add(className);
|
263 | }
|
264 |
|
265 | element.insertAdjacentHTML('afterbegin', html);
|
266 | }
|
267 | |
268 |
|
269 |
|
270 |
|
271 | }, {
|
272 | key: "_getSVGComplete",
|
273 | value: function _getSVGComplete() {
|
274 | return "<svg width=\"24px\" height=\"24px\" viewBox=\"0 0 24 24\">\n <circle cx=\"12\" cy=\"12\" r=\"12\"></circle>\n <polygon points=\"10.3 13.6 7.7 11 6.3 12.4 10.3 16.4 17.8 9 16.4 7.6\"></polygon>\n </svg>";
|
275 | }
|
276 | |
277 |
|
278 |
|
279 |
|
280 | }, {
|
281 | key: "_getCurrentSVG",
|
282 | value: function _getCurrentSVG() {
|
283 | return "<svg>\n <circle cx=\"12\" cy=\"12\" r=\"12\"></circle>\n <circle cx=\"12\" cy=\"12\" r=\"6\"></circle>\n </svg>";
|
284 | }
|
285 | |
286 |
|
287 |
|
288 |
|
289 | }, {
|
290 | key: "_getIncompleteSVG",
|
291 | value: function _getIncompleteSVG() {
|
292 | return "<svg>\n <circle cx=\"12\" cy=\"12\" r=\"12\"></circle>\n </svg>";
|
293 | }
|
294 | }, {
|
295 | key: "addOverflowTooltip",
|
296 | value: function addOverflowTooltip() {
|
297 | var _this3 = this;
|
298 |
|
299 | var stepLabels = toArray(this.element.querySelectorAll(this.options.selectorLabel));
|
300 | var tooltips = toArray(this.element.querySelectorAll(this.options.selectorTooltip));
|
301 | stepLabels.forEach(function (step) {
|
302 | if (step.scrollWidth > _this3.options.maxWidth) {
|
303 | step.classList.add(_this3.options.classOverflowLabel);
|
304 | }
|
305 | });
|
306 | tooltips.forEach(function (tooltip) {
|
307 | var childText = tooltip.querySelector(_this3.options.selectorTooltipText);
|
308 |
|
309 | if (childText.scrollHeight > _this3.options.tooltipMaxHeight) {
|
310 | tooltip.classList.add(_this3.options.classTooltipMulti);
|
311 | }
|
312 | });
|
313 | }
|
314 | }], [{
|
315 | key: "options",
|
316 |
|
317 | |
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | get: function get() {
|
335 | var prefix = _settings.default.prefix;
|
336 | return {
|
337 | selectorInit: '[data-progress]',
|
338 | selectorStepElement: ".".concat(prefix, "--progress-step"),
|
339 | selectorCurrent: ".".concat(prefix, "--progress-step--current"),
|
340 | selectorIncomplete: ".".concat(prefix, "--progress-step--incomplete"),
|
341 | selectorComplete: ".".concat(prefix, "--progress-step--complete"),
|
342 | selectorLabel: ".".concat(prefix, "--progress-label"),
|
343 | selectorTooltip: ".".concat(prefix, "--tooltip"),
|
344 | selectorTooltipText: ".".concat(prefix, "--tooltip__text"),
|
345 | classStep: "".concat(prefix, "--progress-step"),
|
346 | classComplete: "".concat(prefix, "--progress-step--complete"),
|
347 | classCurrent: "".concat(prefix, "--progress-step--current"),
|
348 | classIncomplete: "".concat(prefix, "--progress-step--incomplete"),
|
349 | classOverflowLabel: "".concat(prefix, "--progress-label-overflow"),
|
350 | classTooltipMulti: "".concat(prefix, "--tooltip_multi"),
|
351 | maxWidth: 87,
|
352 | tooltipMaxHeight: 21
|
353 | };
|
354 | }
|
355 | }]);
|
356 |
|
357 | ProgressIndicator.components = new WeakMap();
|
358 | return ProgressIndicator;
|
359 | }((0, _mixin2.default)(_createComponent.default, _initComponentBySearch.default));
|
360 |
|
361 | var _default = ProgressIndicator;
|
362 | _exports.default = _default;
|
363 | }); |
\ | No newline at end of file |