Skip to content

Commit afb7d7d

Browse files
committed
added grunt to unify generating dist files (and eventually js linting)
added updated dist files from previous merged commit
1 parent 16eace2 commit afb7d7d

6 files changed

Lines changed: 191 additions & 60 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.project
1+
.project
2+
node_modules
3+
bower_components

Gruntfile.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*global module:false*/
2+
module.exports = function (grunt) {
3+
4+
// Project configuration.
5+
grunt.initConfig({
6+
// Metadata.
7+
pkg: grunt.file.readJSON('package.json'),
8+
banner: '/*! jquery.typer.js <%= pkg.version %>- <%= grunt.template.today("yyyy-mm-dd") %> */\n',
9+
// Task configuration.
10+
concat: {
11+
options: {
12+
banner: '<%= banner %>',
13+
stripBanners: true
14+
},
15+
dist: {
16+
src: ['src/jquery.typer.js'],
17+
dest: 'dist/jquery.typer.js'
18+
}
19+
},
20+
uglify: {
21+
options: {
22+
banner: '<%= banner %>'
23+
},
24+
dist: {
25+
src: '<%= concat.dist.dest %>',
26+
dest: 'dist/jquery.typer.min.js'
27+
}
28+
},
29+
copy: {
30+
dist: {
31+
src:'src/jquery.typer.js',
32+
dest: 'dist/jquery.typer.js'
33+
}
34+
},
35+
jshint: {
36+
options: {
37+
curly: true,
38+
eqeqeq: true,
39+
immed: true,
40+
latedef: true,
41+
newcap: true,
42+
noarg: true,
43+
sub: true,
44+
undef: true,
45+
unused: true,
46+
boss: true,
47+
eqnull: true,
48+
browser: true,
49+
globals: {
50+
jQuery: true
51+
}
52+
},
53+
gruntfile: {
54+
src: 'Gruntfile.js'
55+
},
56+
dist: {
57+
options: {
58+
curly: true,
59+
eqeqeq: true,
60+
immed: true,
61+
latedef: true,
62+
newcap: true,
63+
noarg: true,
64+
sub: true,
65+
undef: true,
66+
unused: true,
67+
boss: true,
68+
eqnull: true,
69+
browser: true,
70+
globals: {
71+
jQuery: true
72+
}
73+
},
74+
src: 'src/jquery.typer.js'
75+
}
76+
},
77+
watch: {
78+
gruntfile: {
79+
files: '<%= jshint.gruntfile.src %>',
80+
tasks: ['jshint:gruntfile']
81+
}
82+
}
83+
});
84+
85+
// These plugins provide necessary tasks.
86+
grunt.loadNpmTasks('grunt-contrib-concat');
87+
grunt.loadNpmTasks('grunt-contrib-uglify');
88+
grunt.loadNpmTasks('grunt-contrib-jshint');
89+
grunt.loadNpmTasks('grunt-contrib-watch');
90+
grunt.loadNpmTasks('grunt-contrib-copy');
91+
92+
// Default task.
93+
grunt.registerTask('dist', [/*'jshint:dist', */'concat:dist', 'uglify:dist', 'copy:dist']);
94+
95+
};

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Set the options individually:
4747
```javascript
4848
$.typer.options.highlightSpeed = 500;
4949
```
50+
51+
## Contributing
52+
53+
Make your changes on `src/jquery.typer.js`. To generate updated minified distribution versions run `$ grunt dist`.
54+
5055
## About
5156

