mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
5 lines
7.5 KiB
JavaScript
Executable file
5 lines
7.5 KiB
JavaScript
Executable file
/* Materializecss Stepper - By Kinark 2016
|
|
// https://github.com/Kinark/Materialize-stepper
|
|
// JS.min v2.1.3
|
|
*/
|
|
var validation=$.isFunction($.fn.valid)?1:0;$.fn.isValid=function(){return!validation||this.valid()},validation&&$.validator.setDefaults({errorClass:"invalid",validClass:"valid",errorPlacement:function(a,b){b.is(":radio")||b.is(":checkbox")?a.insertBefore($(b).parent()):a.insertAfter(b)},success:function(a){$(a).closest("li").find("label.invalid:not(:empty)").length||$(a).closest("li").removeClass("wrong")}}),$.fn.getActiveStep=function(){return active=this.find(".step.active"),$(this.children(".step:visible")).index($(active))+1},$.fn.activateStep=function(a){$(this).hasClass("step")||(stepper=$(this).closest("ul.stepper"),stepper.find(">li").removeAttr("data-last"),window.innerWidth<993||!stepper.hasClass("horizontal")?$(this).addClass("step").stop().slideDown(400,function(){$(this).css({height:"auto","margin-bottom":"",display:"inherit"}),a&&a(),stepper.find(">li.step").last().attr("data-last","true")}):$(this).addClass("step").stop().css({width:"0%",display:"inherit"}).animate({width:"100%"},400,function(){$(this).css({height:"auto","margin-bottom":"",display:"inherit"}),a&&a(),stepper.find(">li.step").last().attr("data-last","true")}))},$.fn.deactivateStep=function(a){$(this).hasClass("step")&&(stepper=$(this).closest("ul.stepper"),stepper.find(">li").removeAttr("data-last"),window.innerWidth<993||!stepper.hasClass("horizontal")?$(this).stop().css({transition:"none","-webkit-transition":"margin-bottom none"}).slideUp(400,function(){$(this).removeClass("step").css({height:"auto","margin-bottom":"",transition:"margin-bottom .4s","-webkit-transition":"margin-bottom .4s"}),a&&a(),stepper.find(">li").removeAttr("data-last"),stepper.find(">li.step").last().attr("data-last","true")}):$(this).stop().animate({width:"0%"},400,function(){$(this).removeClass("step").hide().css({height:"auto","margin-bottom":"",display:"none",width:""}),a&&a(),stepper.find(">li.step").last().attr("data-last","true")}))},$.fn.showError=function(a){if(validation){name=this.attr("name"),form=this.closest("form");var b={};b[name]=a,form.validate().showErrors(b),this.closest("li").addClass("wrong")}else this.removeClass("valid").addClass("invalid"),this.next().attr("data-error",a)},$.fn.activateFeedback=function(){active=this.find(".step.active:not(.feedbacking)").addClass("feedbacking").find(".step-content"),active.prepend('<div class="wait-feedback"> <div class="preloader-wrapper active"> <div class="spinner-layer spinner-blue"> <div class="circle-clipper left"> <div class="circle"></div></div><div class="gap-patch"> <div class="circle"></div></div><div class="circle-clipper right"> <div class="circle"></div></div></div><div class="spinner-layer spinner-red"> <div class="circle-clipper left"> <div class="circle"></div></div><div class="gap-patch"> <div class="circle"></div></div><div class="circle-clipper right"> <div class="circle"></div></div></div><div class="spinner-layer spinner-yellow"> <div class="circle-clipper left"> <div class="circle"></div></div><div class="gap-patch"> <div class="circle"></div></div><div class="circle-clipper right"> <div class="circle"></div></div></div><div class="spinner-layer spinner-green"> <div class="circle-clipper left"> <div class="circle"></div></div><div class="gap-patch"> <div class="circle"></div></div><div class="circle-clipper right"> <div class="circle"></div></div></div></div></div>')},$.fn.destroyFeedback=function(){return active=this.find(".step.active.feedbacking"),active&&(active.removeClass("feedbacking"),active.find(".wait-feedback").remove()),!0},$.fn.resetStepper=function(a){return a||(a=1),form=$(this).closest("form"),$(form)[0].reset(),Materialize.updateTextFields(),$(this).openStep(a)},$.fn.submitStepper=function(a){form=this.closest("form"),form.isValid()&&form.submit()},$.fn.nextStep=function(a,b,c){return stepper=this,settings=$(stepper).data("settings"),form=this.closest("form"),active=this.find(".step.active"),next=$(this.children(".step:visible")).index($(active))+2,feedback=active.find(".next-step").length>1?c?$(c.target).data("feedback"):void 0:active.find(".next-step").data("feedback"),form.isValid()?feedback&&b?(settings.showFeedbackLoader&&stepper.activateFeedback(),window[feedback].call()):(active.removeClass("wrong").addClass("done"),this.openStep(next,a),this.trigger("nextstep")):active.removeClass("done").addClass("wrong")},$.fn.prevStep=function(a){if(active=this.find(".step.active"),!active.hasClass("feedbacking"))return prev=$(this.children(".step:visible")).index($(active)),active.removeClass("wrong"),this.openStep(prev,a),this.trigger("prevstep")},$.fn.openStep=function(a,b){settings=$(this).closest("ul.stepper").data("settings"),$this=this,step_num=a-1,a=this.find(".step:visible:eq("+step_num+")"),a.hasClass("active")||(active=this.find(".step.active"),prev_active=next=$(this.children(".step:visible")).index($(active)),order=step_num>prev_active?1:0,active.hasClass("feedbacking")&&$this.destroyFeedback(),active.closeAction(order),a.openAction(order,function(){settings.autoFocusInput&&a.find("input:enabled:visible:first").focus(),$this.trigger("stepchange").trigger("step"+(step_num+1)),a.data("event")&&$this.trigger(a.data("event")),b&&b()}))},$.fn.closeAction=function(a,b){closable=this.removeClass("active").find(".step-content"),window.innerWidth<993||!this.closest("ul").hasClass("horizontal")?closable.stop().slideUp(300,"easeOutQuad",b):1==a?closable.animate({left:"-100%"},function(){closable.css({display:"none",left:"0%"},b)}):closable.animate({left:"100%"},function(){closable.css({display:"none",left:"0%"},b)})},$.fn.openAction=function(a,b){openable=this.removeClass("done").addClass("active").find(".step-content"),window.innerWidth<993||!this.closest("ul").hasClass("horizontal")?openable.slideDown(300,"easeOutQuad",b):1==a?openable.css({left:"100%",display:"block"}).animate({left:"0%"},b):openable.css({left:"-100%",display:"block"}).animate({left:"0%"},b)},$.fn.activateStepper=function(a){var b=$.extend({linearStepsNavigation:!0,autoFocusInput:!0,showFeedbackLoader:!0,autoFormCreation:!0},a);$(document).on("click",function(a){$(a.target).parents(".stepper").length||$(".stepper.focused").removeClass("focused")}),$(this).each(function(){var a=$(this);!a.parents("form").length&&b.autoFormCreation&&(method=a.data("method"),action=a.data("action"),method=method?method:"GET",action=action?action:"?",a.wrap('<form action="'+action+'" method="'+method+'"></div>')),a.data("settings",{linearStepsNavigation:b.linearStepsNavigation,autoFocusInput:b.autoFocusInput,showFeedbackLoader:b.showFeedbackLoader}),a.find("li.step.active").openAction(1),a.find(">li").removeAttr("data-last"),a.find(">li.step").last().attr("data-last","true"),a.on("click",".step:not(.active)",function(){object=$(a.children(".step:visible")).index($(this)),a.hasClass("linear")?b.linearStepsNavigation&&(active=a.find(".step.active"),$(a.children(".step:visible")).index($(active))+1==object?a.nextStep(void 0,!0,void 0):$(a.children(".step:visible")).index($(active))-1==object&&a.prevStep(void 0)):a.openStep(object+1)}).on("click",".next-step",function(b){b.preventDefault(),a.nextStep(void 0,!0,b)}).on("click",".previous-step",function(b){b.preventDefault(),a.prevStep(void 0)}).on("click","button:submit:not(.next-step, .previous-step)",function(b){if(b.preventDefault(),feedback=b?$(b.target).data("feedback"):void 0,form=a.closest("form"),form.isValid()){if(feedback)return stepper.activateFeedback(),window[feedback].call();form.submit()}}).on("click",function(){$(".stepper.focused").removeClass("focused"),$(this).addClass("focused")})})};
|