Skip to content

Commit c9d798a

Browse files
author
Rafael J. Staib
committed
Add improvements to the build process and decoupled calls from the private to the public methods
1 parent 336fea8 commit c9d798a

File tree

9 files changed

+154
-56
lines changed

9 files changed

+154
-56
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dist
2-
build/dist
2+
build
33
docs
44
downloads
55
*~

Gruntfile.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ module.exports = function (grunt)
88
concat: {
99
dist: {
1010
files: {
11-
'dist/jquery.steps.js': [
12-
'src/banner.js',
13-
'src/variables.js',
14-
'src/privates.js',
15-
'src/publics.js',
16-
'src/enums.js',
17-
'src/model.js',
18-
'src/defaults.js',
19-
'src/globals.js',
20-
'src/footer.js'
11+
'<%= pkg.folders.dist %>/jquery.steps.js': [
12+
'<%= pkg.folders.src %>/banner.js',
13+
'<%= pkg.folders.src %>/variables.js',
14+
'<%= pkg.folders.src %>/privates.js',
15+
'<%= pkg.folders.src %>/publics.js',
16+
'<%= pkg.folders.src %>/objects.js',
17+
'<%= pkg.folders.src %>/defaults.js',
18+
'<%= pkg.folders.src %>/helper.js',
19+
'<%= pkg.folders.src %>/footer.js'
2120
]
2221
}
2322
}
@@ -31,30 +30,30 @@ module.exports = function (grunt)
3130
},
3231
all: {
3332
files: {
34-
'dist/jquery.steps.min.js': ['dist/jquery.steps.js']
33+
'<%= pkg.folders.dist %>/jquery.steps.min.js': ['<%= pkg.folders.dist %>/jquery.steps.js']
3534
}
3635
}
3736
},
3837
compress: {
3938
main: {
4039
options: {
41-
archive: 'dist/<%= pkg.name %>-<%= pkg.version %>.zip'
40+
archive: '<%= pkg.folders.dist %>/<%= pkg.name %>-<%= pkg.version %>.zip'
4241
},
4342
files: [
4443
{
4544
src: [
4645
'README.md',
4746
/*'changelog.txt',*/
48-
'src/**/*.*',
49-
'docs/**/*.*',
47+
'<%= pkg.folders.src %>/**/*.*',
48+
'<%= pkg.folders.docs %>/**/*.*',
5049
'demo/**/*.*',
5150
'lib/*.*',
5251
'test/**/*.*'
5352
]
5453
},
5554
{
5655
flatten: true,
57-
src: ['dist/*.js'],
56+
src: ['<%= pkg.folders.dist %>/*.js'],
5857
filter: 'isFile'
5958
}
6059
]
@@ -82,7 +81,7 @@ module.exports = function (grunt)
8281
}
8382
},
8483
files: [
85-
'dist/jquery-steps.js'
84+
'<%= pkg.folders.dist %>/jquery-steps.js'
8685
],
8786
test: {
8887
options: {
@@ -124,11 +123,14 @@ module.exports = function (grunt)
124123
options: {
125124
exclude: 'qunit-1.11.0.js',
126125
paths: '.',
127-
outdir: 'docs/'
126+
outdir: '<%= pkg.folders.docs %>/'
128127
}
129128
}
130129
},
131-
clean: ["dist", "docs"]
130+
clean: {
131+
api: ["<%= pkg.folders.docs %>"],
132+
build: ["<%= pkg.folders.dist %>"]
133+
}
132134
});
133135

134136
grunt.loadNpmTasks('grunt-contrib-jshint');
@@ -139,7 +141,8 @@ module.exports = function (grunt)
139141
grunt.loadNpmTasks('grunt-contrib-compress');
140142
grunt.loadNpmTasks('grunt-contrib-clean');
141143

