You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
4.8 KiB

  1. (function (b, c) {
  2. var a = function (f, e) {
  3. var d;
  4. this.$element = b(f);
  5. this.options = b.extend({}, b.fn.wizard.defaults, e);
  6. this.currentStep = 1;
  7. this.numSteps = this.$element.find("li").length;
  8. /*Customized to Enable Out Of Wizard Buttons*/
  9. this.$prevBtn = $('#'+this.$element[0].id+'-actions').find("a.btn-prev");
  10. this.$nextBtn = $('#' + this.$element[0].id + '-actions').find("a.btn-next");
  11. /*End Customized to Enable Out Of Wizard Buttons*/
  12. d = this.$nextBtn.children().detach();
  13. this.nextText = b.trim(this.$nextBtn.text());
  14. this.$nextBtn.append(d);
  15. this.$prevBtn.on("click", b.proxy(this.previous, this));
  16. this.$nextBtn.on("click", b.proxy(this.next, this));
  17. this.$element.on("click", "li.complete", b.proxy(this.stepclicked, this));
  18. this.$stepContainer = this.$element.data("target") || "body";
  19. this.$stepContainer = b(this.$stepContainer)
  20. };
  21. a.prototype = {
  22. constructor: a,
  23. setState: function () {
  24. var n = (this.currentStep > 1);
  25. var o = (this.currentStep === 1);
  26. var d = (this.currentStep === this.numSteps);
  27. this.$prevBtn.attr("disabled", (o === true || n === false));
  28. var h = this.$nextBtn.data();
  29. if (h && h.last) {
  30. this.lastText = h.last;
  31. if (typeof this.lastText !== "undefined") {
  32. var l = (d !== true) ? this.nextText : this.lastText;
  33. var f = this.$nextBtn.children().detach();
  34. this.$nextBtn.text(l).append(f)
  35. }
  36. }
  37. var j = this.$element.find("li");
  38. j.removeClass("active").removeClass("complete");
  39. var m = "li:lt(" + (this.currentStep - 1) + ")";
  40. var g = this.$element.find(m);
  41. g.addClass("complete");
  42. var e = "li:eq(" + (this.currentStep - 1) + ")";
  43. var k = this.$element.find(e);
  44. k.addClass("active");
  45. var i = k.data().target;
  46. this.$stepContainer.find(".step-pane").removeClass("active");
  47. b(i).addClass("active");
  48. this.$element.trigger("changed")
  49. },
  50. stepclicked: function (h) {
  51. var d = b(h.currentTarget);
  52. var g = this.$element.find("li").index(d);
  53. var f = b.Event("change");
  54. this.$element.trigger(f, {
  55. step: g + 1,
  56. direction: "stepclicked",
  57. currentStep: g + 1
  58. });
  59. if (f.isDefaultPrevented()) {
  60. return
  61. }
  62. this.currentStep = (g + 1);
  63. this.setState()
  64. },
  65. previous: function () {
  66. var d = (this.currentStep > 1);
  67. if (d) {
  68. var f = b.Event("change");
  69. this.$element.trigger(f, {
  70. step: this.currentStep,
  71. direction: "previous",
  72. currentStep:this.currentStep-1
  73. });
  74. if (f.isDefaultPrevented()) {
  75. return
  76. }
  77. this.currentStep -= 1;
  78. this.setState()
  79. }
  80. },
  81. next: function () {
  82. var g = (this.currentStep + 1 <= this.numSteps);
  83. var d = (this.currentStep === this.numSteps);
  84. if (g) {
  85. var f = b.Event("change");
  86. this.$element.trigger(f, {
  87. step: this.currentStep,
  88. direction: "next",
  89. currentStep: this.currentStep + 1
  90. });
  91. if (f.isDefaultPrevented()) {
  92. return
  93. }
  94. this.currentStep += 1;
  95. this.setState()
  96. } else {
  97. if (d) {
  98. this.$element.trigger("finished")
  99. }
  100. }
  101. },
  102. selectedItem: function (d) {
  103. return {
  104. step: this.currentStep
  105. }
  106. }
  107. };
  108. b.fn.wizard = function (e, g) {
  109. var f;
  110. var d = this.each(function () {
  111. var j = b(this);
  112. var i = j.data("wizard");
  113. var h = typeof e === "object" && e;
  114. if (!i) {
  115. j.data("wizard", (i = new a(this, h)))
  116. }
  117. if (typeof e === "string") {
  118. f = i[e](g)
  119. }
  120. });
  121. return (f === c) ? d : f
  122. };
  123. b.fn.wizard.defaults = {};
  124. b.fn.wizard.Constructor = a;
  125. b(function () {
  126. b("body").on("mousedown.wizard.data-api", ".wizard", function () {
  127. var d = b(this);
  128. if (d.data("wizard")) {
  129. return
  130. }
  131. d.wizard(d.data())
  132. })
  133. })
  134. })(window.jQuery);