-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.AstroForm.min.js
1 lines (1 loc) · 5.88 KB
/
jquery.AstroForm.min.js
1
(function(b){function a(d,c){this.astroformClass="astroform-wizard";this.submitClass="astroform-submit";this.resetClass="astroform-reset";this.nextButtonClass="astroform-nav-next";this.backButtonClass="astroform-nav-back";this.stepsListClass="astroform-steps";this.stepsLegendPrefix="astroform-stepsDesc";this.autoNavClass="astroform-auto-nav";this.stepsLabel="Step";this.autoNextLabel="Next";this.autoPrevLabel="Back";this.currentClass="current";this.resetLabel="Reset";this._anchorBase="";this.autoCreateNav=true;this.createStepsList=true;this.clearOnSubmit=true;this.navToJqueryUi=false;this.useAnchorBase=false;this.preventDefaultOnNav=true;this.fieldSets=[];this.thisElement=null;this.currentStep=null;this.stopEvents=false;this.showReset=true;b.extend(this,c);this.thisElement=b(d);this.thisElement.trigger("firstStep");this.currentStep=0;this.thisElement.addClass(this.astroformClass);this.fieldSets=this.thisElement.find("fieldset");if(this.autoCreateNav===true){this._createNav()}if(this.useAnchorBase===true){this._anchorBase=location}this.thisElement.find("."+this.submitClass).hide();this.thisElement.prepend('<ul class="'+this.stepsListClass+'"></ul>');this.thisElement.find("."+this.submitClass).hide();this.thisElement.find("."+this.backButtonClass).hide();this.fieldSets.hide();b(this.fieldSets[0]).show();this._rebuildStepsList();this._updateCurrentStep();if(this.navToJqueryUi===true){this.thisElement.find("."+this.submitClass).button();this.thisElement.find("."+this.nextButtonClass).button();this.thisElement.find("."+this.backButtonClass).button()}if(this.navToJqueryUi===true){b("."+this.autoNavClass).find("a, input").button()}this._registerEvents()}a.prototype.next=function(){if(this.currentStep===this.fieldSets.length-1){return}if(!this.stopEvents){this.thisElement.trigger("preStepChange")}b(this.fieldSets[this.currentStep]).hide();b(this.fieldSets[++this.currentStep]).show();if(this.currentStep===0){this.thisElement.find("."+this.backButtonClass).hide()}else{this.thisElement.find("."+this.backButtonClass).show()}this._updateCurrentStep();if(this.currentStep===this.fieldSets.length-1){this.thisElement.find("."+this.submitClass).show();this.thisElement.find("."+this.nextButtonClass).hide();this.thisElement.trigger("finalStep")}if(!this.stopEvents){this.thisElement.trigger("postStepChange")}};a.prototype.back=function(){if(this.currentStep===0){return}if(!this.stopEvents){this.thisElement.trigger("preStepChange")}b(this.fieldSets[this.currentStep]).hide();b(this.fieldSets[--this.currentStep]).show();if(this.currentStep===0){this.thisElement.find("."+this.backButtonClass).hide()}else{this.thisElement.find("."+this.backButtonClass).show()}this._updateCurrentStep();this.thisElement.find("."+this.submitClass).hide();this.thisElement.find("."+this.nextButtonClass).show();if(!this.stopEvents){this.thisElement.trigger("postStepChange")}};a.prototype._updateCurrentStep=function(){this.thisElement.find("."+this.stepsListClass+" li").removeClass(this.currentClass);this.thisElement.find("."+this.stepsLegendPrefix+this.currentStep).addClass(this.currentClass)};a.prototype._rebuildStepsList=function(){this.fieldSets=this.thisElement.find("fieldset");var d=this.thisElement.find("."+this.stepsListClass).empty();var c=this;this.fieldSets.each(function(f){var e=b(this).find("legend").html();d.append('<li class="'+c.stepsLegendPrefix+f+'">Step '+(f+1)+"<span>"+e+"</span></li>")})};a.prototype._createNav=function(){var c=this.thisElement.find(":reset"),e='<input class="'+this.resetClass+'" type="reset" value="'+c.val()+'"/>',d=this.thisElement.find(":submit").remove().clone();if(c.length){c.remove()}this.thisElement.append('<div class="'+this.autoNavClass+'"><a class="'+this.backButtonClass+'" href="'+this._anchorBase+'#">'+this.autoPrevLabel+'</a><input class="'+this.submitClass+" "+d.attr("class")+'" value="'+d.val()+'" type="submit"><a class="'+this.nextButtonClass+'" href="'+this._anchorBase+'#">'+this.autoNextLabel+"</a>"+e+"</div>");if(!this.showReset){this.thisElement.find("."+this.resetClass).hide()}};a.prototype.gotoFirstStep=function(){this.stopEvents=true;var c=this.currentStep;for(c;c>0;c--){this.back()}this.stopEvents=false;this.thisElement.trigger("firstStep")};a.prototype.gotoLastStep=function(){this.stopEvents=true;var c=this.currentStep;for(c;c<this.fieldSets.length;c++){this.next()}this.stopEvents=false;this.thisElement.trigger("lastStep")};a.prototype.gotoStep=function(c){var e=null;if(c instanceof Array){e=c[0]}else{e=c}if(this.currentStep===e){return}this.stopEvents=true;var d=this.currentStep;if(this.currentStep>e){for(d;d>e;d--){this.back()}}else{for(d;d<e;d++){this.next()}}this.stopEvents=false};a.prototype.createStepAt=function(c){var e=c[0],d=c[1];this.thisElement.trigger("preStepCreation");this.fieldSets.eq(d).before(e);if(this.currentStep>=d){this.currentStep++}this._rebuildStepsList();b(this.fieldSets[d]).hide();this._updateCurrentStep();this.thisElement.trigger("postStepCreation")};a.prototype.removeStep=function(c){var d=null;if(c instanceof Array){d=c[0]}else{d=c}this.thisElement.trigger("preStepRemoval");this.fieldSets.eq(d).remove();if(this.currentStep===d){this.next()}if(this.currentStep>d){this.currentStep--}this._rebuildStepsList();this._updateCurrentStep();this.thisElement.trigger("postStepRemoval")};a.prototype.getCurrentStep=function(){return this.currentStep};a.prototype.reset=function(){this.thisElement.find("."+this.resetClass).click()};a.prototype._registerEvents=function(){var c=this;this.thisElement.find("."+this.nextButtonClass).click(function(d){if(c.preventDefaultOnNav){d.preventDefault()}c.next()});this.thisElement.find("."+this.backButtonClass).click(function(d){if(c.preventDefaultOnNav){d.preventDefault()}c.back()})};b.fn.AstroForm=function(d,c){var f=[],e;this.each(function(g,i){var h=b(this);var j=h.data("AstroForm")?h.data("AstroForm"):function(){var k=new a(this,d);h.data("AstroForm",k);return k}.call(this);if(j[d]){e=j[d].call(j,c)}f[g]=(e!==undefined)?e:i});return f}}(jQuery));