1 | "use strict";
|
2 |
|
3 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4 |
|
5 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
6 |
|
7 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
8 |
|
9 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | (function (factory) {
|
22 | if (typeof define === 'function' && define.amd) {
|
23 |
|
24 | define(['jquery'], factory);
|
25 | } else if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === 'object' && module.exports) {
|
26 |
|
27 | module.exports = function (root, jQuery) {
|
28 | if (jQuery === undefined) {
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | if (typeof window !== 'undefined') {
|
34 | jQuery = require('jquery');
|
35 | } else {
|
36 | jQuery = require('jquery')(root);
|
37 | }
|
38 | }
|
39 |
|
40 | factory(jQuery);
|
41 | return jQuery;
|
42 | };
|
43 | } else {
|
44 |
|
45 | factory(jQuery);
|
46 | }
|
47 | })(function ($) {
|
48 | "use strict";
|
49 |
|
50 | var defaults = {
|
51 | selected: 0,
|
52 |
|
53 | theme: 'basic',
|
54 |
|
55 | justified: true,
|
56 |
|
57 | autoAdjustHeight: true,
|
58 |
|
59 | backButtonSupport: true,
|
60 |
|
61 | enableUrlHash: true,
|
62 |
|
63 | transition: {
|
64 | animation: 'none',
|
65 |
|
66 | speed: '400',
|
67 |
|
68 | easing: '',
|
69 |
|
70 | prefixCss: '',
|
71 |
|
72 | fwdShowCss: '',
|
73 |
|
74 | fwdHideCss: '',
|
75 |
|
76 | bckShowCss: '',
|
77 |
|
78 | bckHideCss: ''
|
79 |
|
80 | },
|
81 | toolbar: {
|
82 | position: 'bottom',
|
83 |
|
84 | showNextButton: true,
|
85 |
|
86 | showPreviousButton: true,
|
87 |
|
88 | extraHtml: ''
|
89 |
|
90 | },
|
91 | anchor: {
|
92 | enableNavigation: true,
|
93 |
|
94 | enableNavigationAlways: false,
|
95 |
|
96 | enableDoneState: true,
|
97 |
|
98 | markPreviousStepsAsDone: true,
|
99 |
|
100 | unDoneOnBackNavigation: false,
|
101 |
|
102 | enableDoneStateNavigation: true
|
103 |
|
104 | },
|
105 | keyboard: {
|
106 | keyNavigation: true,
|
107 |
|
108 | keyLeft: [37],
|
109 |
|
110 | keyRight: [39]
|
111 |
|
112 | },
|
113 | lang: {
|
114 |
|
115 | next: 'Next',
|
116 | previous: 'Previous'
|
117 | },
|
118 | style: {
|
119 |
|
120 | mainCss: 'sw',
|
121 | navCss: 'nav',
|
122 | navLinkCss: 'nav-link',
|
123 | contentCss: 'tab-content',
|
124 | contentPanelCss: 'tab-pane',
|
125 | themePrefixCss: 'sw-theme-',
|
126 | anchorDefaultCss: 'default',
|
127 | anchorDoneCss: 'done',
|
128 | anchorActiveCss: 'active',
|
129 | anchorDisabledCss: 'disabled',
|
130 | anchorHiddenCss: 'hidden',
|
131 | anchorErrorCss: 'error',
|
132 | anchorWarningCss: 'warning',
|
133 | justifiedCss: 'sw-justified',
|
134 | btnCss: 'sw-btn',
|
135 | btnNextCss: 'sw-btn-next',
|
136 | btnPrevCss: 'sw-btn-prev',
|
137 | loaderCss: 'sw-loading',
|
138 | progressCss: 'progress',
|
139 | progressBarCss: 'progress-bar',
|
140 | toolbarCss: 'toolbar',
|
141 | toolbarPrefixCss: 'toolbar-'
|
142 | },
|
143 | disabledSteps: [],
|
144 |
|
145 | errorSteps: [],
|
146 |
|
147 | warningSteps: [],
|
148 |
|
149 | hiddenSteps: [],
|
150 |
|
151 | getContent: null
|
152 |
|
153 | };
|
154 |
|
155 | var SmartWizard = function () {
|
156 | function SmartWizard(element, options) {
|
157 | var _this = this;
|
158 |
|
159 | _classCallCheck(this, SmartWizard);
|
160 |
|
161 |
|
162 | this.options = $.extend(true, {}, defaults, options);
|
163 |
|
164 | this.main = $(element);
|
165 |
|
166 | this.nav = this._getFirstDescendant('.' + this.options.style.navCss);
|
167 |
|
168 | this.container = this._getFirstDescendant('.' + this.options.style.contentCss);
|
169 |
|
170 | this.steps = this.nav.find('.' + this.options.style.navLinkCss);
|
171 |
|
172 | this.pages = this.container.children('.' + this.options.style.contentPanelCss);
|
173 |
|
174 | this.progressbar = this.main.find('.' + this.options.style.progressCss);
|
175 |
|
176 | this.dir = this._getDir();
|
177 |
|
178 | this.current_index = -1;
|
179 |
|
180 | this.is_init = false;
|
181 |
|
182 | this._init();
|
183 |
|
184 |
|
185 | setTimeout(function () {
|
186 | _this._load();
|
187 | }, 0);
|
188 | }
|
189 |
|
190 |
|
191 | _createClass(SmartWizard, [{
|
192 | key: "_init",
|
193 | value: function _init() {
|
194 |
|
195 | this._setElements();
|
196 |
|
197 |
|
198 | this._setToolbar();
|
199 |
|
200 |
|
201 | if (this.is_init === true) return true;
|
202 |
|
203 | this._setEvents();
|
204 |
|
205 | this.is_init = true;
|
206 |
|
207 | this._triggerEvent("initialized");
|
208 | }
|
209 |
|
210 | }, {
|
211 | key: "_load",
|
212 | value: function _load() {
|
213 |
|
214 | this.pages.hide();
|
215 |
|
216 | this.steps.removeClass([this.options.style.anchorDoneCss, this.options.style.anchorActiveCss]);
|
217 |
|
218 | this.current_index = -1;
|
219 |
|
220 | var idx = this._getURLHashIndex();
|
221 |
|
222 | idx = idx !== false ? idx : this.options.selected;
|
223 |
|
224 | var idxShowable = this._getShowable(idx - 1, 'forward');
|
225 |
|
226 | idx = idxShowable === null && idx > 0 ? this._getShowable(-1, 'forward') : idxShowable;
|
227 |
|
228 | if (idx > 0 && this.options.anchor.enableDoneState && this.options.anchor.markPreviousStepsAsDone) {
|
229 | this.steps.slice(0, idx).addClass(this.options.style.anchorDoneCss);
|
230 | }
|
231 |
|
232 |
|
233 | this._showStep(idx);
|
234 |
|
235 |
|
236 | this._triggerEvent("loaded");
|
237 | }
|
238 | }, {
|
239 | key: "_getFirstDescendant",
|
240 | value: function _getFirstDescendant(selector) {
|
241 |
|
242 | var elm = this.main.children(selector);
|
243 |
|
244 | if (elm.length > 0) {
|
245 | return elm;
|
246 | }
|
247 |
|
248 |
|
249 | this.main.children().each(function (i, n) {
|
250 | var tmp = $(n).children(selector);
|
251 |
|
252 | if (tmp.length > 0) {
|
253 | elm = tmp;
|
254 | return false;
|
255 | }
|
256 | });
|
257 |
|
258 | if (elm.length > 0) {
|
259 | return elm;
|
260 | }
|
261 |
|
262 |
|
263 | this._showError("Element not found " + selector);
|
264 |
|
265 | return false;
|
266 | }
|
267 | }, {
|
268 | key: "_getDir",
|
269 | value: function _getDir() {
|
270 | var dir = this.main.prop('dir');
|
271 |
|
272 | if (dir.length === 0) {
|
273 | dir = document.documentElement.dir;
|
274 |
|
275 | this.main.prop('dir', dir);
|
276 | }
|
277 |
|
278 | return dir;
|
279 | }
|
280 | }, {
|
281 | key: "_setElements",
|
282 | value: function _setElements() {
|
283 | var _this2 = this;
|
284 |
|
285 |
|
286 | this.main.removeClass(function (i, className) {
|
287 | return (className.match(new RegExp('(^|\\s)' + _this2.options.style.themePrefixCss + '\\S+', 'g')) || []).join(' ');
|
288 | }).addClass(this.options.style.mainCss + ' ' + this.options.style.themePrefixCss + this.options.theme);
|
289 |
|
290 | this.main.toggleClass(this.options.style.justifiedCss, this.options.justified);
|
291 |
|
292 | if (this.options.anchor.enableNavigationAlways !== true || this.options.anchor.enableNavigation !== true) {
|
293 | this.steps.addClass(this.options.style.anchorDefaultCss);
|
294 | }
|
295 |
|
296 |
|
297 | $.each(this.options.disabledSteps, function (i, n) {
|
298 | _this2.steps.eq(n).addClass(_this2.options.style.anchorDisabledCss);
|
299 | });
|
300 |
|
301 | $.each(this.options.errorSteps, function (i, n) {
|
302 | _this2.steps.eq(n).addClass(_this2.options.style.anchorErrorCss);
|
303 | });
|
304 |
|
305 | $.each(this.options.warningSteps, function (i, n) {
|
306 | _this2.steps.eq(n).addClass(_this2.options.style.anchorWarningCss);
|
307 | });
|
308 |
|
309 | $.each(this.options.hiddenSteps, function (i, n) {
|
310 | _this2.steps.eq(n).addClass(_this2.options.style.anchorHiddenCss);
|
311 | });
|
312 | }
|
313 | }, {
|
314 | key: "_setEvents",
|
315 | value: function _setEvents() {
|
316 | var _this3 = this;
|
317 |
|
318 |
|
319 | this.steps.on("click", function (e) {
|
320 | e.preventDefault();
|
321 |
|
322 | if (_this3.options.anchor.enableNavigation !== true) {
|
323 | return;
|
324 | }
|
325 |
|
326 | var elm = $(e.currentTarget);
|
327 |
|
328 | if (_this3._isShowable(elm)) {
|
329 |
|
330 | _this3._showStep(_this3.steps.index(elm));
|
331 | }
|
332 | });
|
333 |
|
334 | this.main.on("click", function (e) {
|
335 | if ($(e.target).hasClass(_this3.options.style.btnNextCss)) {
|
336 | e.preventDefault();
|
337 |
|
338 | _this3._navigate('next');
|
339 | } else if ($(e.target).hasClass(_this3.options.style.btnPrevCss)) {
|
340 | e.preventDefault();
|
341 |
|
342 | _this3._navigate('prev');
|
343 | }
|
344 |
|
345 | return;
|
346 | });
|
347 |
|
348 | $(document).keyup(function (e) {
|
349 | _this3._keyNav(e);
|
350 | });
|
351 |
|
352 | $(window).on('hashchange', function (e) {
|
353 | if (_this3.options.backButtonSupport !== true) {
|
354 | return;
|
355 | }
|
356 |
|
357 | var idx = _this3._getURLHashIndex();
|
358 |
|
359 | if (idx !== false && _this3._isShowable(_this3.steps.eq(idx))) {
|
360 | e.preventDefault();
|
361 |
|
362 | _this3._showStep(idx);
|
363 | }
|
364 | });
|
365 |
|
366 | $(window).on('resize', function (e) {
|
367 | _this3._fixHeight(_this3.current_index);
|
368 | });
|
369 | }
|
370 | }, {
|
371 | key: "_setToolbar",
|
372 | value: function _setToolbar() {
|
373 |
|
374 | this.main.find(".sw-toolbar-elm").remove();
|
375 | var toolbarPosition = this.options.toolbar.position;
|
376 |
|
377 | if (toolbarPosition === 'none') {
|
378 |
|
379 | return;
|
380 | } else if (toolbarPosition == 'both') {
|
381 | this.container.before(this._createToolbar('top'));
|
382 | this.container.after(this._createToolbar('bottom'));
|
383 | } else if (toolbarPosition == 'top') {
|
384 | this.container.before(this._createToolbar('top'));
|
385 | } else {
|
386 | this.container.after(this._createToolbar('bottom'));
|
387 | }
|
388 | }
|
389 | }, {
|
390 | key: "_createToolbar",
|
391 | value: function _createToolbar(position) {
|
392 | var toolbar = $('<div></div>').addClass('sw-toolbar-elm ' + this.options.style.toolbarCss + ' ' + this.options.style.toolbarPrefixCss + position).attr('role', 'toolbar');
|
393 |
|
394 | var btnNext = this.options.toolbar.showNextButton !== false ? $('<button></button>').text(this.options.lang.next).addClass('btn ' + this.options.style.btnNextCss + ' ' + this.options.style.btnCss).attr('type', 'button') : null;
|
395 | var btnPrevious = this.options.toolbar.showPreviousButton !== false ? $('<button></button>').text(this.options.lang.previous).addClass('btn ' + this.options.style.btnPrevCss + ' ' + this.options.style.btnCss).attr('type', 'button') : null;
|
396 | return toolbar.append(btnPrevious, btnNext, this.options.toolbar.extraHtml);
|
397 | }
|
398 | }, {
|
399 | key: "_navigate",
|
400 | value: function _navigate(dir) {
|
401 | this._showStep(this._getShowable(this.current_index, dir));
|
402 | }
|
403 | }, {
|
404 | key: "_showStep",
|
405 | value: function _showStep(idx) {
|
406 | var _this4 = this;
|
407 |
|
408 | if (idx === -1 || idx === null) return false;
|
409 |
|
410 | if (idx == this.current_index) return false;
|
411 |
|
412 | if (!this.steps.eq(idx)) return false;
|
413 |
|
414 | if (!this._isEnabled(this.steps.eq(idx))) return false;
|
415 |
|
416 | var stepDirection = this._getStepDirection(idx);
|
417 |
|
418 | if (this.current_index !== -1) {
|
419 |
|
420 | if (this._triggerEvent("leaveStep", [this._getStepAnchor(this.current_index), this.current_index, idx, stepDirection]) === false) {
|
421 | return false;
|
422 | }
|
423 | }
|
424 |
|
425 | this._loadContent(idx, function () {
|
426 |
|
427 | var selStep = _this4._getStepAnchor(idx);
|
428 |
|
429 |
|
430 | _this4._setURLHash(selStep.attr("href"));
|
431 |
|
432 |
|
433 | _this4._setAnchor(idx);
|
434 |
|
435 |
|
436 | var curPage = _this4._getStepPage(_this4.current_index);
|
437 |
|
438 |
|
439 | var selPage = _this4._getStepPage(idx);
|
440 |
|
441 |
|
442 | _this4._transit(selPage, curPage, stepDirection, function () {
|
443 |
|
444 | _this4._fixHeight(idx);
|
445 |
|
446 |
|
447 | _this4._triggerEvent("showStep", [selStep, idx, stepDirection, _this4._getStepPosition(idx)]);
|
448 | });
|
449 |
|
450 |
|
451 | _this4.current_index = idx;
|
452 |
|
453 | _this4._setButtons(idx);
|
454 |
|
455 |
|
456 | _this4._setProgressbar(idx);
|
457 | });
|
458 | }
|
459 | }, {
|
460 | key: "_getShowable",
|
461 | value: function _getShowable(idx, dir) {
|
462 | var _this5 = this;
|
463 |
|
464 | var si = null;
|
465 | var elmList = dir == 'prev' ? $(this.steps.slice(0, idx).get().reverse()) : this.steps.slice(idx + 1);
|
466 |
|
467 | elmList.each(function (i, elm) {
|
468 | if (_this5._isEnabled($(elm))) {
|
469 | si = dir == 'prev' ? idx - (i + 1) : i + idx + 1;
|
470 | return false;
|
471 | }
|
472 | });
|
473 | return si;
|
474 | }
|
475 | }, {
|
476 | key: "_isShowable",
|
477 | value: function _isShowable(elm) {
|
478 | if (!this._isEnabled(elm)) {
|
479 | return false;
|
480 | }
|
481 |
|
482 | var isDone = elm.hasClass(this.options.style.anchorDoneCss);
|
483 |
|
484 | if (this.options.anchor.enableDoneStateNavigation === false && isDone) {
|
485 | return false;
|
486 | }
|
487 |
|
488 | if (this.options.anchor.enableNavigationAlways === false && !isDone) {
|
489 | return false;
|
490 | }
|
491 |
|
492 | return true;
|
493 | }
|
494 | }, {
|
495 | key: "_isEnabled",
|
496 | value: function _isEnabled(elm) {
|
497 | return elm.hasClass(this.options.style.anchorDisabledCss) || elm.hasClass(this.options.style.anchorHiddenCss) ? false : true;
|
498 | }
|
499 | }, {
|
500 | key: "_getStepDirection",
|
501 | value: function _getStepDirection(idx) {
|
502 | return this.current_index < idx ? "forward" : "backward";
|
503 | }
|
504 | }, {
|
505 | key: "_getStepPosition",
|
506 | value: function _getStepPosition(idx) {
|
507 | if (idx === 0) {
|
508 | return 'first';
|
509 | } else if (idx === this.steps.length - 1) {
|
510 | return 'last';
|
511 | }
|
512 |
|
513 | return 'middle';
|
514 | }
|
515 | }, {
|
516 | key: "_getStepAnchor",
|
517 | value: function _getStepAnchor(idx) {
|
518 | if (idx == null || idx == -1) return null;
|
519 | return this.steps.eq(idx);
|
520 | }
|
521 | }, {
|
522 | key: "_getStepPage",
|
523 | value: function _getStepPage(idx) {
|
524 | if (idx == null || idx == -1) return null;
|
525 | return this.pages.eq(idx);
|
526 | }
|
527 | }, {
|
528 | key: "_loadContent",
|
529 | value: function _loadContent(idx, callback) {
|
530 | if (!$.isFunction(this.options.getContent)) {
|
531 | callback();
|
532 | return;
|
533 | }
|
534 |
|
535 | var selPage = this._getStepPage(idx);
|
536 |
|
537 | if (!selPage) {
|
538 | callback();
|
539 | return;
|
540 | }
|
541 |
|
542 |
|
543 | var stepDirection = this._getStepDirection(idx);
|
544 |
|
545 |
|
546 | var stepPosition = this._getStepPosition(idx);
|
547 |
|
548 |
|
549 | var selStep = this._getStepAnchor(idx);
|
550 |
|
551 | this.options.getContent(idx, stepDirection, stepPosition, selStep, function (content) {
|
552 | if (content) selPage.html(content);
|
553 | callback();
|
554 | });
|
555 | }
|
556 | }, {
|
557 | key: "_transit",
|
558 | value: function _transit(elmToShow, elmToHide, stepDirection, callback) {
|
559 | var transitFn = $.fn.smartWizard.transitions[this.options.transition.animation];
|
560 |
|
561 | this._stopAnimations();
|
562 |
|
563 | if ($.isFunction(transitFn)) {
|
564 | transitFn(elmToShow, elmToHide, stepDirection, this, function (res) {
|
565 | if (res === false) {
|
566 | if (elmToHide !== null) elmToHide.hide();
|
567 | elmToShow.show();
|
568 | }
|
569 |
|
570 | callback();
|
571 | });
|
572 | } else {
|
573 | if (elmToHide !== null) elmToHide.hide();
|
574 | elmToShow.show();
|
575 | callback();
|
576 | }
|
577 | }
|
578 | }, {
|
579 | key: "_stopAnimations",
|
580 | value: function _stopAnimations() {
|
581 | if ($.isFunction(this.container.finish)) {
|
582 | this.pages.finish();
|
583 | this.container.finish();
|
584 | }
|
585 | }
|
586 | }, {
|
587 | key: "_fixHeight",
|
588 | value: function _fixHeight(idx) {
|
589 | if (this.options.autoAdjustHeight === false) return;
|
590 |
|
591 | var contentHeight = this._getStepPage(idx).outerHeight();
|
592 |
|
593 | if ($.isFunction(this.container.finish) && $.isFunction(this.container.animate) && contentHeight > 0) {
|
594 | this.container.finish().animate({
|
595 | height: contentHeight
|
596 | }, this.options.transition.speed);
|
597 | } else {
|
598 | this.container.css({
|
599 | height: contentHeight > 0 ? contentHeight : 'auto'
|
600 | });
|
601 | }
|
602 | }
|
603 | }, {
|
604 | key: "_setAnchor",
|
605 | value: function _setAnchor(idx) {
|
606 |
|
607 | if (this.current_index !== null && this.current_index >= 0) {
|
608 | var removeCss = this.options.style.anchorActiveCss;
|
609 | var addCss = '';
|
610 |
|
611 | if (this.options.anchor.enableDoneState !== false) {
|
612 | addCss += this.options.style.anchorDoneCss;
|
613 |
|
614 | if (this.options.anchor.unDoneOnBackNavigation !== false && this._getStepDirection(idx) === 'backward') {
|
615 | removeCss += ' ' + this.options.style.anchorDoneCss;
|
616 | }
|
617 | }
|
618 |
|
619 | this.steps.eq(this.current_index).addClass(addCss).removeClass(removeCss);
|
620 | }
|
621 |
|
622 |
|
623 | this.steps.eq(idx).removeClass(this.options.style.anchorDoneCss).addClass(this.options.style.anchorActiveCss);
|
624 | }
|
625 | }, {
|
626 | key: "_setButtons",
|
627 | value: function _setButtons(idx) {
|
628 |
|
629 | this.main.find('.' + this.options.style.btnNextCss + ', .' + this.options.style.btnPrevCss).removeClass(this.options.style.anchorDisabledCss);
|
630 |
|
631 | var p = this._getStepPosition(idx);
|
632 |
|
633 | if (p === 'first' || p === 'last') {
|
634 | var c = p === 'first' ? '.' + this.options.style.btnPrevCss : '.' + this.options.style.btnNextCss;
|
635 | this.main.find(c).addClass(this.options.style.anchorDisabledCss);
|
636 | } else {
|
637 | if (this._getShowable(idx, 'next') === null) {
|
638 | this.main.find('.' + this.options.style.btnNextCss).addClass(this.options.style.anchorDisabledCss);
|
639 | }
|
640 |
|
641 | if (this._getShowable(idx, 'prev') === null) {
|
642 | this.main.find('.' + this.options.style.btnPrevCss).addClass(this.options.style.anchorDisabledCss);
|
643 | }
|
644 | }
|
645 | }
|
646 | }, {
|
647 | key: "_setProgressbar",
|
648 | value: function _setProgressbar(idx) {
|
649 | var width = this.nav.width();
|
650 | var widthPercentage = width / this.steps.length * (idx + 1) / width * 100;
|
651 |
|
652 | document.documentElement.style.setProperty('--sw-progress-width', widthPercentage + '%');
|
653 |
|
654 | if (this.progressbar.length > 0) {
|
655 | this.progressbar.find('.' + this.options.style.progressBarCss).css('width', widthPercentage + '%');
|
656 | }
|
657 | }
|
658 |
|
659 | }, {
|
660 | key: "_keyNav",
|
661 | value: function _keyNav(e) {
|
662 | if (!this.options.keyboard.keyNavigation) {
|
663 | return;
|
664 | }
|
665 |
|
666 |
|
667 | if ($.inArray(e.which, this.options.keyboard.keyLeft) > -1) {
|
668 |
|
669 | this._navigate('prev');
|
670 |
|
671 | e.preventDefault();
|
672 | } else if ($.inArray(e.which, this.options.keyboard.keyRight) > -1) {
|
673 |
|
674 | this._navigate('next');
|
675 |
|
676 | e.preventDefault();
|
677 | } else {
|
678 | return;
|
679 | }
|
680 | }
|
681 | }, {
|
682 | key: "_triggerEvent",
|
683 | value: function _triggerEvent(name, params) {
|
684 |
|
685 | var e = $.Event(name);
|
686 | this.main.trigger(e, params);
|
687 |
|
688 | if (e.isDefaultPrevented()) {
|
689 | return false;
|
690 | }
|
691 |
|
692 | return e.result;
|
693 | }
|
694 | }, {
|
695 | key: "_setURLHash",
|
696 | value: function _setURLHash(hash) {
|
697 | if (this.options.enableUrlHash && window.location.hash !== hash) {
|
698 | history.pushState(null, null, hash);
|
699 | }
|
700 | }
|
701 | }, {
|
702 | key: "_getURLHashIndex",
|
703 | value: function _getURLHashIndex() {
|
704 | if (this.options.enableUrlHash) {
|
705 |
|
706 | var hash = window.location.hash;
|
707 |
|
708 | if (hash.length > 0) {
|
709 | var elm = this.nav.find("a[href*='" + hash + "']");
|
710 |
|
711 | if (elm.length > 0) {
|
712 | return this.steps.index(elm);
|
713 | }
|
714 | }
|
715 | }
|
716 |
|
717 | return false;
|
718 | }
|
719 | }, {
|
720 | key: "_showError",
|
721 | value: function _showError(msg) {
|
722 | console.error(msg);
|
723 | }
|
724 | }, {
|
725 | key: "_changeState",
|
726 | value: function _changeState(stepArray, state, addOrRemove) {
|
727 | var _this6 = this;
|
728 |
|
729 |
|
730 | addOrRemove = addOrRemove !== false ? true : false;
|
731 | var css = '';
|
732 |
|
733 | if (state == 'default') {
|
734 | css = this.options.style.anchorDefaultCss;
|
735 | } else if (state == 'active') {
|
736 | css = this.options.style.anchorActiveCss;
|
737 | } else if (state == 'done') {
|
738 | css = this.options.style.anchorDoneCss;
|
739 | } else if (state == 'disable') {
|
740 | css = this.options.style.anchorDisabledCss;
|
741 | } else if (state == 'hidden') {
|
742 | css = this.options.style.anchorHiddenCss;
|
743 | } else if (state == 'error') {
|
744 | css = this.options.style.anchorErrorCss;
|
745 | } else if (state == 'warning') {
|
746 | css = this.options.style.anchorWarningCss;
|
747 | }
|
748 |
|
749 | $.each(stepArray, function (i, n) {
|
750 | _this6.steps.eq(n).toggleClass(css, addOrRemove);
|
751 | });
|
752 | }
|
753 |
|
754 | }, {
|
755 | key: "goToStep",
|
756 | value: function goToStep(stepIndex, force) {
|
757 | force = force !== false ? true : false;
|
758 |
|
759 | if (force !== true && !this._isShowable(this.steps.eq(stepIndex))) {
|
760 | return;
|
761 | }
|
762 |
|
763 |
|
764 | if (force === true && stepIndex > 0 && this.options.anchor.enableDoneState && this.options.anchor.markPreviousStepsAsDone) {
|
765 | this.steps.slice(0, stepIndex).addClass(this.options.style.anchorDoneCss);
|
766 | }
|
767 |
|
768 | this._showStep(stepIndex);
|
769 | }
|
770 | }, {
|
771 | key: "next",
|
772 | value: function next() {
|
773 | this._navigate('next');
|
774 | }
|
775 | }, {
|
776 | key: "prev",
|
777 | value: function prev() {
|
778 | this._navigate('prev');
|
779 | }
|
780 | }, {
|
781 | key: "reset",
|
782 | value: function reset() {
|
783 |
|
784 | this.steps.removeClass([this.options.style.anchorDoneCss, this.options.style.anchorActiveCss, this.options.style.anchorErrorCss, this.options.style.anchorWarningCss]);
|
785 |
|
786 | this._setURLHash('#');
|
787 |
|
788 | this._init();
|
789 |
|
790 | this._load();
|
791 | }
|
792 | }, {
|
793 | key: "setState",
|
794 | value: function setState(stepArray, state) {
|
795 | this._changeState(stepArray, state, true);
|
796 | }
|
797 | }, {
|
798 | key: "unsetState",
|
799 | value: function unsetState(stepArray, state) {
|
800 | this._changeState(stepArray, state, false);
|
801 | }
|
802 | }, {
|
803 | key: "setOptions",
|
804 | value: function setOptions(options) {
|
805 | this.options = $.extend(true, {}, this.options, options);
|
806 |
|
807 | this._init();
|
808 | }
|
809 | }, {
|
810 | key: "getOptions",
|
811 | value: function getOptions() {
|
812 | return this.options;
|
813 | }
|
814 | }, {
|
815 | key: "getStepInfo",
|
816 | value: function getStepInfo() {
|
817 | return {
|
818 | currentStep: this.current_index ? this.current_index : 0,
|
819 | totalSteps: this.steps ? this.steps.length : 0
|
820 | };
|
821 | }
|
822 | }, {
|
823 | key: "loader",
|
824 | value: function loader(state) {
|
825 | this.main.toggleClass(this.options.style.loaderCss, state === "show");
|
826 | }
|
827 | }, {
|
828 | key: "fixHeight",
|
829 | value: function fixHeight() {
|
830 | this._fixHeight(this.current_index);
|
831 | }
|
832 | }]);
|
833 |
|
834 | return SmartWizard;
|
835 | }();
|
836 |
|
837 |
|
838 | $.fn.smartWizard = function (options) {
|
839 | if (options === undefined || _typeof(options) === 'object') {
|
840 | return this.each(function () {
|
841 | if (!$.data(this, "smartWizard")) {
|
842 | $.data(this, "smartWizard", new SmartWizard(this, options));
|
843 | }
|
844 | });
|
845 | } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
|
846 | var instance = $.data(this[0], 'smartWizard');
|
847 |
|
848 | if (options === 'destroy') {
|
849 | $.data(this, 'smartWizard', null);
|
850 | }
|
851 |
|
852 | if (instance instanceof SmartWizard && typeof instance[options] === 'function') {
|
853 | return instance[options].apply(instance, Array.prototype.slice.call(arguments, 1));
|
854 | } else {
|
855 | return this;
|
856 | }
|
857 | }
|
858 | };
|
859 |
|
860 |
|
861 | $.fn.smartWizard.transitions = {
|
862 | fade: function fade(elmToShow, elmToHide, stepDirection, wizardObj, callback) {
|
863 | if (!$.isFunction(elmToShow.fadeOut)) {
|
864 | callback(false);
|
865 | return;
|
866 | }
|
867 |
|
868 | if (elmToHide) {
|
869 | elmToHide.fadeOut(wizardObj.options.transition.speed, wizardObj.options.transition.easing, function () {
|
870 | elmToShow.fadeIn(wizardObj.options.transition.speed, wizardObj.options.transition.easing, function () {
|
871 | callback();
|
872 | });
|
873 | });
|
874 | } else {
|
875 | elmToShow.fadeIn(wizardObj.options.transition.speed, wizardObj.options.transition.easing, function () {
|
876 | callback();
|
877 | });
|
878 | }
|
879 | },
|
880 | slideSwing: function slideSwing(elmToShow, elmToHide, stepDirection, wizardObj, callback) {
|
881 | if (!$.isFunction(elmToShow.slideDown)) {
|
882 | callback(false);
|
883 | return;
|
884 | }
|
885 |
|
886 | if (elmToHide) {
|
887 | elmToHide.slideUp(wizardObj.options.transition.speed, wizardObj.options.transition.easing, function () {
|
888 | elmToShow.slideDown(wizardObj.options.transition.speed, wizardObj.options.transition.easing, function () {
|
889 | callback();
|
890 | });
|
891 | });
|
892 | } else {
|
893 | elmToShow.slideDown(wizardObj.options.transition.speed, wizardObj.options.transition.easing, function () {
|
894 | callback();
|
895 | });
|
896 | }
|
897 | },
|
898 | slideHorizontal: function slideHorizontal(elmToShow, elmToHide, stepDirection, wizardObj, callback) {
|
899 | if (!$.isFunction(elmToShow.animate)) {
|
900 | callback(false);
|
901 | return;
|
902 | }
|
903 |
|
904 |
|
905 | var animFn = function animFn(elm, iniLeft, finLeft, cb) {
|
906 | elm.css({
|
907 | position: 'absolute',
|
908 | left: iniLeft
|
909 | }).show().animate({
|
910 | left: finLeft
|
911 | }, wizardObj.options.transition.speed, wizardObj.options.transition.easing, cb);
|
912 | };
|
913 |
|
914 | if (wizardObj.current_index == -1) {
|
915 |
|
916 | wizardObj.container.height(elmToShow.outerHeight());
|
917 | }
|
918 |
|
919 | var containerWidth = wizardObj.container.width();
|
920 |
|
921 | if (elmToHide) {
|
922 | var initCss1 = elmToHide.css(["position", "left"]);
|
923 | var finLeft = containerWidth * (stepDirection == 'backward' ? 1 : -1);
|
924 | animFn(elmToHide, 0, finLeft, function () {
|
925 | elmToHide.hide().css(initCss1);
|
926 | });
|
927 | }
|
928 |
|
929 | var initCss2 = elmToShow.css(["position"]);
|
930 | var iniLeft = containerWidth * (stepDirection == 'backward' ? -2 : 1);
|
931 | animFn(elmToShow, iniLeft, 0, function () {
|
932 | elmToShow.css(initCss2);
|
933 | callback();
|
934 | });
|
935 | },
|
936 | slideVertical: function slideVertical(elmToShow, elmToHide, stepDirection, wizardObj, callback) {
|
937 | if (!$.isFunction(elmToShow.animate)) {
|
938 | callback(false);
|
939 | return;
|
940 | }
|
941 |
|
942 |
|
943 | var animFn = function animFn(elm, iniTop, finTop, cb) {
|
944 | elm.css({
|
945 | position: 'absolute',
|
946 | top: iniTop
|
947 | }).show().animate({
|
948 | top: finTop
|
949 | }, wizardObj.options.transition.speed, wizardObj.options.transition.easing, cb);
|
950 | };
|
951 |
|
952 | if (wizardObj.current_index == -1) {
|
953 |
|
954 | wizardObj.container.height(elmToShow.outerHeight());
|
955 | }
|
956 |
|
957 | var containerHeight = wizardObj.container.height();
|
958 |
|
959 | if (elmToHide) {
|
960 | var initCss1 = elmToHide.css(["position", "top"]);
|
961 | var finTop = containerHeight * (stepDirection == 'backward' ? -1 : 1);
|
962 | animFn(elmToHide, 0, finTop, function () {
|
963 | elmToHide.hide().css(initCss1);
|
964 | });
|
965 | }
|
966 |
|
967 | var initCss2 = elmToShow.css(["position"]);
|
968 | var iniTop = containerHeight * (stepDirection == 'backward' ? 1 : -2);
|
969 | animFn(elmToShow, iniTop, 0, function () {
|
970 | elmToShow.css(initCss2);
|
971 | callback();
|
972 | });
|
973 | },
|
974 | css: function css(elmToShow, elmToHide, stepDirection, wizardObj, callback) {
|
975 | if (wizardObj.options.transition.fwdHideCss.length == 0 || wizardObj.options.transition.bckHideCss.length == 0) {
|
976 | callback(false);
|
977 | return;
|
978 | }
|
979 |
|
980 |
|
981 | var animFn = function animFn(elm, animation, cb) {
|
982 | if (!animation || animation.length == 0) cb();
|
983 | elm.addClass(animation).one("animationend", function (e) {
|
984 | $(e.currentTarget).removeClass(animation);
|
985 | cb();
|
986 | });
|
987 | elm.addClass(animation).one("animationcancel", function (e) {
|
988 | $(e.currentTarget).removeClass(animation);
|
989 | cb('cancel');
|
990 | });
|
991 | };
|
992 |
|
993 | var showCss = wizardObj.options.transition.prefixCss + ' ' + (stepDirection == 'backward' ? wizardObj.options.transition.bckShowCss : wizardObj.options.transition.fwdShowCss);
|
994 |
|
995 | if (elmToHide) {
|
996 | var hideCss = wizardObj.options.transition.prefixCss + ' ' + (stepDirection == 'backward' ? wizardObj.options.transition.bckHideCss : wizardObj.options.transition.fwdHideCss);
|
997 | animFn(elmToHide, hideCss, function () {
|
998 | elmToHide.hide();
|
999 | animFn(elmToShow, showCss, function () {
|
1000 | callback();
|
1001 | });
|
1002 | elmToShow.show();
|
1003 | });
|
1004 | } else {
|
1005 | animFn(elmToShow, showCss, function () {
|
1006 | callback();
|
1007 | });
|
1008 | elmToShow.show();
|
1009 | }
|
1010 | }
|
1011 | };
|
1012 | }); |
\ | No newline at end of file |