5257
jquery.typer.js was originally developed for [LayerVault](http://layervault.com) by [Kelly Sutton](http://kellysutton.com).

dist/jquery.typer.js

Lines changed: 52 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,21 @@ String.prototype.rightChars = function(n){
1111
};
1212

1313
(function($) {
14-
var
15-
options = {
16-
highlightSpeed : 20,
17-
typeSpeed : 100,
18-
clearDelay : 500,
19-
typeDelay : 200,
20-
clearOnHighlight : true,
21-
highlightEverything: true,
22-
typerDataAttr : 'data-typer-targets',
23-
typerInterval : 2000,
24-
debug : false,
25-
tapeColor : 'auto',
26-
typerOrder : 'random',
27-
},
28-
highlight,
29-
clearText,
30-
backspace,
31-
type,
32-
spanWithColor,
33-
clearDelay,
34-
typeDelay,
35-
clearData,
36-
isNumber,
37-
typeWithAttribute,
38-
getHighlightInterval,
39-
getTypeInterval,
40-
intervalHandle,
41-
typerInterval;
14+
var opts,
15+
highlight,
16+
clearText,
17+
backspace,
18+
type,
19+
spanWithColor,
20+
clearDelay,
21+
typeDelay,
22+
clearData,
23+
isNumber,
24+
typeWithAttribute,
25+
getHighlightInterval,
26+
getTypeInterval,
27+
intervalHandle,
28+
typerInterval;
4229

4330
spanWithColor = function(color, backgroundColor) {
4431
if (color === 'rgba(0, 0, 0, 0)') {
@@ -83,7 +70,6 @@ String.prototype.rightChars = function(n){
8370
return;
8471
}
8572

86-
8773
$e.text(
8874
oldLeft +
8975
text.charAt(0) +
@@ -136,7 +122,7 @@ String.prototype.rightChars = function(n){
136122
.append(
137123
spanWithColor(
138124
$e.data('backgroundColor'),
139-
$.typer.options.tapeColor === 'auto' ? $e.data('primaryColor') : $.typer.options.tapeColor
125+
opts.tapeColor === 'auto' ? $e.data('primaryColor') : opts.tapeColor
140126
)
141127
.append(highlightedText)
142128
)
@@ -160,47 +146,40 @@ String.prototype.rightChars = function(n){
160146
}
161147

162148
try {
163-
targets = JSON.parse($e.attr($.typer.options.typerDataAttr)).targets;
149+
targets = JSON.parse($e.attr(opts.typerDataAttr)).targets;
164150
} catch (e) {}
165151

166152
if (typeof targets === "undefined") {
167-
targets = $.map($e.attr($.typer.options.typerDataAttr).split(','), function (e) {
153+
targets = $.map($e.attr(opts.typerDataAttr).split(','), function (e) {
168154
return $.trim(e);
169155
});
170156
}
171157

172-
if ($.typer.options.typerOrder == 'random') {
158+
if (opts.typerOrder == 'random') {
173159
$e.typeTo(targets[Math.floor(Math.random()*targets.length)]);
174160
}
175-
else if ($.typer.options.typerOrder == 'sequential') {
161+
else if (opts.typerOrder == 'sequential') {
176162
$e.typeTo(targets[last]);
177163
last = (last < targets.length - 1) ? last + 1 : 0;
178164
}
179165
else {
180-
console.error("Type order of '" + $.typer.options.typerOrder + "' not supported");
166+
console.error("Type order of '" + opts.typerOrder + "' not supported");
181167
clearInterval(intervalHandle);
182168
}
183-
}
184-
})();
185-
186-
// Expose our options to the world.
187-
$.typer = (function () {
188-
return { options: options };
169+
};
189170
})();
190171

191-
$.extend($.typer, {
192-
options: options
193-
});
194-
195172
//-- Methods to attach to jQuery sets
196173

197-
$.fn.typer = function() {
174+
$.fn.typer = function(options) {
198175
var $elements = $(this);
199176

177+
opts = jQuery.extend({}, $.fn.typer.defaults, options);
178+
200179
return $elements.each(function () {
201180
var $e = $(this);
202181

203-
if (typeof $e.attr($.typer.options.typerDataAttr) === "undefined") {
182+
if (typeof $e.attr(opts.typerDataAttr) === "undefined") {
204183
return;
205184
}
206185

@@ -219,22 +198,22 @@ String.prototype.rightChars = function(n){
219198
j = 0;
220199

221200
if (currentText === newString) {
222-
if ($.typer.options.debug === true) {
201+
if (opts.debug === true) {
223202
console.log("Our strings our equal, nothing to type");
224203
}
225204
return $e;
226205
}
227206

228207
if (currentText !== $e.html()) {
229-
if ($.typer.options.debug === true) {
208+
if (opts.debug === true) {
230209
console.error("Typer does not work on elements with child elements.");
231210
}
232211
return $e;
233212
}
234213

235214
$e.data('typing', true);
236215

237-
if ($.typer.options.highlightEverything !== true) {
216+
if (opts.highlightEverything !== true) {
238217
while (currentText.charAt(i) === newString.charAt(i)) {
239218
i++;
240219
}
@@ -251,7 +230,7 @@ String.prototype.rightChars = function(n){
251230
oldRight: currentText.rightChars(j - 1),
252231
leftStop: i,
253232
rightStop: currentText.length - j,
254-
primaryColor: $.typer.options.tapeColor === 'auto' ? $e.data('primaryColor') : $.typer.options.tapeColor,
233+
primaryColor: opts.tapeColor === 'auto' ? $e.data('primaryColor') : opts.tapeColor,
255234
backgroundColor: $e.css('background-color'),
256235
text: newString
257236
});
@@ -264,22 +243,37 @@ String.prototype.rightChars = function(n){
264243
//-- Helper methods. These can one day be customized further to include things like ranges of delays.
265244

266245
getHighlightInterval = function () {
267-
return $.typer.options.highlightSpeed;
246+
return opts.highlightSpeed;
268247
};
269248

270249
getTypeInterval = function () {
271-
return $.typer.options.typeSpeed;
272-
},
250+
return opts.typeSpeed;
251+
};
273252

274253
clearDelay = function () {
275-
return $.typer.options.clearDelay;
276-
},
254+
return opts.clearDelay;
255+
};
277256

278257
typeDelay = function () {
279-
return $.typer.options.typeDelay;
258+
return opts.typeDelay;
280259
};
281260

282261
typerInterval = function () {
283-
return $.typer.options.typerInterval;
262+
return opts.typerInterval;
284263
};
264+
265+
$.fn.typer.defaults = {
266+
highlightSpeed : 20,
267+
typeSpeed : 100,
268+
clearDelay : 500,
269+
typeDelay : 200,
270+
clearOnHighlight : true,
271+
highlightEverything : true,
272+
typerDataAttr : 'data-typer-targets',
273+
typerInterval : 2000,
274+
debug : false,
275+
tapeColor : 'auto',
276+
typerOrder : 'random',
277+
};
278+
285279
})(jQuery);

dist/jquery.typer.min.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "jquery.typer.js",
3+
"version": "1.0.0",
4+
"description": "A simple jQuery plugin for a slick typing effect.",
5+
"main": "Gruntfile.js",
6+
"dependencies": {},
7+
"devDependencies": {
8+
"grunt": "^0.4.5",
9+
"grunt-contrib-concat": "^0.5.1",
10+
"grunt-contrib-copy": "^0.8.0",
11+
"grunt-contrib-jshint": "^0.11.1",
12+
"grunt-contrib-uglify": "^0.8.0",
13+
"grunt-contrib-watch": "^0.6.1"
14+
},
15+
"scripts": {
16+
"test": "echo \"Error: no test specified\" && exit 1"
17+
},
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/kontur/jquery.typer.js.git"
21+
},
22+
"keywords": [
23+
"jquery",
24+
"typer",
25+
"typing",
26+
"typewriter",
27+
"text"
28+
],
29+
"author": "Johannes Neumeier <hello@johannesneumeier.com>",
30+
"bugs": {
31+
"url": "https://github.com/kontur/jquery.typer.js/issues"
32+
},
33+
"homepage": "https://github.com/kontur/jquery.typer.js"
34+
}

0 commit comments

Comments
 (0)