142-
grunt.registerTask('default', ['concat', 'jshint', 'qunit']);
143-
grunt.registerTask('api', ['clean', 'yuidoc']);
144-
grunt.registerTask('release', ['default', 'api', 'uglify', 'compress']);
144+
grunt.registerTask('default', ['build']);
145+
grunt.registerTask('api', ['clean:api', 'yuidoc']);
146+
grunt.registerTask('build', ['clean:build', 'concat', 'jshint', 'qunit']);
147+
grunt.registerTask('release', ['build', 'api', 'uglify', 'compress']);
145148
};

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@
3939
"grunt-cli": "~0.1.9"
4040
},
4141
"readmeFilename": "README.md",
42-
"gitHead": "0d9f4f8b6a0c3d3b8a73eabf6a4b8cececd52f7a"
42+
"gitHead": "0d9f4f8b6a0c3d3b8a73eabf6a4b8cececd52f7a",
43+
"folders": {
44+
"dist": "build",
45+
"src": "src",
46+
"docs": "docs"
47+
}
4348
}
File renamed without changes.

src/model.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/enums.js renamed to src/objects.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Enums
3+
*/
4+
5+
6+
17
/**
28
* An enum represents the different content types of a step and their loading mechanisms.
39
*
@@ -82,4 +88,39 @@ $.fn.steps.transitionEffect = {
8288
* @for transitionEffect
8389
**/
8490
slideLeft: 3
91+
};
92+
93+
94+
95+
/*
96+
* Model
97+
*/
98+
99+
100+
101+
$.fn.steps.stepModel = {
102+
title: "",
103+
content: "",
104+
contentUrl: "",
105+
contentMode: $.fn.steps.contentMode.html,
106+
contentLoaded: false
107+
};
108+
109+
110+
111+
/*
112+
* Model
113+
*/
114+
115+
116+
117+
$.fn.steps.currentIndex = {
118+
decrease: function (state, decreaseBy)
119+
{
120+
return state.currentIndex - decreaseBy;
121+
},
122+
increase: function (state, increaseBy)
123+
{
124+
return state.currentIndex + increaseBy;
125+
}
85126
};

src/privates.js

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,30 @@ var privates = {
6868
});
6969
},
7070

71+
/**
72+
* Triggers the onFinishing and onFinished event.
73+
*
74+
* @static
75+
* @private
76+
* @method finishStep
77+
* @param wizard {Object} The jQuery wizard object
78+
* @param state {Object} The state container of the current wizard
79+
**/
80+
finishStep: function (wizard, state)
81+
{
82+
var currentStep = wizard.find(".steps li").eq(state.currentIndex);
83+
84+
if (wizard.triggerHandler("finishing", [state.currentIndex]))
85+
{
86+
currentStep.addClass("done").removeClass("error");
87+
wizard.triggerHandler("finished", [state.currentIndex]);
88+
}
89+
else
90+
{
91+
currentStep.addClass("error");
92+
}
93+
},
94+
7195
generateMenuItem: function (tag, label)
7296
{
7397
return "<li><a href=\"#" + tag + "\" role=\"menuitem\">" + label + "</a></li>";
@@ -161,6 +185,38 @@ var privates = {
161185
}
162186
},
163187

