This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstepper.min.js
1 lines (1 loc) · 16.5 KB
/
stepper.min.js
1
!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports){"use strict";!function(){function MaterialStepper(element){this.element_=element,this.init()}window.MaterialStepper=MaterialStepper,MaterialStepper.prototype.Stepper_={},MaterialStepper.prototype.getStepper_=function(){return{isLinear:this.element_.classList.contains(this.CssClasses_.STEPPER_LINEAR),hasFeedback:this.element_.classList.contains(this.CssClasses_.STEPPER_FEEDBACK)}},MaterialStepper.prototype.StepState_={COMPLETED:"completed",ERROR:"error",NORMAL:"normal"},MaterialStepper.prototype.DatasetAttributes_={CONTINUE:"stepper-next",CANCEL:"stepper-cancel",SKIP:"stepper-skip",BACK:"stepper-back"},MaterialStepper.prototype.defineCustomEvent=function(evtName,bubble,cancel){var ev;return"CustomEvent"in window&&"function"==typeof window.CustomEvent?ev=new Event(evtName,{bubbles:bubble,cancelable:cancel}):(ev=document.createEvent("Events"),ev.initEvent(evtName,bubble,cancel)),ev},MaterialStepper.prototype.CustomEvents_={onstepnext:MaterialStepper.prototype.defineCustomEvent("onstepnext",!0,!0),onstepcancel:MaterialStepper.prototype.defineCustomEvent("onstepcancel",!0,!0),onstepskip:MaterialStepper.prototype.defineCustomEvent("onstepskip",!0,!0),onstepback:MaterialStepper.prototype.defineCustomEvent("onstepback",!0,!0),onstepcomplete:MaterialStepper.prototype.defineCustomEvent("onstepcomplete",!0,!0),onsteperror:MaterialStepper.prototype.defineCustomEvent("onsteperror",!0,!0),onsteppercomplete:MaterialStepper.prototype.defineCustomEvent("onsteppercomplete",!0,!0)},MaterialStepper.prototype.CssClasses_={BUTTON_JS:"mdl-js-button",STEPPER_LINEAR:"mdl-stepper--linear",STEPPER_FEEDBACK:"mdl-stepper--feedback",STEP_COMPLETED:"mdl-step--completed",STEP_ERROR:"mdl-step--error",STEP_TRANSIENT:"mdl-step--transient",STEP_OPTIONAL:"mdl-step--optional",STEP_EDITABLE:"mdl-step--editable",IS_ACTIVE:"is-active",TRANSIENT:"mdl-step__transient",TRANSIENT_OVERLAY:"mdl-step__transient-overlay",TRANSIENT_LOADER:"mdl-step__transient-loader",SPINNER:"mdl-spinner",SPINNER_JS:"mdl-js-spinner",SPINNER_IS_ACTIVE:"is-active",STEPPER:"mdl-stepper",STEP:"mdl-step",STEP_LABEL:"mdl-step__label",STEP_LABEL_INDICATOR:"mdl-step__label-indicator",STEP_LABEL_INDICATOR_CONTENT:"mdl-step__label-indicator-content",STEP_TITLE:"mdl-step__title",STEP_TITLE_TEXT:"mdl-step__title-text",STEP_TITLE_MESSAGE:"mdl-step__title-message",STEP_CONTENT:"mdl-step__content",STEP_ACTIONS:"mdl-step__actions"},MaterialStepper.prototype.Steps_={},MaterialStepper.prototype.getIndicatorElement_=function(step){var indicatorElement,indicatorContent;return indicatorElement=document.createElement("span"),indicatorContent=this.getIndicatorContentNormal_(step.labelndicatorText),indicatorElement.classList.add(this.CssClasses_.STEP_LABEL_INDICATOR),indicatorElement.appendChild(indicatorContent),indicatorElement},MaterialStepper.prototype.getIndicatorContentNormal_=function(text){var normal;return normal=document.createElement("span"),normal.classList.add(this.CssClasses_.STEP_LABEL_INDICATOR_CONTENT),normal.textContent=text,normal},MaterialStepper.prototype.getIndicatorContentCompleted_=function(isEditable){var completed;return completed=document.createElement("i"),completed.classList.add("material-icons",this.CssClasses_.STEP_LABEL_INDICATOR_CONTENT),completed.textContent=isEditable?"edit":"check",completed},MaterialStepper.prototype.getIndicatorContentError_=function(){var error;return error=document.createElement("span"),error.classList.add(this.CssClasses_.STEP_LABEL_INDICATOR_CONTENT),error.textContent="!",error},MaterialStepper.prototype.getStepModel_=function(step,id){var model,selectorActionsBack,selectorActionsCancel,selectorActionsNext,selectorActionsSkip;return selectorActionsBack="[data-"+this.DatasetAttributes_.BACK+"]",selectorActionsCancel="[data-"+this.DatasetAttributes_.CANCEL+"]",selectorActionsNext="[data-"+this.DatasetAttributes_.CONTINUE+"]",selectorActionsSkip="[data-"+this.DatasetAttributes_.SKIP+"]",model={},model.container=step,model.id=id,model.label=step.querySelector("."+this.CssClasses_.STEP_LABEL),model.labelndicatorText=id,model.labelTitle=step.querySelector("."+this.CssClasses_.STEP_TITLE),model.labelTitleText=step.querySelector("."+this.CssClasses_.STEP_TITLE_TEXT).textContent,model.labelTitleMessage=step.querySelector("."+this.CssClasses_.STEP_TITLE_MESSAGE),model.labelTitleMessageText=model.labelTitleMessage?model.labelTitleMessage.textContent:"",model.content=step.querySelector("."+this.CssClasses_.STEP_CONTENT),model.actions=step.querySelector("."+this.CssClasses_.STEP_ACTIONS),model.actionsBack=model.actions.querySelector(selectorActionsBack)||null,model.actionsCancel=model.actions.querySelector(selectorActionsCancel)||null,model.actionsNext=model.actions.querySelector(selectorActionsNext)||null,model.actionsSkip=model.actions.querySelector(selectorActionsSkip)||null,model.labelIndicator=model.label.querySelector("."+this.CssClasses_.STEP_LABEL_INDICATOR),model.labelIndicator||(model.labelIndicator=this.getIndicatorElement_(model),model.label.appendChild(model.labelIndicator)),step.classList.contains(this.CssClasses_.STEP_COMPLETED)?model.state=this.StepState_.COMPLETED:step.classList.contains(this.CssClasses_.STEP_ERROR)?model.state=this.StepState_.ERROR:model.state=this.StepState_.NORMAL,model.isActive=step.classList.contains(this.CssClasses_.IS_ACTIVE),model.isOptional=step.classList.contains(this.CssClasses_.STEP_OPTIONAL),model.isEditable=step.classList.contains(this.CssClasses_.STEP_EDITABLE),model},MaterialStepper.prototype.getActive=function(){return this.Steps_.collection[this.Steps_.active-1].container},MaterialStepper.prototype.getActiveId=function(){return this.Steps_.collection[this.Steps_.active-1].id},MaterialStepper.prototype.getSteps_=function(){var collection,total,completed,optional,active,stepElements,i;for(collection=[],total=0,completed=0,optional=0,active=0,stepElements=this.element_.querySelectorAll("."+this.CssClasses_.STEP),i=0;i<stepElements.length;i++)collection[i]=this.getStepModel_(stepElements[i],i+1),collection[i].isOptional&&(optional+=1),collection[i].isActive&&(active=collection[i].id),stepElements[i].addEventListener("scroll",function(event){event.target.scrollTop=0});return total=collection.length,{collection:collection,total:total,completed:completed,optional:optional,active:active}},MaterialStepper.prototype.setStepActive_=function(step){var stepsDeactivator;return this.hasTransient()?!1:(stepsDeactivator=function(step){step.container.classList.remove(this.CssClasses_.IS_ACTIVE),step.isActive&&(step.isActive=!1)},this.Steps_.collection.forEach(stepsDeactivator.bind(this)),step.container.classList.remove(this.CssClasses_.STEP_TRANSIENT),step.container.classList.add(this.CssClasses_.IS_ACTIVE),step.isActive=!0,this.Steps_.active=step.id,!0)},MaterialStepper.prototype.setActive_=function(id){var active,first,i,moved,step;if(!isNaN(id)&&(id>this.Steps_.total||0>=id))return!1;if(moved=!1,id){for(i=0;i<this.Steps_.total;i++)if(step=this.Steps_.collection[i],step.id===id){moved=this.setStepActive_(step);break}}else active=this.element_.querySelector("."+this.CssClasses_.IS_ACTIVE),active||(first=this.Steps_.collection[0],moved=this.setStepActive_(first));return this.Stepper_.isLinear&&this.updateLinearStates_(),moved},MaterialStepper.prototype.updateStepState_=function(step,state){var stateClass,indicatorContent,currentIndicatorContent,stepperCompleted,hasRequired,stepItem,item,selectorIndicator;if(selectorIndicator="."+this.CssClasses_.STEP_LABEL_INDICATOR_CONTENT,step.state===state)return!1;switch(step.state===this.StepState_.COMPLETED&&(this.Steps_.completed-=1),currentIndicatorContent=step.labelIndicator.querySelector(selectorIndicator),state){case this.StepState_.COMPLETED:this.Steps_.completed+=1,step.container.classList.remove(this.CssClasses_.STEP_ERROR),indicatorContent=this.getIndicatorContentCompleted_(step.isEditable),stateClass=this.CssClasses_.STEP_COMPLETED;break;case this.StepState_.ERROR:step.container.classList.remove(this.CssClasses_.STEP_COMPLETED),indicatorContent=this.getIndicatorContentError_(),stateClass=this.CssClasses_.STEP_ERROR;break;case this.StepState_.NORMAL:step.container.classList.remove(this.CssClasses_.STEP_COMPLETED),step.container.classList.remove(this.CssClasses_.STEP_ERROR),indicatorContent=this.getIndicatorContentNormal_(step.labelndicatorText)}if(stateClass&&step.container.classList.add(stateClass),step.labelIndicator.replaceChild(indicatorContent,currentIndicatorContent),step.state=state,stepperCompleted=!1,this.Steps_.completed===this.Steps_.total)stepperCompleted=!0;else if(this.Steps_.completed===this.Steps_.total-this.Steps_.optional){for(item in this.Steps_.collection)if(this.Steps_.collection.hasOwnProperty(item)&&(stepItem=this.Steps_.collection[item],hasRequired=!stepItem.isOptional&&stepItem.state!==this.StepState_.COMPLETED))break;stepperCompleted=!hasRequired}return stepperCompleted&&this.dispatchEventOnStepperComplete_(),!0},MaterialStepper.prototype.updateLinearStates_=function(){var i;for(i=0;i<this.Steps_.total&&!this.Steps_.collection[i].isActive;i++)this.Steps_.collection[i].isOptional||this.updateStepState_(this.Steps_.collection[i],this.StepState_.COMPLETED)},MaterialStepper.prototype.back=function(){var moved,moveStep,model,step,previous;moved=!1,moveStep=function(step){var stepActivated;return stepActivated=this.setActive_(step.id),stepActivated&&stepActivated&&this.Stepper_.hasFeedback&&this.removeTransientEffect_(step),stepActivated};for(model in this.Steps_.collection)if(this.Steps_.collection.hasOwnProperty(model)&&(step=this.Steps_.collection[model],step.isActive)){if(previous=this.Steps_.collection[step.id-2],!previous)return!1;this.Stepper_.isLinear?previous.isEditable&&(moved=moveStep.bind(this)(previous)):moved=moveStep.bind(this)(previous);break}return moved},MaterialStepper.prototype.skip=function(){var moved,model,step;moved=!1;for(model in this.Steps_.collection)if(this.Steps_.collection.hasOwnProperty(model)&&(step=this.Steps_.collection[model],step.isActive)){step.isOptional&&(moved=this.setActive_(step.id+1),moved&&this.Stepper_.hasFeedback&&this.removeTransientEffect_(step));break}return moved},MaterialStepper.prototype["goto"]=function(id){return this.setActive_(id)},MaterialStepper.prototype.error=function(message){var model,step;for(model in this.Steps_.collection)if(this.Steps_.collection.hasOwnProperty(model)&&(step=this.Steps_.collection[model],step.isActive)){this.Stepper_.hasFeedback&&this.removeTransientEffect_(step),this.updateStepState_(step,this.StepState_.ERROR),message&&this.updateTitleMessage_(step,message),this.dispatchEventOnStepError_(step);break}},MaterialStepper.prototype.next=function(){var moved,step,activate,model,item,stepItem;moved=!1;for(model in this.Steps_.collection)if(this.Steps_.collection.hasOwnProperty(model)&&(step=this.Steps_.collection[model],step.isActive)){if(activate=step.id+1,this.Stepper_.hasFeedback&&this.removeTransientEffect_(step),step.state===this.StepState_.ERROR&&(step.labelTitleMessageText?this.updateTitleMessage_(step,step.labelTitleMessageText):this.removeTitleMessage_(step)),step.isEditable&&this.Stepper_.isLinear)for(item in this.Steps_.collection)if(this.Steps_.collection.hasOwnProperty(item)&&(stepItem=this.Steps_.collection[item],stepItem.id>step.id&&stepItem.state!==this.StepState_.COMPLETED)){activate=stepItem.id;break}moved=this.setActive_(activate),this.Stepper_.isLinear?(step.isOptional||step.id===this.Steps_.total)&&this.updateStepState_(step,this.StepState_.COMPLETED):this.updateStepState_(step,this.StepState_.COMPLETED),this.dispatchEventOnStepComplete_(step);break}return moved},MaterialStepper.prototype.updateTitleMessage_=function(step,text){var titleMessage;titleMessage=step.container.querySelector("."+this.CssClasses_.STEP_TITLE_MESSAGE),titleMessage||(titleMessage=document.createElement("span"),titleMessage.classList.add(this.CssClasses_.STEP_TITLE_MESSAGE),step.labelTitle.appendChild(titleMessage)),titleMessage.textContent=text},MaterialStepper.prototype.removeTitleMessage_=function(step){var titleMessage;titleMessage=step.container.querySelector("."+this.CssClasses_.STEP_TITLE_MESSAGE),titleMessage&&titleMessage.parentNode.removeChild(titleMessage)},MaterialStepper.prototype.removeTransientEffect_=function(step){var transient;return(transient=step.content.querySelector("."+this.CssClasses_.TRANSIENT))?(step.container.classList.remove(this.CssClasses_.STEP_TRANSIENT),step.content.removeChild(transient),!0):!1},MaterialStepper.prototype.addTransientEffect_=function(step){var transient,overlay,loader,spinner;return step.content.querySelector("."+this.CssClasses_.TRANSIENT)?!1:(transient=document.createElement("div"),overlay=document.createElement("div"),loader=document.createElement("div"),spinner=document.createElement("div"),transient.classList.add(this.CssClasses_.TRANSIENT),overlay.classList.add(this.CssClasses_.TRANSIENT_OVERLAY),loader.classList.add(this.CssClasses_.TRANSIENT_LOADER),spinner.classList.add(this.CssClasses_.SPINNER),spinner.classList.add(this.CssClasses_.SPINNER_JS),spinner.classList.add(this.CssClasses_.SPINNER_IS_ACTIVE),loader.appendChild(spinner),transient.appendChild(overlay),transient.appendChild(loader),step.container.classList.add(this.CssClasses_.STEP_TRANSIENT),step.content.appendChild(transient),componentHandler.upgradeDom(),!0)},MaterialStepper.prototype.setCustomEvents_=function(){var linearLabels,nonLinearLabels,dispatchCustomEvents;linearLabels=function(step){step.isEditable&&step.label.addEventListener("click",function(event){event.preventDefault(),step.state===this.StepState_.COMPLETED&&this.setStepActive_(step)}.bind(this))},nonLinearLabels=function(step){step.label.addEventListener("click",function(event){event.preventDefault(),this.setStepActive_(step)}.bind(this))},dispatchCustomEvents=function(step){this.dispatchEventOnStepNext_(step),this.dispatchEventOnStepCancel_(step),this.dispatchEventOnStepSkip_(step),this.dispatchEventOnStepBack_(step)},this.Stepper_.isLinear?this.Steps_.collection.forEach(linearLabels.bind(this)):this.Steps_.collection.forEach(nonLinearLabels.bind(this)),this.Steps_.collection.forEach(dispatchCustomEvents.bind(this))},MaterialStepper.prototype.dispatchEventOnStepComplete_=function(step){step.container.dispatchEvent(this.CustomEvents_.onstepcomplete)},MaterialStepper.prototype.dispatchEventOnStepError_=function(step){step.container.dispatchEvent(this.CustomEvents_.onsteperror)},MaterialStepper.prototype.dispatchEventOnStepperComplete_=function(){this.element_.dispatchEvent(this.CustomEvents_.onsteppercomplete)},MaterialStepper.prototype.dispatchEventOnStepNext_=function(step){return step.actionsNext?(step.actionsNext.addEventListener("click",function(){this.Stepper_.hasFeedback&&this.addTransientEffect_(step),step.container.dispatchEvent(this.CustomEvents_.onstepnext)}.bind(this)),!0):!1},MaterialStepper.prototype.dispatchEventOnStepCancel_=function(step){return step.actionsCancel?(step.actionsCancel.addEventListener("click",function(event){event.preventDefault(),step.container.dispatchEvent(this.CustomEvents_.onstepcancel)}.bind(this)),!0):!1},MaterialStepper.prototype.dispatchEventOnStepSkip_=function(step){return step.actionsSkip?(step.actionsSkip.addEventListener("click",function(event){event.preventDefault(),step.container.dispatchEvent(this.CustomEvents_.onstepskip)}.bind(this)),!0):!1},MaterialStepper.prototype.dispatchEventOnStepBack_=function(step){return step.actionsBack?(step.actionsBack.addEventListener("click",function(event){event.preventDefault(),step.container.dispatchEvent(this.CustomEvents_.onstepback)}.bind(this)),!0):!1},MaterialStepper.prototype.hasTransient=function(){var cssClasseStep,cssClasseStepContent,cssClasseTransient,selectorTransient,transient;return cssClasseStep="."+this.CssClasses_.STEP,cssClasseStepContent="."+this.CssClasses_.STEP_CONTENT,cssClasseTransient="."+this.CssClasses_.TRANSIENT,selectorTransient=cssClasseStep+" > "+cssClasseStepContent+" > "+cssClasseTransient,transient=this.element_.querySelector(selectorTransient),null!==transient},MaterialStepper.prototype.init=function(){this.element_&&(this.Stepper_=this.getStepper_(),this.Steps_=this.getSteps_(),this.setActive_(),this.setCustomEvents_())},componentHandler.register({constructor:MaterialStepper,classAsString:"MaterialStepper",cssClass:"mdl-stepper",widget:!0})}()}]);