Skip to content

Commit 9eef5ce

Browse files
committed
Cleaned up project structure into src and dist folders (update your includes).
1 parent ff284bb commit 9eef5ce

File tree

11 files changed

+240
-16
lines changed

11 files changed

+240
-16
lines changed

bower.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-steps",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"main": "angular-steps.js",
55
"description": "Split your UI into (wizard-like) steps in AngularJS.",
66
"dependencies": {
@@ -10,9 +10,9 @@
1010
".gitignore",
1111
"bower.json",
1212
"package.json",
13+
"gulpfile.js",
1314
"README.md",
1415
"license.md",
15-
"demo.html",
16-
"gulpfile.js"
16+
"demo/*.*"
1717
]
1818
}
File renamed without changes.
File renamed without changes.

gulpfile.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,37 @@ var rename = require('gulp-rename');
55
var uglify = require('gulp-uglify');
66

77
gulp.task('copy', function () {
8-
gulp.src('angular-steps.less')
9-
.pipe(rename("_angular-steps.scss"))
10-
.pipe(gulp.dest('.'));
8+
gulp.src('src/*.*')
9+
.pipe(gulp.dest('dist'));
10+
});
11+
12+
gulp.task('scss', function () {
13+
return gulp.src('src/*.less')
14+
.pipe(rename({
15+
prefix: '_',
16+
extname: '.scss'
17+
}))
18+
.pipe(gulp.dest('dist'));
1119
});
1220

1321
gulp.task('less', function () {
14-
gulp.src('*.less')
22+
return gulp.src('src/*.less')
1523
.pipe(less())
16-
.pipe(gulp.dest('.'));
24+
.pipe(gulp.dest('dist'));
1725
});
1826

