mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-17 08:46:19 +10:00
7 lines
3.4 KiB
JavaScript
7 lines
3.4 KiB
JavaScript
/**
|
|
* Easy to use Wizard library for AngularJS
|
|
* @version v0.3.0 - 2014-02-24 * @link https://github.com/mgonto/angular-wizard
|
|
* @author Martin Gontovnikas <martin@gon.to>
|
|
* @license MIT License, http://www.opensource.org/licenses/MIT
|
|
*/
|
|
function wizardButtonDirective(a){angular.module("mgo-angular-wizard").directive(a,function(){return{restrict:"A",replace:!1,require:"^wizard",link:function(b,c,d,e){c.on("click",function(c){c.preventDefault(),b.$apply(function(){b.$eval(d[a]),e[a.replace("wz","").toLowerCase()]()})})}}})}angular.module("templates-angularwizard",["step.html","wizard.html"]),angular.module("step.html",[]).run(["$templateCache",function(a){a.put("step.html",'<section ng-show="selected" ng-class="{current: selected, done: completed}" class="step" ng-transclude>\n</section>')}]),angular.module("wizard.html",[]).run(["$templateCache",function(a){a.put("wizard.html",'<div>\n <div class="steps" ng-transclude></div>\n <ul class="steps-indicator steps-{{steps.length}}" ng-if="!hideIndicators">\n <li ng-class="{default: !step.completed && !step.selected, current: step.selected && !step.completed, done: step.completed && !step.selected, editing: step.selected && step.completed}" ng-repeat="step in steps">\n <a ng-click="goTo(step)">{{step.title}}</a>\n </li>\n </ul>\n</div>')}]),angular.module("mgo-angular-wizard",["templates-angularwizard"]),angular.module("mgo-angular-wizard").directive("wzStep",function(){return{restrict:"EA",replace:!0,transclude:!0,scope:{title:"@"},require:"^wizard",templateUrl:"step.html",link:function(a,b,c,d){d.addStep(a)}}}),angular.module("mgo-angular-wizard").directive("wizard",function(){return{restrict:"EA",replace:!0,transclude:!0,scope:{currentStep:"=",onFinish:"&",hideIndicators:"=",editMode:"=",name:"@"},templateUrl:"wizard.html",controller:["$scope","$element","WizardHandler",function(a,b,c){function d(){_.each(a.steps,function(a){a.selected=!1}),a.selectedStep=null}c.addWizard(a.name||c.defaultName,this),a.$on("$destroy",function(){c.removeWizard(a.name||c.defaultName)}),a.steps=[],a.$watch("currentStep",function(b){b&&a.selectedStep&&a.selectedStep.title!==a.currentStep&&a.goTo(_.find(a.steps,{title:a.currentStep}))}),a.$watch("[editMode, steps.length]",function(){var b=a.editMode;_.isUndefined(b)||_.isNull(b)||b&&_.each(a.steps,function(a){a.completed=!0})},!0),this.addStep=function(b){a.steps.push(b),1===a.steps.length&&a.goTo(a.steps[0])},a.goTo=function(b){d(),a.selectedStep=b,_.isUndefined(a.currentStep)||(a.currentStep=b.title),b.selected=!0},this.next=function(b){var c=_.indexOf(a.steps,a.selectedStep);b||(a.selectedStep.completed=!0),c===a.steps.length-1?this.finish():a.goTo(a.steps[c+1])},this.goTo=function(b){var c;c=_.isNumber(b)?a.steps[b]:_.find(a.steps,{title:b}),a.goTo(c)},this.finish=function(){a.onFinish&&a.onFinish()},this.cancel=this.previous=function(){var b=_.indexOf(a.steps,a.selectedStep);if(0===b)throw new Error("Can't go back. It's already in step 0");a.goTo(a.steps[b-1])}}]}}),wizardButtonDirective("wzNext"),wizardButtonDirective("wzPrevious"),wizardButtonDirective("wzFinish"),wizardButtonDirective("wzCancel"),angular.module("mgo-angular-wizard").factory("WizardHandler",function(){var a={},b={};return a.defaultName="defaultWizard",a.addWizard=function(a,c){b[a]=c},a.removeWizard=function(a){delete b[a]},a.wizard=function(c){var d=c;return c||(d=a.defaultName),b[d]},a}); |