Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Commit 5c08b51

Browse files
author
Chris Ferdinandi
committed
updated version number
1 parent 7712648 commit 5c08b51

12 files changed

+84
-43
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Gulp Boilerplate is licensed under the [MIT License](http://gomakethings.com/mit
129129

130130
Gulp Boilerplate uses [semantic versioning](http://semver.org/).
131131

132+
* v1.0.0 - August 31, 2014
133+
* Fixed event listener filter to account for sub elements.
132134
* v0.7.0 - August 24, 2014
133135
* Add new task(s) for concatenating scripts. DRYer code.
134136
* v0.6.0 - August 23, 2014

dist/css/myplugin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.7.0
2+
* gulp-boilerplate v1.0.0
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/css/myplugin.min.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/** gulp-boilerplate v0.7.0, by Chris Ferdinandi | http://github.com/cferdinandi/Plugin | Licensed under MIT: http://gomakethings.com/mit/ */
1+
/** gulp-boilerplate v1.0.0, by Chris Ferdinandi | http://github.com/cferdinandi/Plugin | Licensed under MIT: http://gomakethings.com/mit/ */

dist/js/bind-polyfill.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.7.0
2+
* gulp-boilerplate v1.0.0
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/js/bind-polyfill.min.js

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

dist/js/classList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.7.0
2+
* gulp-boilerplate v1.0.0
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/js/classList.min.js

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

dist/js/myplugin.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.7.0
2+
* gulp-boilerplate v1.0.0
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*
@@ -89,6 +89,32 @@
8989
return !options || !(typeof JSON === 'object' && typeof JSON.parse === 'function') ? {} : JSON.parse( options );
9090
};
9191

92+
/**
93+
* Get the closest matching element up the DOM tree
94+
* @param {Element} elem Starting element
95+
* @param {String} selector Selector to match against (class, ID, or data attribute)
96+
* @return {Boolean|Element} Returns false if not match found
97+
*/
98+
var getClosest = function (elem, selector) {
99+
var firstChar = selector.charAt(0);
100+
for ( ; elem && elem !== document; elem = elem.parentNode ) {
101+
if ( firstChar === '.' ) {
102+
if ( elem.classList.contains( selector.substr(1) ) ) {
103+
return elem;
104+
}
105+
} else if ( firstChar === '#' ) {
106+
if ( elem.id === selector.substr(1) ) {
107+
return elem;
108+
}
109+
} else if ( firstChar === '[' ) {
110+
if ( elem.hasAttribute( selector.substr(1, selector.length - 2) ) ) {
111+
return elem;
112+
}
113+
}
114+
}
115+
return false;
116+
};
117+
92118
// @todo Do something...
93119

94120
/**
@@ -97,7 +123,8 @@
97123
*/
98124
var eventHandler = function (event) {
99125
var toggle = event.target;
100-
if ( toggle.hasAttribute('data-myplugin') ) {
126+
var closest = getClosest(toggle, '[data-some-selector]');
127+
if ( closest ) {
101128
// run methods
102129
}
103130
};

dist/js/myplugin.min.js

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

gulpfile.js

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var gulp = require('gulp');
33
var plumber = require('gulp-plumber');
44
var clean = require('gulp-clean');
5+
var lazypipe = require('lazypipe');
56
var rename = require('gulp-rename');
67
var flatten = require('gulp-flatten');
78
var tap = require('gulp-tap');
@@ -19,7 +20,6 @@ var package = require('./package.json');
1920
// Paths to project folders
2021
var paths = {
2122
output : 'dist/',
22-
temp: 'src/temp/',
2323
scripts : {
2424
input : [ 'src/js/*' ],
2525
output : 'dist/js/'
@@ -55,36 +55,29 @@ var banner = {
5555
' */\n'
5656
};
5757

58-
// Concatenate scripts in subfolders
59-
gulp.task('concatenate', function() {
58+
// Lint, minify, and concatenate scripts
59+
gulp.task('scripts', ['clean'], function() {
60+
61+
var jsTasks = lazypipe()
62+
.pipe(header, banner.full, { package : package })
63+
.pipe(gulp.dest, paths.scripts.output)
64+
.pipe(rename, { suffix: '.min' })
65+
.pipe(uglify)
66+
.pipe(header, banner.min, { package : package })
67+
.pipe(gulp.dest, paths.scripts.output);
68+
6069
return gulp.src(paths.scripts.input)
6170
.pipe(plumber())
6271
.pipe(flatten())
63-
6472
.pipe(tap(function (file, t) {
6573
if ( file.stat.isDirectory() ) {
6674
var name = file.relative + '.js';
6775
return gulp.src(file.path + '/*.js')
6876
.pipe(concat(name))
69-
.pipe(gulp.dest(paths.temp));
77+
.pipe(jsTasks());
7078
}
71-
}));
72-
});
73-
74-
// Lint and minify scripts
75-
gulp.task('scripts', ['clean', 'concatenate'], function() {
76-
return gulp.src([
77-
paths.scripts.input + '/../*.js',
78-
paths.temp + '/*.js'
79-
])
80-
.pipe(plumber())
81-
.pipe(flatten())
82-
.pipe(header(banner.full, { package : package }))
83-
.pipe(gulp.dest(paths.scripts.output))
84-
.pipe(rename({ suffix: '.min' }))
85-
.pipe(uglify())
86-
.pipe(header(banner.min, { package : package }))
87-
.pipe(gulp.dest(paths.scripts.output));
79+
}))
80+
.pipe(jsTasks());
8881
});
8982

9083
// Process, lint, and minify Sass files
@@ -128,13 +121,6 @@ gulp.task('clean', function () {
128121
.pipe(clean());
129122
});
130123

131-
// Remove temporary files
132-
gulp.task('cleanTemp', ['scripts'], function () {
133-
return gulp.src(paths.temp, { read: false })
134-
.pipe(plumber())
135-
.pipe(clean());
136-
});
137-
138124
// Run unit tests
139125
gulp.task('test', function() {
140126
return gulp.src([paths.scripts.input + '/../**/*.js'].concat(paths.test.spec))
@@ -148,9 +134,7 @@ gulp.task('default', [
148134
'lint',
149135
'clean',
150136
'static',
151-
'concatenate',
152137
'scripts',
153138
'styles',
154-
'cleanTemp',
155139
'test'
156140
]);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gulp-boilerplate",
3-
"version": "0.7.0",
3+
"version": "1.0.0",
44
"description": "My Gulp.js boilerplate for creating new web projects",
55
"author": {
66
"name": "Chris Ferdinandi",
@@ -27,6 +27,7 @@
2727
"gulp-ruby-sass": "~0.7.1",
2828
"gulp-uglify": "~0.3.0",
2929
"jshint-stylish": "^0.2.0",
30+
"lazypipe": "0.2.2",
3031
"karma": "^0.12.16",
3132
"karma-coverage": "^0.2.4",
3233
"karma-jasmine": "~0.2.0",

src/js/myplugin.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@
8080
return !options || !(typeof JSON === 'object' && typeof JSON.parse === 'function') ? {} : JSON.parse( options );
8181
};
8282

83+
/**
84+
* Get the closest matching element up the DOM tree
85+
* @param {Element} elem Starting element
86+
* @param {String} selector Selector to match against (class, ID, or data attribute)
87+
* @return {Boolean|Element} Returns false if not match found
88+
*/
89+
var getClosest = function (elem, selector) {
90+
var firstChar = selector.charAt(0);
91+
for ( ; elem && elem !== document; elem = elem.parentNode ) {
92+
if ( firstChar === '.' ) {
93+
if ( elem.classList.contains( selector.substr(1) ) ) {
94+
return elem;
95+
}
96+
} else if ( firstChar === '#' ) {
97+
if ( elem.id === selector.substr(1) ) {
98+
return elem;
99+
}
100+
} else if ( firstChar === '[' ) {
101+
if ( elem.hasAttribute( selector.substr(1, selector.length - 2) ) ) {
102+
return elem;
103+
}
104+
}
105+
}
106+
return false;
107+
};
108+
83109
// @todo Do something...
84110

85111
/**
@@ -88,7 +114,8 @@
88114
*/
89115
var eventHandler = function (event) {
90116
var toggle = event.target;
91-
if ( toggle.hasAttribute('data-myplugin') ) {
117+
var closest = getClosest(toggle, '[data-some-selector]');
118+
if ( closest ) {
92119
// run methods
93120
}
94121
};

0 commit comments

Comments
 (0)