19-
gulp.task('css', function () {
20-
gulp.src('angular-steps.css')
27+
gulp.task('css', ['less'], function () {
28+
return gulp.src('dist/*.css')
2129
.pipe(minifyCSS())
2230
.pipe(rename({suffix: '.min'}))
23-
.pipe(gulp.dest('.'));
31+
.pipe(gulp.dest('dist'));
2432
});
2533

2634
gulp.task('compress', function() {
27-
gulp.src('angular-steps.js')
35+
return gulp.src('src/*.js')
2836
.pipe(uglify())
2937
.pipe(rename({suffix: '.min'}))
30-
.pipe(gulp.dest('.'))
38+
.pipe(gulp.dest('dist'))
3139
});
3240

33-
gulp.task('default', ['less'], function () {
34-
gulp.start('css', 'copy', 'compress');
35-
});
41+
gulp.task('default', ['scss', 'less', 'css', 'copy', 'compress']);

src/angular-steps.js

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/**
2+
* angular-steps
3+
* @version v0.1.0 - 2014-07-10
4+
* @link https://github.com/omichelsen/angular-steps
5+
* @author Ole Michelsen <[email protected]>
6+
* @license MIT License, http://www.opensource.org/licenses/MIT
7+
*/
8+
(function () {
9+
10+
angular.module('templates-angular-steps', ['step.html', 'steps.html']);
11+
12+
angular.module('step.html', []).run(['$templateCache',
13+
function($templateCache) {
14+
$templateCache.put('step.html', '<div ng-show=\"selected\" class=\"step ng-hide\" ng-transclude></div>');
15+
}
16+
]);
17+
18+
angular.module('steps.html', []).run(['$templateCache',
19+
function($templateCache) {
20+
$templateCache.put('steps.html',
21+
'<div class=\"angular-steps\">\n' +
22+
' <div class=\"steps\" ng-transclude></div>\n' +
23+
'</div>');
24+
}
25+
]);
26+
27+
angular.module('angular-steps', ['templates-angular-steps']);
28+
29+
angular.module('angular-steps').directive('step', function() {
30+
return {
31+
restrict: 'EA',
32+
replace: true,
33+
transclude: true,
34+
scope: {
35+
name: '@'
36+
},
37+
require: '^steps',
38+
templateUrl: function(element, attributes) {
39+
return attributes.template || 'step.html';
40+
},
41+
link: function($scope, $element, $attrs, steps) {
42+
steps.addStep($scope);
43+
}
44+
};
45+
});
46+
47+
angular.module('angular-steps').directive('steps', function() {
48+
return {
49+
restrict: 'EA',
50+
replace: true,
51+
transclude: true,
52+
scope: {
53+
currentStep: '=',
54+
onFinish: '&',
55+
name: '@'
56+
},
57+
templateUrl: function(element, attributes) {
58+
return attributes.template || 'steps.html';
59+
},
60+
controller: ['$scope', '$element', 'StepsService',
61+
function($scope, $element, StepsService) {
62+
63+
StepsService.addSteps($scope.name || StepsService.defaultName, this);
64+
$scope.$on('$destroy', function() {
65+
StepsService.removeSteps($scope.name || StepsService.defaultName);
66+
});
67+
68+
$scope.steps = [];
69+
70+
$scope.$watch('currentStep', function(step) {
71+
if (!step) return;
72+
var stepName = $scope.selectedStep.name;
73+
if ($scope.selectedStep && stepName !== $scope.currentStep) {
74+
var found = $scope.steps.filter(function (elm) {
75+
return elm.name === $scope.currentStep;
76+
})[0];
77+
$scope.goTo(found);
78+
}
79+
});
80+
81+
this.addStep = function(step) {
82+
$scope.steps.push(step);
83+
if ($scope.steps.length === 1) {
84+
$scope.goTo($scope.steps[0]);
85+
}
86+
};
87+
88+
$scope.goTo = function(step) {
89+
unselectAll();
90+
$scope.selectedStep = step;
91+
if ($scope.currentStep !== void 0) {
92+
$scope.currentStep = step.name;
93+
}
94+
step.selected = true;
95+
};
96+
97+
function unselectAll() {
98+
$scope.steps.forEach(function(step) {
99+
step.selected = false;
100+
});
101+
$scope.selectedStep = null;
102+
}
103+
104+
this.next = function() {
105+
var index = $scope.steps.indexOf($scope.selectedStep);
106+
if (index === $scope.steps.length - 1) {
107+
this.finish();
108+
} else {
109+
$scope.goTo($scope.steps[index + 1]);
110+
}
111+
};
112+
113+
this.goTo = function(step) {
114+
var stepTo;
115+
if (isNaN(step)) {
116+
stepTo = $scope.steps.filter(function (elm) {
117+
return elm.name === step;
118+
})[0];
119+
} else {
120+
stepTo = $scope.steps[step];
121+
}
122+
$scope.goTo(stepTo);
123+
};
124+
125+
this.finish = function() {
126+
if ($scope.onFinish) {
127+
$scope.onFinish();
128+
}
129+
};
130+
131+
this.cancel = this.previous = function() {
132+
var index = $scope.steps.indexOf($scope.selectedStep);
133+
if (index === 0) {
134+
throw new Error('Already at step 0');
135+
} else {
136+
$scope.goTo($scope.steps[index - 1]);
137+
}
138+
};
139+
}
140+
]
141+
};
142+
});
143+
144+
function stepsButtonDirective(action) {
145+
angular.module('angular-steps')
146+
.directive(action, function() {
147+
return {
148+
restrict: 'A',
149+
replace: false,
150+
require: '^steps',
151+
link: function($scope, $element, $attrs, steps) {
152+
$element.on('click', function(e) {
153+
e.preventDefault();
154+
$scope.$apply(function() {
155+
$scope.$eval($attrs[action]);
156+
steps[action.replace('step', '').toLowerCase()]();
157+
});
158+
});
159+
}
160+
};
161+
});
162+
}
163+
164+
stepsButtonDirective('stepNext');
165+
stepsButtonDirective('stepPrevious');
166+
stepsButtonDirective('stepFinish');
167+
stepsButtonDirective('stepCancel');
168+
169+
angular.module('angular-steps').factory('StepsService', function() {
170+
var service = {};
171+
172+
var instances = {};
173+
174+
service.defaultName = 'default';
175+
176+
service.addSteps = function(name, steps) {
177+
instances[name] = steps;
178+
};
179+
180+
service.removeSteps = function(name) {
181+
delete instances[name];
182+
};
183+
184+
service.steps = function(name) {
185+
return instances[name || service.defaultName];
186+
};
187+
188+
return service;
189+
});
190+
191+
})();

0 commit comments

Comments
 (0)