Advertisement
Guest User

Untitled

a guest
May 31st, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. (function($) {
  2. $.fn.formToWizard = function(options) {
  3. options = $.extend({
  4. submitButton: ""
  5. }, options);
  6.  
  7. var element = this;
  8.  
  9. var steps = $(element).find(".fieldset");
  10. var count = steps.size();
  11. var submmitButtonName = "#" + options.submitButton;
  12. $(submmitButtonName).hide();
  13.  
  14. // 2
  15. $(element).before("<ul id='steps'></ul>");
  16.  
  17. steps.each(function(i) {
  18. $(this).wrap("<div id='step" + i + "'></div>");
  19. $(this).append("<p id='step" + i + "commands'></p>");
  20.  
  21. // 2
  22. var name = $(this).find("legend").html();
  23. $("#steps").append("<li id='stepDesc" + i + "'> " + (i + 1) + "<span>" + name + "</span></li>");
  24.  
  25. if (i == 0) {
  26. createNextButton(i);
  27. selectStep(i);
  28. } else if (i == count - 1) {
  29. $("#step" + i).hide();
  30. createPrevButton(i);
  31. } else {
  32. $("#step" + i).hide();
  33. createPrevButton(i);
  34. createNextButton(i);
  35. }
  36. });
  37.  
  38. function createPrevButton(i) {
  39. var stepName = "step" + i;
  40. $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Prev' class='prev'> Back</a>");
  41.  
  42. $("#" + stepName + "Prev").bind("click", function(e) {
  43. $("#" + stepName).hide();
  44. $("#step" + (i - 1)).show();
  45. $(submmitButtonName).hide();
  46. selectStep(i - 1);
  47. });
  48. }
  49.  
  50. function createNextButton(i) {
  51. var stepName = "step" + i;
  52. $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'> Next </a>");
  53.  
  54. $("#" + stepName + "Next").bind("click", function(e) {
  55. $("#" + stepName).hide();
  56. $("#step" + (i + 1)).show();
  57. if (i + 2 == count)
  58. $(submmitButtonName).show();
  59. selectStep(i + 1);
  60. });
  61. }
  62.  
  63. function selectStep(i) {
  64. $("#steps li").removeClass("current");
  65. $("#stepDesc" + i).addClass("current");
  66. }
  67.  
  68. }
  69. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement