jquery-wizard.js 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. /**
  2. * jQuery wizard v0.4.4
  3. * https://github.com/amazingSurge/jquery-wizard
  4. *
  5. * Copyright (c) amazingSurge
  6. * Released under the LGPL-3.0 license
  7. */
  8. (function(global, factory) {
  9. if (typeof define === 'function' && define.amd) {
  10. define(['jquery'], factory);
  11. } else if (typeof exports !== 'undefined') {
  12. factory(require('jquery'));
  13. } else {
  14. var mod = {
  15. exports: {}
  16. };
  17. factory(global.jQuery);
  18. global.jqueryWizardEs = mod.exports;
  19. }
  20. })(this, function(_jquery) {
  21. 'use strict';
  22. var _jquery2 = _interopRequireDefault(_jquery);
  23. function _interopRequireDefault(obj) {
  24. return obj && obj.__esModule
  25. ? obj
  26. : {
  27. default: obj
  28. };
  29. }
  30. function _toConsumableArray(arr) {
  31. if (Array.isArray(arr)) {
  32. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
  33. arr2[i] = arr[i];
  34. }
  35. return arr2;
  36. } else {
  37. return Array.from(arr);
  38. }
  39. }
  40. var _typeof =
  41. typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'
  42. ? function(obj) {
  43. return typeof obj;
  44. }
  45. : function(obj) {
  46. return obj &&
  47. typeof Symbol === 'function' &&
  48. obj.constructor === Symbol &&
  49. obj !== Symbol.prototype
  50. ? 'symbol'
  51. : typeof obj;
  52. };
  53. function _classCallCheck(instance, Constructor) {
  54. if (!(instance instanceof Constructor)) {
  55. throw new TypeError('Cannot call a class as a function');
  56. }
  57. }
  58. var _createClass = (function() {
  59. function defineProperties(target, props) {
  60. for (var i = 0; i < props.length; i++) {
  61. var descriptor = props[i];
  62. descriptor.enumerable = descriptor.enumerable || false;
  63. descriptor.configurable = true;
  64. if ('value' in descriptor) descriptor.writable = true;
  65. Object.defineProperty(target, descriptor.key, descriptor);
  66. }
  67. }
  68. return function(Constructor, protoProps, staticProps) {
  69. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  70. if (staticProps) defineProperties(Constructor, staticProps);
  71. return Constructor;
  72. };
  73. })();
  74. /*eslint no-unused-vars: "off"*/
  75. /*eslint no-empty-function: "off"*/
  76. var DEFAULTS = {
  77. step: '.wizard-steps > li',
  78. getPane: function getPane(index, step) {
  79. return this.$element
  80. .find('.wizard-content')
  81. .children()
  82. .eq(index);
  83. },
  84. buttonsAppendTo: 'this',
  85. templates: {
  86. buttons: function buttons() {
  87. var options = this.options;
  88. return (
  89. '<div class="wizard-buttons"><a class="wizard-back" href="#' +
  90. this.id +
  91. '" data-wizard="back" role="button">' +
  92. options.buttonLabels.back +
  93. '</a><a class="wizard-next" href="#' +
  94. this.id +
  95. '" data-wizard="next" role="button">' +
  96. options.buttonLabels.next +
  97. '</a><a class="wizard-finish" href="#' +
  98. this.id +
  99. '" data-wizard="finish" role="button">' +
  100. options.buttonLabels.finish +
  101. '</a></div>'
  102. );
  103. }
  104. },
  105. classes: {
  106. step: {
  107. done: 'done',
  108. error: 'error',
  109. active: 'current',
  110. disabled: 'disabled',
  111. activing: 'activing',
  112. loading: 'loading'
  113. },
  114. pane: {
  115. active: 'active',
  116. activing: 'activing'
  117. },
  118. button: {
  119. hide: 'hide',
  120. disabled: 'disabled'
  121. }
  122. },
  123. autoFocus: true,
  124. keyboard: true,
  125. enableWhenVisited: false,
  126. buttonLabels: {
  127. next: 'Next',
  128. back: 'Back',
  129. finish: 'Finish'
  130. },
  131. loading: {
  132. show: function show(step) {},
  133. hide: function hide(step) {},
  134. fail: function fail(step) {}
  135. },
  136. cacheContent: false,
  137. validator: function validator(step) {
  138. return true;
  139. },
  140. onInit: null,
  141. onNext: null,
  142. onBack: null,
  143. onReset: null,
  144. onBeforeShow: null,
  145. onAfterShow: null,
  146. onBeforeHide: null,
  147. onAfterHide: null,
  148. onBeforeLoad: null,
  149. onAfterLoad: null,
  150. onBeforeChange: null,
  151. onAfterChange: null,
  152. onStateChange: null,
  153. onFinish: null
  154. };
  155. /**
  156. * Css features detect
  157. **/
  158. var support = {};
  159. (function(support) {
  160. /**
  161. * Borrowed from Owl carousel
  162. **/
  163. var events = {
  164. transition: {
  165. end: {
  166. WebkitTransition: 'webkitTransitionEnd',
  167. MozTransition: 'transitionend',
  168. OTransition: 'oTransitionEnd',
  169. transition: 'transitionend'
  170. }
  171. },
  172. animation: {
  173. end: {
  174. WebkitAnimation: 'webkitAnimationEnd',
  175. MozAnimation: 'animationend',
  176. OAnimation: 'oAnimationEnd',
  177. animation: 'animationend'
  178. }
  179. }
  180. },
  181. prefixes = ['webkit', 'Moz', 'O', 'ms'],
  182. style = (0, _jquery2.default)('<support>').get(0).style,
  183. tests = {
  184. csstransitions: function csstransitions() {
  185. return Boolean(test('transition'));
  186. },
  187. cssanimations: function cssanimations() {
  188. return Boolean(test('animation'));
  189. }
  190. };
  191. var test = function test(property, prefixed) {
  192. var result = false,
  193. upper = property.charAt(0).toUpperCase() + property.slice(1);
  194. if (style[property] !== undefined) {
  195. result = property;
  196. }
  197. if (!result) {
  198. _jquery2.default.each(prefixes, function(i, prefix) {
  199. if (style[prefix + upper] !== undefined) {
  200. result = '-' + prefix.toLowerCase() + '-' + upper;
  201. return false;
  202. }
  203. return true;
  204. });
  205. }
  206. if (prefixed) {
  207. return result;
  208. }
  209. if (result) {
  210. return true;
  211. }
  212. return false;
  213. };
  214. var prefixed = function prefixed(property) {
  215. return test(property, true);
  216. };
  217. if (tests.csstransitions()) {
  218. /*eslint no-new-wrappers: "off"*/
  219. support.transition = new String(prefixed('transition'));
  220. support.transition.end = events.transition.end[support.transition];
  221. }
  222. if (tests.cssanimations()) {
  223. /*eslint no-new-wrappers: "off"*/
  224. support.animation = new String(prefixed('animation'));
  225. support.animation.end = events.animation.end[support.animation];
  226. }
  227. })(support);
  228. function emulateTransitionEnd($el, duration) {
  229. 'use strict';
  230. var called = false;
  231. $el.one(support.transition.end, function() {
  232. called = true;
  233. });
  234. var callback = function callback() {
  235. if (!called) {
  236. $el.trigger(support.transition.end);
  237. }
  238. };
  239. setTimeout(callback, duration);
  240. }
  241. var Step = (function() {
  242. function Step(element, wizard, index) {
  243. _classCallCheck(this, Step);
  244. this.TRANSITION_DURATION = 200;
  245. this.initialize(element, wizard, index);
  246. }
  247. _createClass(Step, [
  248. {
  249. key: 'initialize',
  250. value: function initialize(element, wizard, index) {
  251. this.$element = (0, _jquery2.default)(element);
  252. this.wizard = wizard;
  253. this.events = {};
  254. this.loader = null;
  255. this.loaded = false;
  256. this.validator = this.wizard.options.validator;
  257. this.states = {
  258. done: false,
  259. error: false,
  260. active: false,
  261. disabled: false,
  262. activing: false
  263. };
  264. this.index = index;
  265. this.$element.data('wizard-index', index);
  266. this.$pane = this.getPaneFromTarget();
  267. if (!this.$pane) {
  268. this.$pane = this.wizard.options.getPane.call(
  269. this.wizard,
  270. index,
  271. element
  272. );
  273. }
  274. this.setValidatorFromData();
  275. this.setLoaderFromData();
  276. }
  277. },
  278. {
  279. key: 'getPaneFromTarget',
  280. value: function getPaneFromTarget() {
  281. var selector = this.$element.data('target');
  282. if (!selector) {
  283. selector = this.$element.attr('href');
  284. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '');
  285. }
  286. if (selector) {
  287. return (0, _jquery2.default)(selector);
  288. }
  289. return null;
  290. }
  291. },
  292. {
  293. key: 'setup',
  294. value: function setup() {
  295. var current = this.wizard.currentIndex();
  296. if (this.index === current) {
  297. this.enter('active');
  298. if (this.loader) {
  299. this.load();
  300. }
  301. } else if (this.index > current) {
  302. this.enter('disabled');
  303. }
  304. this.$element.attr('aria-expanded', this.is('active'));
  305. this.$pane.attr('aria-expanded', this.is('active'));
  306. var classes = this.wizard.options.classes;
  307. if (this.is('active')) {
  308. this.$pane.addClass(classes.pane.active);
  309. } else {
  310. this.$pane.removeClass(classes.pane.active);
  311. }
  312. }
  313. },
  314. {
  315. key: 'show',
  316. value: function show(callback) {
  317. if (this.is('activing') || this.is('active')) {
  318. return;
  319. }
  320. this.trigger('beforeShow');
  321. this.enter('activing');
  322. var classes = this.wizard.options.classes;
  323. this.$element.attr('aria-expanded', true);
  324. this.$pane
  325. .addClass(classes.pane.activing)
  326. .addClass(classes.pane.active)
  327. .attr('aria-expanded', true);
  328. var complete = function complete() {
  329. this.$pane.removeClass(classes.pane.activing);
  330. this.leave('activing');
  331. this.enter('active');
  332. this.trigger('afterShow');
  333. if (_jquery2.default.isFunction(callback)) {
  334. callback.call(this);
  335. }
  336. };
  337. if (!support.transition) {
  338. complete.call(this);
  339. return;
  340. }
  341. this.$pane.one(
  342. support.transition.end,
  343. _jquery2.default.proxy(complete, this)
  344. );
  345. emulateTransitionEnd(this.$pane, this.TRANSITION_DURATION);
  346. }
  347. },
  348. {
  349. key: 'hide',
  350. value: function hide(callback) {
  351. if (this.is('activing') || !this.is('active')) {
  352. return;
  353. }
  354. this.trigger('beforeHide');
  355. this.enter('activing');
  356. var classes = this.wizard.options.classes;
  357. this.$element.attr('aria-expanded', false);
  358. this.$pane
  359. .addClass(classes.pane.activing)
  360. .removeClass(classes.pane.active)
  361. .attr('aria-expanded', false);
  362. var complete = function complete() {
  363. this.$pane.removeClass(classes.pane.activing);
  364. this.leave('activing');
  365. this.leave('active');
  366. this.trigger('afterHide');
  367. if (_jquery2.default.isFunction(callback)) {
  368. callback.call(this);
  369. }
  370. };
  371. if (!support.transition) {
  372. complete.call(this);
  373. return;
  374. }
  375. this.$pane.one(
  376. support.transition.end,
  377. _jquery2.default.proxy(complete, this)
  378. );
  379. emulateTransitionEnd(this.$pane, this.TRANSITION_DURATION);
  380. }
  381. },
  382. {
  383. key: 'empty',
  384. value: function empty() {
  385. this.$pane.empty();
  386. }
  387. },
  388. {
  389. key: 'load',
  390. value: function load(callback) {
  391. var that = this;
  392. var loader = this.loader;
  393. if (_jquery2.default.isFunction(loader)) {
  394. loader = loader.call(this.wizard, this);
  395. }
  396. if (this.wizard.options.cacheContent && this.loaded) {
  397. if (_jquery2.default.isFunction(callback)) {
  398. callback.call(this);
  399. }
  400. return;
  401. }
  402. this.trigger('beforeLoad');
  403. this.enter('loading');
  404. function setContent(content) {
  405. that.$pane.html(content);
  406. that.leave('loading');
  407. that.loaded = true;
  408. that.trigger('afterLoad');
  409. if (_jquery2.default.isFunction(callback)) {
  410. callback.call(that);
  411. }
  412. }
  413. if (typeof loader === 'string') {
  414. setContent(loader);
  415. } else if (
  416. (typeof loader === 'undefined' ? 'undefined' : _typeof(loader)) ===
  417. 'object' &&
  418. loader.hasOwnProperty('url')
  419. ) {
  420. that.wizard.options.loading.show.call(that.wizard, that);
  421. _jquery2.default
  422. .ajax(loader.url, loader.settings || {})
  423. .done(function(data) {
  424. setContent(data);
  425. that.wizard.options.loading.hide.call(that.wizard, that);
  426. })
  427. .fail(function() {
  428. that.wizard.options.loading.fail.call(that.wizard, that);
  429. });
  430. } else {
  431. setContent('');
  432. }
  433. }
  434. },
  435. {
  436. key: 'trigger',
  437. value: function trigger(event) {
  438. var _wizard;
  439. for (
  440. var _len = arguments.length,
  441. args = Array(_len > 1 ? _len - 1 : 0),
  442. _key = 1;
  443. _key < _len;
  444. _key++
  445. ) {
  446. args[_key - 1] = arguments[_key];
  447. }
  448. if (_jquery2.default.isArray(this.events[event])) {
  449. for (var i in this.events[event]) {
  450. if ({}.hasOwnProperty.call(this.events[event], i)) {
  451. var _events$event;
  452. (_events$event = this.events[event])[i].apply(
  453. _events$event,
  454. args
  455. );
  456. }
  457. }
  458. }
  459. (_wizard = this.wizard).trigger.apply(
  460. _wizard,
  461. _toConsumableArray([event, this].concat(args))
  462. );
  463. }
  464. },
  465. {
  466. key: 'enter',
  467. value: function enter(state) {
  468. this.states[state] = true;
  469. var classes = this.wizard.options.classes;
  470. this.$element.addClass(classes.step[state]);
  471. this.trigger('stateChange', true, state);
  472. }
  473. },
  474. {
  475. key: 'leave',
  476. value: function leave(state) {
  477. if (this.states[state]) {
  478. this.states[state] = false;
  479. var classes = this.wizard.options.classes;
  480. this.$element.removeClass(classes.step[state]);
  481. this.trigger('stateChange', false, state);
  482. }
  483. }
  484. },
  485. {
  486. key: 'setValidatorFromData',
  487. value: function setValidatorFromData() {
  488. var validator = this.$pane.data('validator');
  489. if (validator && _jquery2.default.isFunction(window[validator])) {
  490. this.validator = window[validator];
  491. }
  492. }
  493. },
  494. {
  495. key: 'setLoaderFromData',
  496. value: function setLoaderFromData() {
  497. var loader = this.$pane.data('loader');
  498. if (loader) {
  499. if (_jquery2.default.isFunction(window[loader])) {
  500. this.loader = window[loader];
  501. }
  502. } else {
  503. var url = this.$pane.data('loader-url');
  504. if (url) {
  505. this.loader = {
  506. url: url,
  507. settings: this.$pane.data('settings') || {}
  508. };
  509. }
  510. }
  511. }
  512. },
  513. {
  514. key: 'active',
  515. value: function active() {
  516. return this.wizard.goTo(this.index);
  517. }
  518. },
  519. {
  520. key: 'on',
  521. value: function on(event, handler) {
  522. if (_jquery2.default.isFunction(handler)) {
  523. if (_jquery2.default.isArray(this.events[event])) {
  524. this.events[event].push(handler);
  525. } else {
  526. this.events[event] = [handler];
  527. }
  528. }
  529. return this;
  530. }
  531. },
  532. {
  533. key: 'off',
  534. value: function off(event, handler) {
  535. if (
  536. _jquery2.default.isFunction(handler) &&
  537. _jquery2.default.isArray(this.events[event])
  538. ) {
  539. _jquery2.default.each(this.events[event], function(i, f) {
  540. /*eslint consistent-return: "off"*/
  541. if (f === handler) {
  542. delete this.events[event][i];
  543. return false;
  544. }
  545. });
  546. }
  547. return this;
  548. }
  549. },
  550. {
  551. key: 'is',
  552. value: function is(state) {
  553. return this.states[state] && this.states[state] === true;
  554. }
  555. },
  556. {
  557. key: 'reset',
  558. value: function reset() {
  559. for (var state in this.states) {
  560. if ({}.hasOwnProperty.call(this.states, state)) {
  561. this.leave(state);
  562. }
  563. }
  564. this.setup();
  565. return this;
  566. }
  567. },
  568. {
  569. key: 'setLoader',
  570. value: function setLoader(loader) {
  571. this.loader = loader;
  572. if (this.is('active')) {
  573. this.load();
  574. }
  575. return this;
  576. }
  577. },
  578. {
  579. key: 'setValidator',
  580. value: function setValidator(validator) {
  581. if (_jquery2.default.isFunction(validator)) {
  582. this.validator = validator;
  583. }
  584. return this;
  585. }
  586. },
  587. {
  588. key: 'validate',
  589. value: function validate() {
  590. return this.validator.call(this.$pane.get(0), this);
  591. }
  592. }
  593. ]);
  594. return Step;
  595. })();
  596. var counter = 0;
  597. var NAMESPACE$1 = 'wizard';
  598. var wizard = (function() {
  599. function wizard(element) {
  600. var options =
  601. arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  602. _classCallCheck(this, wizard);
  603. this.$element = (0, _jquery2.default)(element);
  604. this.options = _jquery2.default.extend(true, {}, DEFAULTS, options);
  605. this.$steps = this.$element.find(this.options.step);
  606. this.id = this.$element.attr('id');
  607. if (!this.id) {
  608. this.id = 'wizard-' + ++counter;
  609. this.$element.attr('id', this.id);
  610. }
  611. this.trigger('init');
  612. this.initialize();
  613. }
  614. _createClass(
  615. wizard,
  616. [
  617. {
  618. key: 'initialize',
  619. value: function initialize() {
  620. this.steps = [];
  621. var that = this;
  622. this.$steps.each(function(index) {
  623. that.steps.push(new Step(this, that, index));
  624. });
  625. this._current = 0;
  626. this.transitioning = null;
  627. _jquery2.default.each(this.steps, function(i, step) {
  628. step.setup();
  629. });
  630. this.setup();
  631. this.$element.on('click', this.options.step, function(e) {
  632. var index = (0, _jquery2.default)(this).data('wizard-index');
  633. if (!that.get(index).is('disabled')) {
  634. that.goTo(index);
  635. }
  636. e.preventDefault();
  637. e.stopPropagation();
  638. });
  639. if (this.options.keyboard) {
  640. (0, _jquery2.default)(document).on(
  641. 'keyup',
  642. _jquery2.default.proxy(this.keydown, this)
  643. );
  644. }
  645. this.trigger('ready');
  646. }
  647. },
  648. {
  649. key: 'setup',
  650. value: function setup() {
  651. this.$buttons = (0, _jquery2.default)(
  652. this.options.templates.buttons.call(this)
  653. );
  654. this.updateButtons();
  655. var buttonsAppendTo = this.options.buttonsAppendTo;
  656. var $to = void 0;
  657. if (buttonsAppendTo === 'this') {
  658. $to = this.$element;
  659. } else if (_jquery2.default.isFunction(buttonsAppendTo)) {
  660. $to = buttonsAppendTo.call(this);
  661. } else {
  662. $to = this.$element.find(buttonsAppendTo);
  663. }
  664. this.$buttons = this.$buttons.appendTo($to);
  665. }
  666. },
  667. {
  668. key: 'updateButtons',
  669. value: function updateButtons() {
  670. var classes = this.options.classes.button;
  671. var $back = this.$buttons.find('[data-wizard="back"]');
  672. var $next = this.$buttons.find('[data-wizard="next"]');
  673. var $finish = this.$buttons.find('[data-wizard="finish"]');
  674. if (this._current === 0) {
  675. $back.addClass(classes.disabled);
  676. } else {
  677. $back.removeClass(classes.disabled);
  678. }
  679. if (this._current === this.lastIndex()) {
  680. $next.addClass(classes.hide);
  681. $finish.removeClass(classes.hide);
  682. } else {
  683. $next.removeClass(classes.hide);
  684. $finish.addClass(classes.hide);
  685. }
  686. }
  687. },
  688. {
  689. key: 'updateSteps',
  690. value: function updateSteps() {
  691. var _this = this;
  692. _jquery2.default.each(this.steps, function(i, step) {
  693. if (i > _this._current) {
  694. step.leave('error');
  695. step.leave('active');
  696. step.leave('done');
  697. if (!_this.options.enableWhenVisited) {
  698. step.enter('disabled');
  699. }
  700. }
  701. });
  702. }
  703. },
  704. {
  705. key: 'keydown',
  706. value: function keydown(e) {
  707. if (/input|textarea/i.test(e.target.tagName)) {
  708. return;
  709. }
  710. switch (e.which) {
  711. case 37:
  712. this.back();
  713. break;
  714. case 39:
  715. this.next();
  716. break;
  717. default:
  718. return;
  719. }
  720. e.preventDefault();
  721. }
  722. },
  723. {
  724. key: 'trigger',
  725. value: function trigger(eventType) {
  726. for (
  727. var _len2 = arguments.length,
  728. params = Array(_len2 > 1 ? _len2 - 1 : 0),
  729. _key2 = 1;
  730. _key2 < _len2;
  731. _key2++
  732. ) {
  733. params[_key2 - 1] = arguments[_key2];
  734. }
  735. var data = [this].concat(params);
  736. // event
  737. this.$element.trigger(NAMESPACE$1 + '::' + eventType, data);
  738. // callback
  739. eventType = eventType.replace(/\b\w+\b/g, function(word) {
  740. return word.substring(0, 1).toUpperCase() + word.substring(1);
  741. });
  742. var onFunction = 'on' + eventType;
  743. if (typeof this.options[onFunction] === 'function') {
  744. this.options[onFunction].apply(this, params);
  745. }
  746. }
  747. },
  748. {
  749. key: 'get',
  750. value: function get(index) {
  751. if (typeof index === 'string' && index.substring(0, 1) === '#') {
  752. var id = index.substring(1);
  753. for (var i in this.steps) {
  754. if (this.steps[i].$pane.attr('id') === id) {
  755. return this.steps[i];
  756. }
  757. }
  758. }
  759. if (index < this.length() && this.steps[index]) {
  760. return this.steps[index];
  761. }
  762. return null;
  763. }
  764. },
  765. {
  766. key: 'goTo',
  767. value: function goTo(index, callback) {
  768. if (index === this._current || this.transitioning === true) {
  769. return false;
  770. }
  771. var current = this.current();
  772. var to = this.get(index);
  773. if (index > this._current) {
  774. if (!current.validate()) {
  775. current.leave('done');
  776. current.enter('error');
  777. return -1;
  778. }
  779. current.leave('error');
  780. if (index > this._current) {
  781. current.enter('done');
  782. }
  783. }
  784. var that = this;
  785. var process = function process() {
  786. that.trigger('beforeChange', current, to);
  787. that.transitioning = true;
  788. current.hide();
  789. to.show(function() {
  790. that._current = index;
  791. that.transitioning = false;
  792. this.leave('disabled');
  793. that.updateButtons();
  794. that.updateSteps();
  795. if (that.options.autoFocus) {
  796. var $input = this.$pane.find(':input');
  797. if ($input.length > 0) {
  798. $input.eq(0).focus();
  799. } else {
  800. this.$pane.focus();
  801. }
  802. }
  803. if (_jquery2.default.isFunction(callback)) {
  804. callback.call(that);
  805. }
  806. that.trigger('afterChange', current, to);
  807. });
  808. };
  809. if (to.loader) {
  810. to.load(function() {
  811. process();
  812. });
  813. } else {
  814. process();
  815. }
  816. return true;
  817. }
  818. },
  819. {
  820. key: 'length',
  821. value: function length() {
  822. return this.steps.length;
  823. }
  824. },
  825. {
  826. key: 'current',
  827. value: function current() {
  828. return this.get(this._current);
  829. }
  830. },
  831. {
  832. key: 'currentIndex',
  833. value: function currentIndex() {
  834. return this._current;
  835. }
  836. },
  837. {
  838. key: 'lastIndex',
  839. value: function lastIndex() {
  840. return this.length() - 1;
  841. }
  842. },
  843. {
  844. key: 'next',
  845. value: function next() {
  846. if (this._current < this.lastIndex()) {
  847. var from = this._current,
  848. to = this._current + 1;
  849. this.goTo(to, function() {
  850. this.trigger('next', this.get(from), this.get(to));
  851. });
  852. }
  853. return false;
  854. }
  855. },
  856. {
  857. key: 'back',
  858. value: function back() {
  859. if (this._current > 0) {
  860. var from = this._current,
  861. to = this._current - 1;
  862. this.goTo(to, function() {
  863. this.trigger('back', this.get(from), this.get(to));
  864. });
  865. }
  866. return false;
  867. }
  868. },
  869. {
  870. key: 'first',
  871. value: function first() {
  872. return this.goTo(0);
  873. }
  874. },
  875. {
  876. key: 'finish',
  877. value: function finish() {
  878. if (this._current === this.lastIndex()) {
  879. var current = this.current();
  880. if (current.validate()) {
  881. this.trigger('finish');
  882. current.leave('error');
  883. current.enter('done');
  884. } else {
  885. current.enter('error');
  886. }
  887. }
  888. }
  889. },
  890. {
  891. key: 'reset',
  892. value: function reset() {
  893. this._current = 0;
  894. _jquery2.default.each(this.steps, function(i, step) {
  895. step.reset();
  896. });
  897. this.trigger('reset');
  898. }
  899. }
  900. ],
  901. [
  902. {
  903. key: 'setDefaults',
  904. value: function setDefaults(options) {
  905. _jquery2.default.extend(
  906. true,
  907. DEFAULTS,
  908. _jquery2.default.isPlainObject(options) && options
  909. );
  910. }
  911. }
  912. ]
  913. );
  914. return wizard;
  915. })();
  916. (0, _jquery2.default)(document).on('click', '[data-wizard]', function(e) {
  917. 'use strict';
  918. var href = void 0;
  919. var $this = (0, _jquery2.default)(this);
  920. var $target = (0, _jquery2.default)(
  921. $this.attr('data-target') ||
  922. ((href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, ''))
  923. );
  924. var wizard = $target.data(NAMESPACE$1);
  925. if (!wizard) {
  926. return;
  927. }
  928. var method = $this.data(NAMESPACE$1);
  929. if (/^(back|next|first|finish|reset)$/.test(method)) {
  930. wizard[method]();
  931. }
  932. e.preventDefault();
  933. });
  934. var info = {
  935. version: '0.4.4'
  936. };
  937. var NAMESPACE = 'wizard';
  938. var OtherWizard = _jquery2.default.fn.wizard;
  939. var jQueryWizard = function jQueryWizard(options) {
  940. for (
  941. var _len3 = arguments.length,
  942. args = Array(_len3 > 1 ? _len3 - 1 : 0),
  943. _key3 = 1;
  944. _key3 < _len3;
  945. _key3++
  946. ) {
  947. args[_key3 - 1] = arguments[_key3];
  948. }
  949. if (typeof options === 'string') {
  950. var method = options;
  951. if (/^_/.test(method)) {
  952. return false;
  953. } else if (/^(get)/.test(method)) {
  954. var instance = this.first().data(NAMESPACE);
  955. if (instance && typeof instance[method] === 'function') {
  956. return instance[method].apply(instance, args);
  957. }
  958. } else {
  959. return this.each(function() {
  960. var instance = _jquery2.default.data(this, NAMESPACE);
  961. if (instance && typeof instance[method] === 'function') {
  962. instance[method].apply(instance, args);
  963. }
  964. });
  965. }
  966. }
  967. return this.each(function() {
  968. if (!(0, _jquery2.default)(this).data(NAMESPACE)) {
  969. (0, _jquery2.default)(this).data(NAMESPACE, new wizard(this, options));
  970. }
  971. });
  972. };
  973. _jquery2.default.fn.wizard = jQueryWizard;
  974. _jquery2.default.wizard = _jquery2.default.extend(
  975. {
  976. setDefaults: wizard.setDefaults,
  977. noConflict: function noConflict() {
  978. _jquery2.default.fn.wizard = OtherWizard;
  979. return jQueryWizard;
  980. }
  981. },
  982. info
  983. );
  984. });