188+
/**
189+
* Routes to the next step.
190+
*
191+
* @static
192+
* @private
193+
* @method goToNextStep
194+
* @param wizard {Object} The jQuery wizard object
195+
* @param options {Object} Settings of the current wizard
196+
* @param state {Object} The state container of the current wizard
197+
* @return {Boolean} Indicates whether the action executed
198+
**/
199+
goToNextStep: function (wizard, options, state)
200+
{
201+
return privates.paginationClick(wizard, options, state, $.fn.steps.currentIndex.increase(state, 1));
202+
},
203+
204+
/**
205+
* Routes to the previous step.
206+
*
207+
* @static
208+
* @private
209+
* @method goToPreviousStep
210+
* @param wizard {Object} The jQuery wizard object
211+
* @param options {Object} Settings of the current wizard
212+
* @param state {Object} The state container of the current wizard
213+
* @return {Boolean} Indicates whether the action executed
214+
**/
215+
goToPreviousStep: function (wizard, options, state)
216+
{
217+
return privates.paginationClick(wizard, options, state, $.fn.steps.currentIndex.decrease(state, 1));
218+
},
219+
164220
/**
165221
* Routes to a specific step by a given index.
166222
*
@@ -393,9 +449,11 @@ var privates = {
393449
*/
394450
keyUpHandler: function (event)
395451
{
396-
var wizard = $(this);
452+
var wizard = $(this),
453+
options = wizard.data("options"),
454+
state = wizard.data("state");
397455

398-
if (wizard.data("options").suppressPaginationOnFocus && wizard.find(":focus").is(":input"))
456+
if (options.suppressPaginationOnFocus && wizard.find(":focus").is(":input"))
399457
{
400458
event.preventDefault();
401459
return false;
@@ -405,12 +463,12 @@ var privates = {
405463
if (event.keyCode === keyCodes.left)
406464
{
407465
event.preventDefault();
408-
wizard.steps("previous");
466+
privates.goToPreviousStep(wizard, options, state);
409467
}
410468
else if (event.keyCode === keyCodes.right)
411469
{
412470
event.preventDefault();
413-
wizard.steps("next");
471+
privates.goToNextStep(wizard, options, state);
414472
}
415473
},
416474

@@ -458,14 +516,14 @@ var privates = {
458516
* @private
459517
* @method paginationClick
460518
* @param wizard {Object} The jQuery wizard object
519+
* @param options {Object} Settings of the current wizard
520+
* @param state {Object} The state container of the current wizard
461521
* @param index {Integer} The position (zero-based) to route to
462522
* @return {Boolean} Indicates whether the event fired successfully or not
463523
**/
464-
paginationClick: function (wizard, index)
524+
paginationClick: function (wizard, options, state, index)
465525
{
466-
var options = wizard.data("options"),
467-
state = wizard.data("state"),
468-
oldIndex = state.currentIndex;
526+
var oldIndex = state.currentIndex;
469527

470528
if (index >= 0 && index < state.stepCount && !(options.forceMoveForward && index < state.currentIndex))
471529
{
@@ -504,20 +562,22 @@ var privates = {
504562

505563
var anchor = $(this),
506564
wizard = anchor.parents(":has(.steps)"),
565+
options = wizard.data("options"),
566+
state = wizard.data("state"),
507567
href = anchor.attr("href");
508568

509569
switch (href.substring(href.lastIndexOf("#")))
510570
{
511571
case "#finish":
512-
wizard.steps("finish");
572+
privates.finishStep(wizard, options, state);
513573
break;
514574

515575
case "#next":
516-
wizard.steps("next");
576+
privates.goToNextStep(wizard, options, state);
517577
break;
518578

519579
case "#previous":
520-
wizard.steps("previous");
580+
privates.goToPreviousStep(wizard, options, state)
521581
break;
522582
}
523583
},

src/publics.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,9 @@ $.fn.steps.add = function (step)
4545
**/
4646
$.fn.steps.finish = function ()
4747
{
48-
var options = this.data("options"),
49-
state = this.data("state"),
50-
currentStep = this.find(".steps li").eq(state.currentIndex);
48+
var state = this.data("state");
5149

52-
if (this.triggerHandler("finishing", [state.currentIndex]))
53-
{
54-
currentStep.addClass("done").removeClass("error");
55-
this.triggerHandler("finished", [state.currentIndex]);
56-
}
57-
else
58-
{
59-
currentStep.addClass("error");
60-
}
50+
privates.finishStep(this, state);
6151
};
6252

6353
/**
@@ -126,7 +116,10 @@ $.fn.steps.insert = function (index, step)
126116
**/
127117
$.fn.steps.next = function ()
128118
{
129-
return privates.paginationClick(this, this.data("state").currentIndex + 1);
119+
var options = this.data("options"),
120+
state = this.data("state");
121+
122+
return privates.goToNextStep(this, options, state);
130123
};
131124

132125
/**
@@ -137,7 +130,10 @@ $.fn.steps.next = function ()
137130
**/
138131
$.fn.steps.previous = function ()
139132
{
140-
return privates.paginationClick(this, this.data("state").currentIndex - 1);
133+
var options = this.data("options"),
134+
state = this.data("state");
135+
136+
return privates.goToPreviousStep(this, options, state);
141137
};
142138

143139
/**

test/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ <h1>contentModeWithStringArgument</h1>
5858
<script src="qunit/qunit-1.11.0.js"></script>
5959
<script src="tests.js"></script>
6060
<script src="jquery.js"></script>
61-
<script src="../dist/jquery.steps.js"></script>
61+
<script src="../build/jquery.steps.js"></script>
6262
<script>
6363
$(function ()
6464
{

0 commit comments

Comments
 (0)