big-moving.ru/assets/vendor_components/jquery-wizard-master/dist/jquery-wizard.min.js

4 lines
11 KiB
JavaScript
Executable File

/*! jQuery wizard - v0.3.1 - 2015-05-07
* https://github.com/amazingSurge/jquery-wizard
* Copyright (c) 2015 amazingSurge; Licensed GPL */
!function(a,b,c,d){"use strict";function e(a,b){var c=!1;a.one(g.transition.end,function(){c=!0});var d=function(){c||a.trigger(g.transition.end)};setTimeout(d,b)}function f(){return this.initialize.apply(this,Array.prototype.slice.call(arguments))}var g=function(){function b(b,c){var g=!1,h=b.charAt(0).toUpperCase()+b.slice(1);return e[b]!==d&&(g=b),g||a.each(f,function(a,b){return e[b+h]!==d?(g="-"+b.toLowerCase()+"-"+h,!1):void 0}),c?g:g?!0:!1}function c(a){return b(a,!0)}var e=a("<support>").get(0).style,f=["webkit","Moz","O","ms"],g={transition:{end:{WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd",transition:"transitionend"}}},h={csstransitions:function(){return!!b("transition")}},i={};return h.csstransitions()&&(i.transition=new String(c("transition")),i.transition.end=g.transition.end[i.transition]),i}(),h=0,i=function(b,c){this.$element=a(b),this.options=a.extend(!0,{},i.defaults,c),this.$steps=this.$element.find(this.options.step),this.id=this.$element.attr("id"),this.id||(this.id="wizard-"+ ++h,this.$element.attr("id",this.id)),this.initialize()};i.defaults={step:".wizard-steps > li",getPane:function(a,b){return this.$element.find(".wizard-content").children().eq(a)},buttonsAppendTo:"this",templates:{buttons:function(){var a=this.options;return'<div class="wizard-buttons"><a class="wizard-back" href="#'+this.id+'" data-wizard="back" role="button">'+a.buttonLabels.back+'</a><a class="wizard-next" href="#'+this.id+'" data-wizard="next" role="button">'+a.buttonLabels.next+'</a><a class="wizard-finish" href="#'+this.id+'" data-wizard="finish" role="button">'+a.buttonLabels.finish+"</a></div>"}},classes:{step:{done:"done",error:"error",active:"current",disabled:"disabled",activing:"activing",loading:"loading"},pane:{active:"active",activing:"activing"},button:{hide:"hide",disabled:"disabled"}},autoFocus:!0,keyboard:!0,enableWhenVisited:!1,buttonLabels:{next:"Next",back:"Back",finish:"Finish"},loading:{show:function(a){},hide:function(a){},fail:function(a){}},cacheContent:!1,validator:function(a){return!0},onInit:null,onNext:null,onBack:null,onReset:null,onBeforeShow:null,onAfterShow:null,onBeforeHide:null,onAfterHide:null,onBeforeLoad:null,onAfterLoad:null,onBeforeChange:null,onAfterChange:null,onStateChange:null,onFinish:null},a.extend(f.prototype,{TRANSITION_DURATION:200,initialize:function(b,c,d){this.$element=a(b),this.wizard=c,this.events={},this.loader=null,this.loaded=!1,this.validator=this.wizard.options.validator,this.states={done:!1,error:!1,active:!1,disabled:!1,activing:!1},this.index=d,this.$element.data("wizard-index",d),this.$pane=this.getPaneFromTarget(),this.$pane||(this.$pane=this.wizard.options.getPane.call(this.wizard,d,b)),this.setValidatorFromData(),this.setLoaderFromData()},getPaneFromTarget:function(){var b=this.$element.data("target");return b||(b=this.$element.attr("href"),b=b&&b.replace(/.*(?=#[^\s]*$)/,"")),b?a(b):null},setup:function(){var a=this.wizard.currentIndex();this.index===a?(this.enter("active"),this.loader&&this.load()):this.index>a&&this.enter("disabled"),this.$element.attr("aria-expanded",this.is("active")),this.$pane.attr("aria-expanded",this.is("active"));var b=this.wizard.options.classes;this.is("active")?this.$pane.addClass(b.pane.active):this.$pane.removeClass(b.pane.active)},show:function(b){if(!this.is("activing")&&!this.is("active")){this.trigger("beforeShow"),this.enter("activing");var c=this.wizard.options.classes;this.$element.attr("aria-expanded",!0),this.$pane.addClass(c.pane.activing).addClass(c.pane.active).attr("aria-expanded",!0);var d=function(){this.$pane.removeClass(c.pane.activing),this.leave("activing"),this.enter("active"),this.trigger("afterShow"),a.isFunction(b)&&b.call(this)};if(!g.transition)return d.call(this);this.$pane.one(g.transition.end,a.proxy(d,this)),e(this.$pane,this.TRANSITION_DURATION)}},hide:function(b){if(!this.is("activing")&&this.is("active")){this.trigger("beforeHide"),this.enter("activing");var c=this.wizard.options.classes;this.$element.attr("aria-expanded",!1),this.$pane.addClass(c.pane.activing).removeClass(c.pane.active).attr("aria-expanded",!1);var d=function(){this.$pane.removeClass(c.pane.activing),this.leave("activing"),this.leave("active"),this.trigger("afterHide"),a.isFunction(b)&&b.call(this)};if(!g.transition)return d.call(this);this.$pane.one(g.transition.end,a.proxy(d,this)),e(this.$pane,this.TRANSITION_DURATION)}},empty:function(){this.$pane.empty()},load:function(b){function c(c){d.$pane.html(c),d.leave("loading"),d.loaded=!0,d.trigger("afterLoad"),a.isFunction(b)&&b.call(d)}var d=this,e=this.loader;return a.isFunction(e)&&(e=e.call(this.wizard,this)),this.wizard.options.cacheContent&&this.loaded?(a.isFunction(b)&&b.call(this),!0):(this.trigger("beforeLoad"),this.enter("loading"),void("string"==typeof e?c(e):"object"==typeof e&&e.hasOwnProperty("url")?(d.wizard.options.loading.show.call(d.wizard,d),a.ajax(e.url,e.settings||{}).done(function(a){c(a),d.wizard.options.loading.hide.call(d.wizard,d)}).fail(function(){d.wizard.options.loading.fail.call(d.wizard,d)})):c("")))},trigger:function(b){var c=Array.prototype.slice.call(arguments,1);if(a.isArray(this.events[b]))for(var d in this.events[b])this.events[b][d].apply(this,c);this.wizard.trigger.apply(this.wizard,[b,this].concat(c))},enter:function(a){this.states[a]=!0;var b=this.wizard.options.classes;this.$element.addClass(b.step[a]),this.trigger("stateChange",!0,a)},leave:function(a){if(this.states[a]){this.states[a]=!1;var b=this.wizard.options.classes;this.$element.removeClass(b.step[a]),this.trigger("stateChange",!1,a)}},setValidatorFromData:function(){var b=this.$pane.data("validator");b&&a.isFunction(c[b])&&(this.validator=c[b])},setLoaderFromData:function(){var b=this.$pane.data("loader");if(b)a.isFunction(c[b])&&(this.loader=c[b]);else{var d=this.$pane.data("loader-url");d&&(this.loader={url:d,settings:this.$pane.data("settings")||{}})}},active:function(){return this.wizard.goTo(this.index)},on:function(b,c){return a.isFunction(c)&&(a.isArray(this.events[b])?this.events[b].push(c):this.events[b]=[c]),this},off:function(b,c){return a.isFunction(c)&&a.isArray(this.events[b])&&a.each(this.events[b],function(a,d){return d===c?(delete this.events[b][a],!1):void 0}),this},is:function(a){return this.states[a]&&this.states[a]===!0},reset:function(){for(var a in this.states)this.leave(a);return this.setup(),this},setLoader:function(a){return this.loader=a,this.is("active")&&this.load(),this},setValidator:function(b){return a.isFunction(b)&&(this.validator=b),this},validate:function(){return this.validator.call(this.$pane.get(0),this)}}),a.extend(i.prototype,{Constructor:i,initialize:function(){this.steps=[];var c=this;this.$steps.each(function(a){c.steps.push(new f(this,c,a))}),this._current=0,this.transitioning=null,a.each(this.steps,function(a,b){b.setup()}),this.setup(),this.$element.on("click",this.options.step,function(b){var d=a(this).data("wizard-index");c.get(d).is("disabled")||c.goTo(d),b.preventDefault(),b.stopPropagation()}),this.options.keyboard&&a(b).on("keyup",a.proxy(this.keydown,this)),this.trigger("init")},setup:function(){this.$buttons=a(this.options.templates.buttons.call(this)),this.updateButtons();var b,c=this.options.buttonsAppendTo;b="this"===c?this.$element:a.isFunction(c)?c.call(this):this.$element.find(c),this.$buttons=this.$buttons.appendTo(b)},updateButtons:function(){var a=this.options.classes.button,b=this.$buttons.find('[data-wizard="back"]'),c=this.$buttons.find('[data-wizard="next"]'),d=this.$buttons.find('[data-wizard="finish"]');0===this._current?b.addClass(a.disabled):b.removeClass(a.disabled),this._current===this.lastIndex()?(c.addClass(a.hide),d.removeClass(a.hide)):(c.removeClass(a.hide),d.addClass(a.hide))},updateSteps:function(){var b=this;a.each(this.steps,function(a,c){a>b._current&&(c.leave("error"),c.leave("active"),c.leave("done"),b.options.enableWhenVisited||c.enter("disabled"))})},keydown:function(a){if(!/input|textarea/i.test(a.target.tagName)){switch(a.which){case 37:this.back();break;case 39:this.next();break;default:return}a.preventDefault()}},trigger:function(a){var b=Array.prototype.slice.call(arguments,1),c=[this].concat(b);this.$element.trigger("wizard::"+a,c),a=a.replace(/\b\w+\b/g,function(a){return a.substring(0,1).toUpperCase()+a.substring(1)});var d="on"+a;"function"==typeof this.options[d]&&this.options[d].apply(this,b)},get:function(a){if("string"==typeof a&&"#"===a.substring(0,1)){var b=a.substring(1);for(var c in this.steps)if(this.steps[c].$pane.attr("id")===b)return this.steps[c]}return a<this.length()&&this.steps[a]?this.steps[a]:null},goTo:function(b,c){if(b===this._current||this.transitioning===!0)return!1;var d=this.current(),e=this.get(b);if(b>this._current){if(!d.validate())return d.leave("done"),d.enter("error"),-1;d.leave("error"),b>this._current&&d.enter("done")}var f=this,g=function(){f.trigger("beforeChange",d,e),f.transitioning=!0,d.hide(),e.show(function(){if(f._current=b,f.transitioning=!1,this.leave("disabled"),f.updateButtons(),f.updateSteps(),f.options.autoFocus){var g=this.$pane.find(":input");g.length>0?g.eq(0).focus():this.$pane.focus()}a.isFunction(c)&&c.call(f),f.trigger("afterChange",d,e)})};return e.loader?e.load(function(){g()}):g(),!0},length:function(){return this.steps.length},current:function(){return this.get(this._current)},currentIndex:function(){return this._current},lastIndex:function(){return this.length()-1},next:function(){if(this._current<this.lastIndex()){var a=this._current,b=this._current+1;this.goTo(b,function(){this.trigger("next",this.get(a),this.get(b))})}return!1},back:function(){if(this._current>0){var a=this._current,b=this._current-1;this.goTo(b,function(){this.trigger("back",this.get(a),this.get(b))})}return!1},first:function(){return this.goTo(0)},finish:function(){if(this._current===this.lastIndex()){var a=this.current();a.validate()?(this.trigger("finish"),a.leave("error"),a.enter("done")):a.enter("error")}},reset:function(){this._current=0,a.each(this.steps,function(a,b){b.reset()}),this.trigger("reset")}}),a(b).on("click","[data-wizard]",function(b){var c,d=a(this),e=a(d.attr("data-target")||(c=d.attr("href"))&&c.replace(/.*(?=#[^\s]+$)/,"")),f=e.data("wizard");if(f){var g=d.data("wizard");/^(back|next|first|finish|reset)$/.test(g)&&f[g](),b.preventDefault()}}),a.fn.wizard=function(b){if("string"!=typeof b)return this.each(function(){a.data(this,"wizard")||a.data(this,"wizard",new i(this,b))});var c=b,d=Array.prototype.slice.call(arguments,1);if(/^\_/.test(c))return!1;if(!/^(get)$/.test(c))return this.each(function(){var b=a.data(this,"wizard");b&&"function"==typeof b[c]&&b[c].apply(b,d)});var e=this.first().data("wizard");return e&&"function"==typeof e[c]?e[c].apply(e,d):void 0}}(jQuery,document,window);