|
1 | 1 | /*! |
2 | | - * jQuery Steps Plugin v0.8.0 - A powerful jQuery wizard plugin that supports accessibility and HTML5 |
| 2 | + * jQuery Steps Plugin v0.8.1 - A powerful jQuery wizard plugin that supports accessibility and HTML5 |
3 | 3 | * https://github.com/rstaib/jquery-steps |
4 | 4 | * |
5 | 5 | * Copyright (c) 2013 Rafael J. Staib |
|
17 | 17 | * - Implement preloadContent for async and iframe content types. |
18 | 18 | * - Implement slideLeft animation |
19 | 19 | * - Implement functionality to skip a certain amount of steps |
| 20 | + * - Add insert and remove step method |
20 | 21 | */ |
21 | 22 |
|
22 | 23 |
|
23 | 24 | (function ($) |
24 | 25 | { |
25 | | - var uid = 0; |
| 26 | + var uniqueId = 0; |
26 | 27 |
|
27 | 28 | /// <summary> |
28 | 29 | /// |
|
130 | 131 | currentIndex: opts.startIndex, |
131 | 132 | currentStep: null, |
132 | 133 | stepCount: 0, |
133 | | - transitionLock: false |
| 134 | + transitionShowElement: null |
134 | 135 | }); |
135 | 136 | createUniqueId($this); |
136 | 137 |
|
|
339 | 340 | var options = wizard.data("options"); |
340 | 341 | var state = wizard.data("state"); |
341 | 342 |
|
342 | | - if (state.transitionLock) |
343 | | - { |
344 | | - return; |
345 | | - } |
346 | | - |
347 | 343 | if (index < 0 || index >= state.stepCount || state.stepCount == 0) |
348 | 344 | { |
349 | | - //TODO: Change to a better error message |
350 | | - throw new "Index out of range exception!"; |
| 345 | + throw new "Index out of range."; |
351 | 346 | } |
352 | 347 |
|
353 | 348 | if (options.forceMoveForward && index < state.currentIndex) |
|
374 | 369 | switch (options.transitionEffect) |
375 | 370 | { |
376 | 371 | case $.fn.steps.transitionEffect.fade: |
377 | | - state.transitionLock = true; |
| 372 | + state.transitionShowElement = stepContents.eq(index); |
378 | 373 | stepContents.eq(oldIndex).fadeOut(options.transitionEffectSpeed, function () |
379 | 374 | { |
380 | | - stepContents.eq(index).fadeIn(options.transitionEffectSpeed, |
381 | | - function () { state.transitionLock = false; }); |
382 | | - }); |
| 375 | + var wizard = $(this).parents(".wizard"); |
| 376 | + var state = wizard.data("state"); |
| 377 | + |
| 378 | + if (state.transitionShowElement) |
| 379 | + { |
| 380 | + state.transitionShowElement.fadeIn(options.transitionEffectSpeed); |
| 381 | + state.transitionShowElement = null; |
| 382 | + } |
| 383 | + }).promise(); |
383 | 384 | break; |
384 | 385 |
|
385 | 386 | case $.fn.steps.transitionEffect.slide: |
386 | | - state.transitionLock = true; |
| 387 | + state.transitionShowElement = stepContents.eq(index); |
387 | 388 | stepContents.eq(oldIndex).slideUp(options.transitionEffectSpeed, function () |
388 | 389 | { |
389 | | - stepContents.eq(index).slideDown(options.transitionEffectSpeed, |
390 | | - function () { state.transitionLock = false; }); |
391 | | - }); |
| 390 | + var wizard = $(this).parents(".wizard"); |
| 391 | + var state = wizard.data("state"); |
| 392 | + |
| 393 | + if (state.transitionShowElement) |
| 394 | + { |
| 395 | + state.transitionShowElement.slideDown(options.transitionEffectSpeed); |
| 396 | + state.transitionShowElement = null; |
| 397 | + } |
| 398 | + }).promise(); |
392 | 399 | break; |
393 | 400 |
|
394 | 401 | //case $.fn.steps.transitionEffect.slideLeft: |
|
435 | 442 | stepContents.not(":eq(" + options.startIndex + ")").hide(); |
436 | 443 | stepContents.eq(options.startIndex).show(); |
437 | 444 |
|
438 | | - if (stepTitles.length !== stepContents.length) |
| 445 | + if (stepTitles.length > stepContents.length) |
| 446 | + { |
| 447 | + throw new "One or more corresponding step contents are missing."; |
| 448 | + } |
| 449 | + else if (stepTitles.length < stepContents.length) |
439 | 450 | { |
440 | | - //TODO: Change to a better error message |
441 | | - throw new "Each title has to have a relating content part and vise versa!"; |
| 451 | + throw new "One or more corresponding step titles are missing."; |
442 | 452 | } |
443 | 453 |
|
444 | 454 | var stepsWrapper = $(document.createElement(options.stepsContainerTag)).addClass("steps"); |
|
641 | 651 | { |
642 | 652 | if (substitutes[key] === undefined) |
643 | 653 | { |
644 | | - //TODO: Change to a better error message |
645 | | - throw new "Substitute key \"" + key + "\" does not exist!"; |
| 654 | + throw new "The key \"" + key + "\" does not exist in the substitute collection!"; |
646 | 655 | } |
647 | 656 |
|
648 | 657 | return substitutes[key]; |
|
673 | 682 | } |
674 | 683 |
|
675 | 684 | /// <summary> |
676 | | - /// |
| 685 | + /// Creates an unique id and adds this to the corresponding wizard instance. |
677 | 686 | /// </summary> |
678 | 687 | function createUniqueId(wizard) |
679 | 688 | { |
680 | 689 | if (wizard.attr("data-uid") === undefined) |
681 | 690 | { |
682 | | - wizard.attr("data-uid", "steps-uid-" + ++uid); |
| 691 | + wizard.attr("data-uid", "steps-uid-" + ++uniqueId); |
683 | 692 | } |
684 | 693 | } |
685 | 694 |
|
686 | 695 | /// <summary> |
687 | | - /// |
| 696 | + /// Retrieves the unique id from the given wizard instance. |
688 | 697 | /// </summary> |
689 | 698 | /// <returns></returns> |
690 | 699 | function getUniqueId(wizard) |
|
0 commit comments