Skip to content

Commit

Permalink
Add bower support + gulp + fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-D committed Jan 26, 2015
1 parent a8cc35a commit 6df07d4
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Auto detect text files and perform LF normalization
* text=auto

# SCSS and JS files must always use LF for tools to work
*.js eol=lf
*.scss eol=lf
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
~$*
/node_modules
/bower_components
11 changes: 11 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"expr": true,
"noarg": true,
"onevar": true,
"quotmark": "double",
"undef": true,
"unused": true,

"browser": true,
"node": true
}
66 changes: 66 additions & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
var gulp = require('gulp'),
del = require('del'),
vinylPaths = require('vinyl-paths'),
$ = require('gulp-load-plugins')();

var pkg = require('./package.json');
var banner = ['/**',
' * <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %>',
' * ------------------------',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' * @author <%= pkg.author.name %>',
' * Twitter : @AlexandreDemode',
' * Website : <%= pkg.author.url.replace("http://", "") %>',
' */',
'\n'].join('\n');
var bannerLight = ['/** <%= pkg.title %> v<%= pkg.version %> - <%= pkg.description %>',
' - <%= pkg.homepage.replace("http://", "") %>',
' - License <%= pkg.license %>',
' - Author : <%= pkg.author.name %>',
' / <%= pkg.author.url.replace("http://", "") %>',
' */',
'\n'].join('');




gulp.task('clean', function(){
return gulp.src(['*.min.js'])
.pipe(vinylPaths(del));
});

gulp.task('test', function(){
return gulp.src(['cookies-cnil-banner.js'])
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'));
});

gulp.task('scripts', ['test'], function(){
return gulp.src(['cookies-cnil-banner.js'])
.pipe($.header(banner, { pkg: pkg }))
.pipe($.newer('cookies-cnil-banner.min.js'))
.pipe($.concat('cookies-cnil-banner.js', { newLine: '\r\n\r\n' }))
.pipe($.size({ title: 'cookies-cnil-banner.js' }))
.pipe($.rename({ suffix: ".min" }))
.pipe($.uglify())
.pipe($.header(bannerLight, { pkg: pkg }))
.pipe(gulp.dest('.'))
.pipe($.size({ title: 'cookies-cnil-banner.min.js' }))
});



gulp.task('watch', function(){
gulp.watch(['cookies-cnil-banner.js'], ['scripts']);

gulp.watch(['/*.min.js'], function(file){
$.livereload.changed(file);
});

$.livereload.listen();
});

gulp.task('build', ['scripts']);

gulp.task('default', ['build', 'watch']);
22 changes: 22 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "cookies-cnil-banner",
"main": "cookies-cnil-banner.js",
"version": "1.0.0",
"homepage": "https://github.com/Alex-D/cookies-cnil-banner",
"authors": [
"Alex-D <contact@alex-d.fr>"
],
"description": "Manage display of banner to accept/reject cookies from tracking services like Google Analytics.",
"keywords": [
"cookies",
"analytics"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
18 changes: 9 additions & 9 deletions cookies-cnil-banner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;var CookiesCnilBanner;
var CookiesCnilBanner;

(function(navigator, window, document){
CookiesCnilBanner = function(launchFunction){
Expand Down Expand Up @@ -32,7 +32,7 @@
this.showBanner();

// Accept cookies by default for the next page
this.setCookie('hasConsent', true);
this.setCookie("hasConsent", true);
},

/*
Expand All @@ -41,25 +41,25 @@
showBanner: function(){
var _this = this,
banner = document.getElementById("cookies-cnil-banner"),
rejectButton = document.getElementById("cookies-cnil-reject")
acceptButton = document.getElementById("cookies-cnil-accept")
rejectButton = document.getElementById("cookies-cnil-reject"),
acceptButton = document.getElementById("cookies-cnil-accept"),
moreLink = document.getElementById("cookies-cnil-more");

banner.style.display = "block";

this.addEventListener(moreLink, "click", function(e){
_this.deleteCookie('hasConsent');
this.addEventListener(moreLink, "click", function(){
_this.deleteCookie("hasConsent");
});

this.addEventListener(acceptButton, "click", function(){
banner.parentNode.removeChild(banner);
_this.setCookie('hasConsent', true);
_this.setCookie("hasConsent", true);
_this.launchFunction();
});

this.addEventListener(rejectButton, "click", function(){
banner.parentNode.removeChild(banner);
_this.setCookie('hasConsent', false);
_this.setCookie("hasConsent", false);
});
},

Expand Down Expand Up @@ -89,7 +89,7 @@
*/
isToTrack: function() {
var dnt = navigator.doNotTrack || navigator.msDoNotTrack || window.doNotTrack;
return (dnt !== undefined) ? (dnt && dnt !== 'yes' && dnt !== 1 && dnt !== "1") : true;
return (dnt !== undefined) ? (dnt && dnt !== "yes" && dnt !== 1 && dnt !== "1") : true;
},

/*
Expand Down
2 changes: 2 additions & 0 deletions cookies-cnil-banner.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "cookies-cnil-banner",
"title": "Cookies CNIL banner",
"description": "Manage display of banner to accept/reject cookies from tracking services like Google Analytics",
"version": "1.0.0",
"main": "cookies-cnil-banner.js",
"homepage": "https://github.com/Alex-D/cookies-cnil-banner",
"author": {
"name": "Alexandre Demode (Alex-D)",
"email": "contact@alex-d.fr",
"url": "http://alex-d.fr"
},
"repository": {
"type": "git",
"url": "https://github.com/Alex-D/cookies-cnil-banner.git"
},
"bugs": {
"url": "https://github.com/Alex-D/cookies-cnil-banner/issues"
},
"license": "MIT",
"dependencies": {
"bower": "^1.3.9",
"del": "^1.1.1",
"gulp": "^3.8.5",
"gulp-concat": "~2.3.4",
"gulp-header": "^1.2.2",
"gulp-jshint": "~1.8.4",
"gulp-livereload": "~2.1.0",
"gulp-load-plugins": "~0.5.3",
"gulp-newer": "~0.3.0",
"gulp-rename": "~1.2.0",
"gulp-size": "~1.0.0",
"gulp-uglify": "~0.3.1",
"jshint-stylish": "~0.4.0",
"vinyl-paths": "^1.0.0"
},
"scripts": {
"build": "npm install && gulp build",
"start": "gulp",
"test": "gulp test"
}
}

0 comments on commit 6df07d4

Please sign in to comment.