jquery.smartWizard.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /*!
  2. * SmartWizard v4.2.2
  3. * The awesome jQuery step wizard plugin with Bootstrap support
  4. * http://www.techlaboratory.net/smartwizard
  5. *
  6. * Created by Dipu Raj
  7. * http://dipuraj.me
  8. *
  9. * Licensed under the terms of the MIT License
  10. * https://github.com/techlab/SmartWizard/blob/master/LICENSE
  11. */
  12. ;(function ($, window, document, undefined) {
  13. "use strict";
  14. // Default options
  15. var defaults = {
  16. selected: 0, // Initial selected step, 0 = first step
  17. keyNavigation: true, // Enable/Disable keyboard navigation(left and right keys are used if enabled)
  18. autoAdjustHeight: true, // Automatically adjust content height
  19. cycleSteps: false, // Allows to cycle the navigation of steps
  20. backButtonSupport: true, // Enable the back button support
  21. useURLhash: true, // Enable selection of the step based on url hash
  22. showStepURLhash: true, // Show url hash based on step
  23. lang: { // Language variables for button
  24. next: 'Next',
  25. previous: 'Previous'
  26. },
  27. toolbarSettings: {
  28. toolbarPosition: 'bottom', // none, top, bottom, both
  29. toolbarButtonPosition: 'end', // start, end
  30. showNextButton: true, // show/hide a Next button
  31. showPreviousButton: true, // show/hide a Previous button
  32. toolbarExtraButtons: [] // Extra buttons to show on toolbar, array of jQuery input/buttons elements
  33. },
  34. anchorSettings: {
  35. anchorClickable: true, // Enable/Disable anchor navigation
  36. enableAllAnchors: false, // Activates all anchors clickable all times
  37. markDoneStep: true, // Add done css
  38. markAllPreviousStepsAsDone: true, // When a step selected by url hash, all previous steps are marked done
  39. removeDoneStepOnNavigateBack: false, // While navigate back done step after active step will be cleared
  40. enableAnchorOnDoneStep: true // Enable/Disable the done steps navigation
  41. },
  42. contentURL: null, // content url, Enables Ajax content loading. Can also set as data data-content-url on anchor
  43. contentCache: true, // cache step contents, if false content is fetched always from ajax url
  44. ajaxSettings: {}, // Ajax extra settings
  45. disabledSteps: [], // Array Steps disabled
  46. errorSteps: [], // Highlight step with errors
  47. hiddenSteps: [], // Hidden steps
  48. theme: 'default', // theme for the wizard, related css need to include for other than default theme
  49. transitionEffect: 'none', // Effect on navigation, none/slide/fade
  50. transitionSpeed: '400'
  51. };
  52. // The plugin constructor
  53. function SmartWizard(element, options) {
  54. // Merge user settings with default, recursively
  55. this.options = $.extend(true, {}, defaults, options);
  56. // Main container element
  57. this.main = $(element);
  58. // Navigation bar element
  59. this.nav = this.main.children('ul');
  60. // Step anchor elements
  61. this.steps = $("li > a", this.nav);
  62. // Content container
  63. this.container = this.main.children('div');
  64. // Content pages
  65. this.pages = this.container.children('div');
  66. // Active step index
  67. this.current_index = null;
  68. // Call initial method
  69. this.init();
  70. }
  71. $.extend(SmartWizard.prototype, {
  72. init: function () {
  73. // Set the elements
  74. this._setElements();
  75. // Add toolbar
  76. this._setToolbar();
  77. // Assign plugin events
  78. this._setEvents();
  79. var idx = this.options.selected;
  80. // Get selected step from the url
  81. if (this.options.useURLhash) {
  82. // Get step number from url hash if available
  83. var hash = window.location.hash;
  84. if (hash && hash.length > 0) {
  85. var elm = $("a[href*='" + hash + "']", this.nav);
  86. if (elm.length > 0) {
  87. var id = this.steps.index(elm);
  88. idx = id >= 0 ? id : idx;
  89. }
  90. }
  91. }
  92. if (idx > 0 && this.options.anchorSettings.markDoneStep && this.options.anchorSettings.markAllPreviousStepsAsDone) {
  93. // Mark previous steps of the active step as done
  94. // this.steps.eq(idx).parent('li').prevAll().addClass("done");
  95. this._setDone(this.steps.eq(idx).parent('li').prevAll());
  96. }
  97. // Show the initial step
  98. this._showStep(idx);
  99. },
  100. // PRIVATE FUNCTIONS
  101. _setElements: function () {
  102. // Set the main element
  103. this.main.addClass('sw-main sw-theme-' + this.options.theme);
  104. // Set anchor elements
  105. this.nav.addClass('step-anchor'); // nav-justified nav-pills
  106. // Make the anchor clickable
  107. if (this.options.anchorSettings.enableAllAnchors !== false && this.options.anchorSettings.anchorClickable !== false) {
  108. this.steps.parent('li').addClass('clickable');
  109. }
  110. // Set content container
  111. this.container.addClass('sw-container tab-content');
  112. // Set content pages
  113. this.pages.addClass('tab-pane step-content');
  114. // Disabled steps
  115. var mi = this;
  116. if (this.options.disabledSteps && this.options.disabledSteps.length > 0) {
  117. $.each(this.options.disabledSteps, function (i, n) {
  118. mi.steps.eq(n).parent('li').addClass('disabled');
  119. });
  120. }
  121. // Error steps
  122. if (this.options.errorSteps && this.options.errorSteps.length > 0) {
  123. $.each(this.options.errorSteps, function (i, n) {
  124. mi.steps.eq(n).parent('li').addClass('danger');
  125. });
  126. }
  127. // Hidden steps
  128. if (this.options.hiddenSteps && this.options.hiddenSteps.length > 0) {
  129. $.each(this.options.hiddenSteps, function (i, n) {
  130. mi.steps.eq(n).parent('li').addClass('hidden');
  131. });
  132. }
  133. return true;
  134. },
  135. _setToolbar: function () {
  136. // Skip right away if the toolbar is not enabled
  137. if (this.options.toolbarSettings.toolbarPosition === 'none') {
  138. return true;
  139. }
  140. console.log(this.options.toolbarSettings.toolbarPosition);
  141. // Create the toolbar buttons
  142. var btnNext = this.options.toolbarSettings.showNextButton !== false ? $('<button></button>').text(this.options.lang.next).addClass('btn btn-default sw-btn-next').attr('type', 'button') : null;
  143. var btnPrevious = this.options.toolbarSettings.showPreviousButton !== false ? $('<button></button>').text(this.options.lang.previous).addClass('btn btn-default sw-btn-prev').attr('type', 'button') : null;
  144. var btnGroup = $('<div></div>').addClass('btn-group mr-2 sw-btn-group').attr('role', 'group').append(btnPrevious, btnNext);
  145. var box1 = $('<div></div>').addClass('col-sm-2');
  146. var box2 = $('<div></div>').addClass('col-sm-10').append(btnGroup);
  147. // Add extra toolbar buttons
  148. var btnGroupExtra = null;
  149. if (this.options.toolbarSettings.toolbarExtraButtons && this.options.toolbarSettings.toolbarExtraButtons.length > 0) {
  150. btnGroupExtra = $('<span></span>').addClass('mr-2 sw-btn-group-extra').attr('role', 'group');
  151. $.each(this.options.toolbarSettings.toolbarExtraButtons, function (i, n) {
  152. btnGroupExtra.append(n.clone(true));
  153. });
  154. }
  155. var toolbarTop, toolbarBottom;
  156. // Append toolbar based on the position
  157. switch (this.options.toolbarSettings.toolbarPosition) {
  158. case 'top':
  159. toolbarTop = $('<div></div>').addClass('btn-toolbar sw-toolbar sw-toolbar-top justify-content-' + this.options.toolbarSettings.toolbarButtonPosition);
  160. toolbarTop.append(box1, box2);
  161. if (this.options.toolbarSettings.toolbarButtonPosition === 'left') {
  162. box2.append(btnGroupExtra);
  163. } else {
  164. box2.prepend(btnGroupExtra);
  165. }
  166. this.container.before(toolbarTop);
  167. break;
  168. case 'bottom':
  169. toolbarBottom = $('<div></div>').addClass('btn-toolbar sw-toolbar sw-toolbar-bottom justify-content-' + this.options.toolbarSettings.toolbarButtonPosition);
  170. toolbarBottom.append(box1, box2);
  171. if (this.options.toolbarSettings.toolbarButtonPosition === 'left') {
  172. box2.append(btnGroupExtra);
  173. } else {
  174. box2.prepend(btnGroupExtra);
  175. }
  176. this.container.after(toolbarBottom);
  177. break;
  178. case 'both':
  179. toolbarTop = $('<div></div>').addClass('btn-toolbar sw-toolbar sw-toolbar-top justify-content-' + this.options.toolbarSettings.toolbarButtonPosition);
  180. toolbarTop.append(box1, box2);
  181. if (this.options.toolbarSettings.toolbarButtonPosition === 'left') {
  182. box2.append(btnGroupExtra);
  183. } else {
  184. box2.prepend(btnGroupExtra);
  185. }
  186. this.container.before(toolbarTop);
  187. toolbarBottom = $('<div></div>').addClass('btn-toolbar sw-toolbar sw-toolbar-bottom justify-content-' + this.options.toolbarSettings.toolbarButtonPosition);
  188. toolbarBottom.append(box1, box2);
  189. if (this.options.toolbarSettings.toolbarButtonPosition === 'left') {
  190. box2.append(btnGroupExtra.clone(true));
  191. } else {
  192. box2.prepend(btnGroupExtra.clone(true));
  193. }
  194. this.container.after(toolbarBottom);
  195. break;
  196. default:
  197. toolbarBottom = $('<div></div>').addClass('btn-toolbar sw-toolbar sw-toolbar-bottom justify-content-' + this.options.toolbarSettings.toolbarButtonPosition);
  198. toolbarBottom.append(box1, box2);
  199. if (this.options.toolbarSettings.toolbarButtonPosition === 'left') {
  200. box2.append(btnGroupExtra);
  201. } else {
  202. box2.prepend(btnGroupExtra);
  203. }
  204. this.container.after(toolbarBottom);
  205. break;
  206. }
  207. return true;
  208. },
  209. _setEvents: function () {
  210. // Anchor click event
  211. var mi = this;
  212. $(this.steps).on("click", function (e) {
  213. e.preventDefault();
  214. if (mi.options.anchorSettings.anchorClickable === false) {
  215. return true;
  216. }
  217. var idx = mi.steps.index(this);
  218. if (mi.options.anchorSettings.enableAnchorOnDoneStep === false && mi.steps.eq(idx).parent('li').hasClass('done')) {
  219. return true;
  220. }
  221. if (idx !== mi.current_index) {
  222. if (mi.options.anchorSettings.enableAllAnchors !== false && mi.options.anchorSettings.anchorClickable !== false) {
  223. mi._showStep(idx);
  224. } else {
  225. if (mi.steps.eq(idx).parent('li').hasClass('done')) {
  226. mi._showStep(idx);
  227. }
  228. }
  229. }
  230. });
  231. // Keyboard navigation event
  232. if (this.options.keyNavigation) {
  233. $(document).keyup(function (e) {
  234. mi._keyNav(e);
  235. });
  236. }
  237. // Back/forward browser button event
  238. if (this.options.backButtonSupport) {
  239. $(window).on('hashchange', function (e) {
  240. if (!mi.options.useURLhash) {
  241. return true;
  242. }
  243. if (window.location.hash) {
  244. var elm = $("a[href*='" + window.location.hash + "']", mi.nav);
  245. if (elm && elm.length > 0) {
  246. e.preventDefault();
  247. mi._showStep(mi.steps.index(elm));
  248. }
  249. }
  250. });
  251. }
  252. return true;
  253. },
  254. _showNext: function () {
  255. var si = this.current_index + 1;
  256. // Find the next not disabled step
  257. for (var i = si; i < this.steps.length; i++) {
  258. if (!this.steps.eq(i).parent('li').hasClass('disabled') && !this.steps.eq(i).parent('li').hasClass('hidden')) {
  259. si = i;
  260. break;
  261. }
  262. }
  263. if (this.steps.length <= si) {
  264. if (!this.options.cycleSteps) {
  265. return false;
  266. }
  267. si = 0;
  268. }
  269. this._showStep(si);
  270. return true;
  271. },
  272. _showPrevious: function () {
  273. var si = this.current_index - 1;
  274. // Find the previous not disabled step
  275. for (var i = si; i >= 0; i--) {
  276. if (!this.steps.eq(i).parent('li').hasClass('disabled') && !this.steps.eq(i).parent('li').hasClass('hidden')) {
  277. si = i;
  278. break;
  279. }
  280. }
  281. if (0 > si) {
  282. if (!this.options.cycleSteps) {
  283. return false;
  284. }
  285. si = this.steps.length - 1;
  286. }
  287. this._showStep(si);
  288. return true;
  289. },
  290. _showStep: function (idx) {
  291. // If step not found, skip
  292. if (!this.steps.eq(idx)) {
  293. return false;
  294. }
  295. // If current step is requested again, skip
  296. if (idx == this.current_index) {
  297. return false;
  298. }
  299. // If it is a disabled step, skip
  300. if (this.steps.eq(idx).parent('li').hasClass('disabled') || this.steps.eq(idx).parent('li').hasClass('hidden')) {
  301. return false;
  302. }
  303. // Load step content
  304. this._loadStepContent(idx);
  305. return true;
  306. },
  307. _loadStepContent: function (idx) {
  308. var mi = this;
  309. // Get current step elements
  310. var curTab = this.steps.eq(this.current_index);
  311. // Get the direction of step navigation
  312. var stepDirection = '';
  313. var elm = this.steps.eq(idx);
  314. var contentURL = elm.data('content-url') && elm.data('content-url').length > 0 ? elm.data('content-url') : this.options.contentURL;
  315. if (this.current_index !== null && this.current_index !== idx) {
  316. stepDirection = this.current_index < idx ? "forward" : "backward";
  317. }
  318. // Trigger "leaveStep" event
  319. if (this.current_index !== null && this._triggerEvent("leaveStep", [curTab, this.current_index, stepDirection]) === false) {
  320. return false;
  321. }
  322. if (contentURL && contentURL.length > 0 && (!elm.data('has-content') || !this.options.contentCache)) {
  323. // Get ajax content and then show step
  324. var selPage = elm.length > 0 ? $(elm.attr("href"), this.main) : null;
  325. var ajaxSettings = $.extend(true, {}, {
  326. url: contentURL,
  327. type: "POST",
  328. data: { step_number: idx },
  329. dataType: "text",
  330. beforeSend: function () {
  331. elm.parent('li').addClass('loading');
  332. },
  333. error: function (jqXHR, status, message) {
  334. elm.parent('li').removeClass('loading');
  335. $.error(message);
  336. },
  337. success: function (res) {
  338. if (res && res.length > 0) {
  339. elm.data('has-content', true);
  340. selPage.html(res);
  341. }
  342. elm.parent('li').removeClass('loading');
  343. mi._transitPage(idx);
  344. }
  345. }, this.options.ajaxSettings);
  346. $.ajax(ajaxSettings);
  347. } else {
  348. // Show step
  349. this._transitPage(idx);
  350. }
  351. return true;
  352. },
  353. _transitPage: function (idx) {
  354. var mi = this;
  355. // Get current step elements
  356. var curTab = this.steps.eq(this.current_index);
  357. var curPage = curTab.length > 0 ? $(curTab.attr("href"), this.main) : null;
  358. // Get step to show elements
  359. var selTab = this.steps.eq(idx);
  360. var selPage = selTab.length > 0 ? $(selTab.attr("href"), this.main) : null;
  361. // Get the direction of step navigation
  362. var stepDirection = '';
  363. if (this.current_index !== null && this.current_index !== idx) {
  364. stepDirection = this.current_index < idx ? "forward" : "backward";
  365. }
  366. var stepPosition = 'middle';
  367. if (idx === 0) {
  368. stepPosition = 'first';
  369. } else if (idx === this.steps.length - 1) {
  370. stepPosition = 'final';
  371. }
  372. this.options.transitionEffect = this.options.transitionEffect.toLowerCase();
  373. this.pages.finish();
  374. if (this.options.transitionEffect === 'slide') {
  375. // normal slide
  376. if (curPage && curPage.length > 0) {
  377. curPage.slideUp('fast', this.options.transitionEasing, function () {
  378. selPage.slideDown(mi.options.transitionSpeed, mi.options.transitionEasing);
  379. });
  380. } else {
  381. selPage.slideDown(this.options.transitionSpeed, this.options.transitionEasing);
  382. }
  383. } else if (this.options.transitionEffect === 'fade') {
  384. // normal fade
  385. if (curPage && curPage.length > 0) {
  386. curPage.fadeOut('fast', this.options.transitionEasing, function () {
  387. selPage.fadeIn('fast', mi.options.transitionEasing, function () {
  388. $(this).show();
  389. });
  390. });
  391. } else {
  392. selPage.fadeIn(this.options.transitionSpeed, this.options.transitionEasing, function () {
  393. $(this).show();
  394. });
  395. }
  396. } else {
  397. if (curPage && curPage.length > 0) {
  398. curPage.hide();
  399. }
  400. selPage.show();
  401. }
  402. // Change the url hash to new step
  403. this._setURLHash(selTab.attr("href"));
  404. // Update controls
  405. this._setAnchor(idx);
  406. // Set the buttons based on the step
  407. this._setButtons(idx);
  408. // Fix height with content
  409. this._fixHeight(idx);
  410. // Update the current index
  411. this.current_index = idx;
  412. // Trigger "showStep" event
  413. this._triggerEvent("showStep", [selTab, this.current_index, stepDirection, stepPosition]);
  414. return true;
  415. },
  416. _setAnchor: function (idx) {
  417. // Current step anchor > Remove other classes and add done class
  418. this.steps.eq(this.current_index).parent('li').removeClass("active danger loading");
  419. if (this.options.anchorSettings.markDoneStep !== false && this.current_index !== null) {
  420. this._setDone(this.steps.eq(this.current_index).parent('li'));
  421. if (this.options.anchorSettings.removeDoneStepOnNavigateBack !== false) {
  422. this._removeDone(this.steps.eq(idx).parent('li').nextAll());
  423. }
  424. }
  425. // Next step anchor > Remove other classes and add active class
  426. this.steps.eq(idx).parent('li').removeClass("danger loading").addClass("active");
  427. this._removeDone(this.steps.eq(idx).parent('li'));
  428. return true;
  429. },
  430. _setDone: function ($li) {
  431. $li.addClass("done");
  432. $li.find('.la-step-icon').html('<i style="vertical-align:middle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="check" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 0 0-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1.4-12.8-6.3-12.8z"></path></svg></i>');
  433. },
  434. //
  435. _removeDone: function ($lis) {
  436. $lis.removeClass("done");
  437. $lis.each(function (k, li) {
  438. var $icon = $(li).find('.la-step-icon');
  439. $icon.text($icon.data('index') + 1);
  440. });
  441. },
  442. _setButtons: function (idx) {
  443. // Previous/Next Button enable/disable based on step
  444. if (!this.options.cycleSteps) {
  445. if (0 >= idx) {
  446. $('.sw-btn-prev', this.main).addClass("disabled");
  447. } else {
  448. $('.sw-btn-prev', this.main).removeClass("disabled");
  449. }
  450. if (this.steps.length - 1 <= idx) {
  451. $('.sw-btn-next', this.main).addClass("disabled");
  452. } else {
  453. $('.sw-btn-next', this.main).removeClass("disabled");
  454. }
  455. }
  456. return true;
  457. },
  458. // HELPER FUNCTIONS
  459. _keyNav: function (e) {
  460. var mi = this;
  461. // Keyboard navigation
  462. switch (e.which) {
  463. case 37:
  464. // left
  465. mi._showPrevious();
  466. e.preventDefault();
  467. break;
  468. case 39:
  469. // right
  470. mi._showNext();
  471. e.preventDefault();
  472. break;
  473. default:
  474. return; // exit this handler for other keys
  475. }
  476. },
  477. _fixHeight: function (idx) {
  478. // Auto adjust height of the container
  479. if (this.options.autoAdjustHeight) {
  480. var selPage = this.steps.eq(idx).length > 0 ? $(this.steps.eq(idx).attr("href"), this.main) : null;
  481. this.container.finish().animate({ minHeight: selPage.outerHeight() }, this.options.transitionSpeed, function () {});
  482. }
  483. return true;
  484. },
  485. _triggerEvent: function (name, params) {
  486. // Trigger an event
  487. var e = $.Event(name);
  488. this.main.trigger(e, params);
  489. if (e.isDefaultPrevented()) {
  490. return false;
  491. }
  492. return e.result;
  493. },
  494. _setURLHash: function (hash) {
  495. if (this.options.showStepURLhash && window.location.hash !== hash) {
  496. window.location.hash = hash;
  497. }
  498. },
  499. // PUBLIC FUNCTIONS
  500. theme: function (v) {
  501. if (this.options.theme === v) {
  502. return false;
  503. }
  504. this.main.removeClass('sw-theme-' + this.options.theme);
  505. this.options.theme = v;
  506. this.main.addClass('sw-theme-' + this.options.theme);
  507. // Trigger "themeChanged" event
  508. this._triggerEvent("themeChanged", [this.options.theme]);
  509. },
  510. next: function () {
  511. this._showNext();
  512. },
  513. prev: function () {
  514. this._showPrevious();
  515. },
  516. reset: function () {
  517. // Trigger "beginReset" event
  518. if (this._triggerEvent("beginReset") === false) {
  519. return false;
  520. }
  521. // Reset all elements and classes
  522. this.container.stop(true);
  523. this.pages.stop(true);
  524. this.pages.hide();
  525. this.current_index = null;
  526. this._setURLHash(this.steps.eq(this.options.selected).attr("href"));
  527. $(".sw-toolbar", this.main).remove();
  528. this.steps.removeClass();
  529. this.steps.parents('li').removeClass();
  530. this.steps.data('has-content', false);
  531. this.init();
  532. // Trigger "endReset" event
  533. this._triggerEvent("endReset");
  534. },
  535. stepState: function (stepArray, state) {
  536. var mi = this;
  537. stepArray = $.isArray(stepArray) ? stepArray : [stepArray];
  538. var selSteps = $.grep(this.steps, function (n, i) {
  539. return $.inArray(i, stepArray) !== -1 && i !== mi.current_index;
  540. });
  541. if (selSteps && selSteps.length > 0) {
  542. switch (state) {
  543. case 'disable':
  544. $(selSteps).parents('li').addClass('disabled');
  545. break;
  546. case 'enable':
  547. $(selSteps).parents('li').removeClass('disabled');
  548. break;
  549. case 'hide':
  550. $(selSteps).parents('li').addClass('hidden');
  551. break;
  552. case 'show':
  553. $(selSteps).parents('li').removeClass('hidden');
  554. break;
  555. }
  556. }
  557. }
  558. });
  559. // Wrapper for the plugin
  560. $.fn.smartWizard = function (options) {
  561. var args = arguments;
  562. var instance;
  563. if (options === undefined || typeof options === 'object') {
  564. return this.each(function () {
  565. if (!$.data(this, "smartWizard")) {
  566. $.data(this, "smartWizard", new SmartWizard(this, options));
  567. }
  568. });
  569. } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
  570. instance = $.data(this[0], 'smartWizard');
  571. if (options === 'destroy') {
  572. $.data(this, 'smartWizard', null);
  573. }
  574. if (instance instanceof SmartWizard && typeof instance[options] === 'function') {
  575. return instance[options].apply(instance, Array.prototype.slice.call(args, 1));
  576. } else {
  577. return this;
  578. }
  579. }
  580. };
  581. })(jQuery, window, document);