Guest User

Untitled

a guest
Aug 9th, 2015
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function (e)
  2. {
  3.     e.widget("ui.formwizard", {
  4.         _init: function ()
  5.         {
  6.             var t = this;
  7.             var n = this.options.formOptions.success;
  8.             var r = this.options.formOptions.complete;
  9.             var i = this.options.formOptions.beforeSend;
  10.             var s = this.options.formOptions.beforeSubmit;
  11.             var o = this.options.formOptions.beforeSerialize;
  12.             this.options.formOptions = e.extend(this.options.formOptions, {
  13.                 success: function (e, r, i)
  14.                 {
  15.                     if (n)
  16.                     {
  17.                         n(e, r, i)
  18.                     }
  19.                     if (t.options.formOptions && t.options.formOptions.resetForm || !t.options.formOptions)
  20.                     {
  21.                         t._reset()
  22.                     }
  23.                 },
  24.                 complete: function (e, n)
  25.                 {
  26.                     if (r)
  27.                     {
  28.                         r(e, n)
  29.                     }
  30.                     t._enableNavigation()
  31.                 },
  32.                 beforeSubmit: function (e, n, r)
  33.                 {
  34.                     if (s)
  35.                     {
  36.                         var i = s(e, n, r);
  37.                         if (!i) t._enableNavigation();
  38.                         return i
  39.                     }
  40.                 },
  41.                 beforeSend: function (e)
  42.                 {
  43.                     if (i)
  44.                     {
  45.                         var n = i(e);
  46.                         if (!n) t._enableNavigation();
  47.                         return n
  48.                     }
  49.                 },
  50.                 beforeSerialize: function (e, n)
  51.                 {
  52.                     if (o)
  53.                     {
  54.                         var r = o(e, n);
  55.                         if (!r) t._enableNavigation();
  56.                         return r
  57.                     }
  58.                 }
  59.             });
  60.             if (this.options.historyEnabled)
  61.             {
  62.                 e.bbq.removeState("_" + e(this.element).attr("id"))
  63.             }
  64.             this.steps = this.element.find(".step").hide();
  65.             this.firstStep = this.steps.eq(0).attr("id");
  66.             this.activatedSteps = new Array;
  67.             this.isLastStep = false;
  68.             this.previousStep = undefined;
  69.             this.currentStep = this.steps.eq(0).attr("id");
  70.             this.nextButton = this.element.find(this.options.next).click(function ()
  71.             {
  72.                 return t._next()
  73.             });
  74.             this.nextButtonInitinalValue = this.nextButton.val();
  75.             this.nextButton.val(this.options.textNext);
  76.             this.backButton = this.element.find(this.options.back).click(function ()
  77.             {
  78.                 t._back();
  79.                 return false
  80.             });
  81.             this.backButtonInitinalValue = this.backButton.val();
  82.             this.backButton.val(this.options.textBack);
  83.             if (this.options.validationEnabled && jQuery().validate == undefined)
  84.             {
  85.                 this.options.validationEnabled = false;
  86.                 if (window["console"] !== undefined)
  87.                 {
  88.                     console.log("%s", "validationEnabled option set, but the validation plugin is not included")
  89.                 }
  90.             }
  91.             else if (this.options.validationEnabled)
  92.             {
  93.                 this.element.validate(this.options.validationOptions)
  94.             }
  95.             if (this.options.formPluginEnabled && jQuery().ajaxSubmit == undefined)
  96.             {
  97.                 this.options.formPluginEnabled = false;
  98.                 if (window["console"] !== undefined)
  99.                 {
  100.                     console.log("%s", "formPluginEnabled option set but the form plugin is not included")
  101.                 }
  102.             }
  103.             if (this.options.disableInputFields == true)
  104.             {
  105.                 e(this.steps).find(":input:not('.wizard-ignore')").attr("disabled", "disabled")
  106.             }
  107.             if (this.options.historyEnabled)
  108.             {
  109.                 e(window).bind("hashchange", undefined, function (n)
  110.                 {
  111.                     var r = n.getState("_" + e(t.element).attr("id")) || t.firstStep;
  112.                     if (r !== t.currentStep)
  113.                     {
  114.                         if (t.options.validationEnabled && r === t._navigate(t.currentStep))
  115.                         {
  116.                             if (!t.element.valid())
  117.                             {
  118.                                 t._updateHistory(t.currentStep);
  119.                                 t.element.validate().focusInvalid();
  120.                                 return false
  121.                             }
  122.                         }
  123.                         if (r !== t.currentStep) t._show(r)
  124.                     }
  125.                 })
  126.             }
  127.             this.element.addClass("ui-formwizard");
  128.             this.element.find(":input").addClass("ui-wizard-content");
  129.             this.steps.addClass("ui-formwizard-content");
  130.             this.backButton.addClass("ui-formwizard-button ui-wizard-content");
  131.             this.nextButton.addClass("ui-formwizard-button ui-wizard-content");
  132.             if (!this.options.disableUIStyles)
  133.             {
  134.                 this.element.addClass("ui-helper-reset ui-widget ui-widget-content ui-helper-reset ui-corner-all");
  135.                 this.element.find(":input").addClass("ui-helper-reset ui-state-default");
  136.                 this.steps.addClass("ui-helper-reset ui-corner-all");
  137.                 this.backButton.addClass("ui-helper-reset ui-state-default");
  138.                 this.nextButton.addClass("ui-helper-reset ui-state-default")
  139.             }
  140.             this._show(undefined);
  141.             return e(this)
  142.         },
  143.         _next: function ()
  144.         {
  145.             if (this.options.validationEnabled)
  146.             {
  147.                 if (!this.element.valid())
  148.                 {
  149.                     this.element.validate().focusInvalid();
  150.                     return false
  151.                 }
  152.             }
  153.             if (this.options.remoteAjax != undefined)
  154.             {
  155.                 var t = this.options.remoteAjax[this.currentStep];
  156.                 var n = this;
  157.                 if (t !== undefined)
  158.                 {
  159.                     var r = t.success;
  160.                     var i = t.beforeSend;
  161.                     var s = t.complete;
  162.                     t = e.extend(
  163.                     {}, t, {
  164.                         success: function (e, t)
  165.                         {
  166.                             if (r !== undefined && r(e, t) || r == undefined)
  167.                             {
  168.                                 n._continueToNextStep()
  169.                             }
  170.                         },
  171.                         beforeSend: function (t)
  172.                         {
  173.                             n._disableNavigation();
  174.                             if (i !== undefined) i(t);
  175.                             e(n.element).trigger("before_remote_ajax", {
  176.                                 currentStep: n.currentStep
  177.                             })
  178.                         },
  179.                         complete: function (t, r)
  180.                         {
  181.                             if (s !== undefined) s(t, r);
  182.                             e(n.element).trigger("after_remote_ajax", {
  183.                                 currentStep: n.currentStep
  184.                             });
  185.                             n._enableNavigation()
  186.                         }
  187.                     });
  188.                     this.element.ajaxSubmit(t);
  189.                     return false
  190.                 }
  191.             }
  192.             return this._continueToNextStep()
  193.         },
  194.         _back: function ()
  195.         {
  196.             if (this.activatedSteps.length > 0)
  197.             {
  198.                 if (this.options.historyEnabled)
  199.                 {
  200.                     this._updateHistory(this.activatedSteps[this.activatedSteps.length - 2])
  201.                 }
  202.                 else
  203.                 {
  204.                     this._show(this.activatedSteps[this.activatedSteps.length - 2], true)
  205.                 }
  206.             }
  207.             return false
  208.         },
  209.         _continueToNextStep: function ()
  210.         {
  211.             if (this.isLastStep)
  212.             {
  213.                 for (var e = 0; e < this.activatedSteps.length; e++)
  214.                 {
  215.                     this.steps.filter("#" + this.activatedSteps[e]).find(":input").not(".wizard-ignore").removeAttr("disabled")
  216.                 }
  217.                 if (!this.options.formPluginEnabled)
  218.                 {
  219.                     return true
  220.                 }
  221.                 else
  222.                 {
  223.                     this._disableNavigation();
  224.                     this.element.ajaxSubmit(this.options.formOptions);
  225.                     return false
  226.                 }
  227.             }
  228.             var t = this._navigate(this.currentStep);
  229.             if (t == this.currentStep)
  230.             {
  231.                 return false
  232.             }
  233.             if (this.options.historyEnabled)
  234.             {
  235.                 this._updateHistory(t)
  236.             }
  237.             else
  238.             {
  239.                 this._show(t, true)
  240.             }
  241.             return false
  242.         },
  243.         _updateHistory: function (t)
  244.         {
  245.             var n = {};
  246.             n["_" + e(this.element).attr("id")] = t;
  247.             e.bbq.pushState(n)
  248.         },
  249.         _disableNavigation: function ()
  250.         {
  251.             this.nextButton.attr("disabled", "disabled");
  252.             this.backButton.attr("disabled", "disabled");
  253.             if (!this.options.disableUIStyles)
  254.             {
  255.                 this.nextButton.removeClass("ui-state-active").addClass("ui-state-disabled");
  256.                 this.backButton.removeClass("ui-state-active").addClass("ui-state-disabled")
  257.             }
  258.         },
  259.         _enableNavigation: function ()
  260.         {
  261.             if (this.isLastStep)
  262.             {
  263.                 this.nextButton.val(this.options.textSubmit)
  264.             }
  265.             else
  266.             {
  267.                 this.nextButton.val(this.options.textNext)
  268.             }
  269.             if (e.trim(this.currentStep) !== this.steps.eq(0).attr("id"))
  270.             {
  271.                 this.backButton.removeAttr("disabled");
  272.                 if (!this.options.disableUIStyles)
  273.                 {
  274.                     this.backButton.removeClass("ui-state-disabled").addClass("ui-state-active")
  275.                 }
  276.             }
  277.             this.nextButton.removeAttr("disabled");
  278.             if (!this.options.disableUIStyles)
  279.             {
  280.                 this.nextButton.removeClass("ui-state-disabled").addClass("ui-state-active")
  281.             }
  282.         },
  283.         _animate: function (e, t, n)
  284.         {
  285.             this._disableNavigation();
  286.             var r = this.steps.filter("#" + e);
  287.             var i = this.steps.filter("#" + t);
  288.             r.find(":input").not(".wizard-ignore").attr("disabled", "disabled");
  289.             i.find(":input").not(".wizard-ignore").removeAttr("disabled");
  290.             var s = this;
  291.             r.animate(s.options.outAnimation, s.options.outDuration, s.options.easing, function ()
  292.             {
  293.                 i.animate(s.options.inAnimation, s.options.inDuration, s.options.easing, function ()
  294.                 {
  295.                     if (s.options.focusFirstInput) i.find(":input:first").focus();
  296.                     s._enableNavigation();
  297.                     n.apply(s)
  298.                 });
  299.                 return
  300.             })
  301.         },
  302.         _checkIflastStep: function (t)
  303.         {
  304.             this.isLastStep = false;
  305.             if (e("#" + t).hasClass(this.options.submitStepClass) || this.steps.filter(":last").attr("id") == t)
  306.             {
  307.                 this.isLastStep = true
  308.             }
  309.         },
  310.         _getLink: function (t)
  311.         {
  312.             var n = undefined;
  313.             var r = this.steps.filter("#" + t).find(this.options.linkClass);
  314.             if (r != undefined)
  315.             {
  316.                 if (r.filter(":radio,:checkbox").size() > 0)
  317.                 {
  318.                     n = r.filter(this.options.linkClass + ":checked").val()
  319.                 }
  320.                 else
  321.                 {
  322.                     n = e(r).val()
  323.                 }
  324.             }
  325.             return n
  326.         },
  327.         _navigate: function (e)
  328.         {
  329.             var t = this._getLink(e);
  330.             if (t != undefined)
  331.             {
  332.                 if (t != "" && t != null && t != undefined && this.steps.filter("#" + t).attr("id") != undefined)
  333.                 {
  334.                     return t
  335.                 }
  336.                 return this.currentStep
  337.             }
  338.             else if (t == undefined && !this.isLastStep)
  339.             {
  340.                 var n = this.steps.filter("#" + e).next().attr("id");
  341.                 return n
  342.             }
  343.         },
  344.         _show: function (t)
  345.         {
  346.             var n = false;
  347.             var r = t !== undefined;
  348.             if (t == undefined || t == "")
  349.             {
  350.                 this.activatedSteps.pop();
  351.                 t = this.firstStep;
  352.                 this.activatedSteps.push(t)
  353.             }
  354.             else
  355.             {
  356.                 if (e.inArray(t, this.activatedSteps) > -1)
  357.                 {
  358.                     n = true;
  359.                     this.activatedSteps.pop()
  360.                 }
  361.                 else
  362.                 {
  363.                     this.activatedSteps.push(t)
  364.                 }
  365.             }
  366.             if (this.currentStep !== t || t === this.firstStep)
  367.             {
  368.                 this.previousStep = this.currentStep;
  369.                 this._checkIflastStep(t);
  370.                 this.currentStep = t;
  371.                 var i = function ()
  372.                     {
  373.                         if (r)
  374.                         {
  375.                             e(this.element).trigger("step_shown", e.extend(
  376.                             {
  377.                                 isBackNavigation: n
  378.                             }, this._state()))
  379.                         }
  380.                     };
  381.                 if (r)
  382.                 {
  383.                     e(this.element).trigger("before_step_shown", e.extend(
  384.                     {
  385.                         isBackNavigation: n
  386.                     }, this._state()))
  387.                 }
  388.                 this._animate(this.previousStep, t, i)
  389.             }
  390.         },
  391.         _reset: function ()
  392.         {
  393.             this.element.resetForm();
  394.             e("label,:input,textarea", this).removeClass("error");
  395.             for (var t = 0; t < this.activatedSteps.length; t++)
  396.             {
  397.                 this.steps.filter("#" + this.activatedSteps[t]).hide().find(":input").attr("disabled", "disabled")
  398.             }
  399.             this.activatedSteps = new Array;
  400.             this.previousStep = undefined;
  401.             this.isLastStep = false;
  402.             if (this.options.historyEnabled)
  403.             {
  404.                 historyEnabled: false,
  405.                 validationEnabled: false,
  406.                 validationOptions: undefined,
  407.                 formPluginEnabled: false,
  408.                 linkClass: ".link",
  409.                 submitStepClass: "submit_step",
  410.                 back: ":reset",
  411.                 next: ":submit",
  412.                 textSubmit: "Submit",
  413.                 textNext: "Next",
  414.                 textBack: "Back",
  415.                 remoteAjax: undefined,
  416.                 inAnimation: {
  417.                     opacity: "show"
  418.                 },
  419.                 outAnimation: {
  420.                     opacity: "hide"
  421.                 },
  422.                 inDuration: 400,
  423.                 outDuration: 400,
  424.                 easing: "swing",
  425.                 focusFirstInput: false,
  426.                 disableInputFields: true,
  427.                 formOptions: {
  428.                     reset: true,
  429.                     success: function (e)
  430.                     {
  431.                         if (window["console"] !== undefined)
  432.                         {
  433.                             console.log("%s", "form submit successful")
  434.                         }
  435.                     },
  436.                     disableUIStyles: false
  437.                 }
  438.             }
  439.         })
  440.     })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment