From 49ab4771b9060bf8405968b00801bf71871e44c8 Mon Sep 17 00:00:00 2001 From: Ramon Gebben Date: Sun, 18 Jan 2015 11:59:12 +0100 Subject: [PATCH] Added linting by jshint --- Cquence.js | 90 ++++++++++++++++++++++----------------------- Gulpfile.js | 16 ++++++-- minified/Cquence.js | 2 +- package.json | 4 +- 4 files changed, 60 insertions(+), 52 deletions(-) diff --git a/Cquence.js b/Cquence.js index d1d1f03..5edc1ed 100644 --- a/Cquence.js +++ b/Cquence.js @@ -2,10 +2,10 @@ var Cquence; Cquence = function(){ - var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function( f ){ setTimeout( f, 1000/60 ); }; - var elem = function( id ){ return document.getElementById( id ); } - - // IE checking + var raf = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function( f ){ setTimeout( f, 1000/60 ); }; + var elem = function( id ){ return document.getElementById( id ); }; + + // IE checking var IEVERSION = getInternetExplorerVersion(); var IE8 = IEVERSION === 8; var IEWTF = IEVERSION < 8 && IEVERSION > -1; @@ -14,15 +14,15 @@ Cquence = function(){ if( k === 'opacity' ){ if( IE8 ){ // gemene browsers e.style[ "-ms-filter" ] = "progid:DXImageTransform.Microsoft.Alpha(Opacity=" + Math.floor( v * 100 ) + ")"; - e.style[ "filter" ] = "alpha(opacity=" + Math.floor( v * 100 ) + ")";// ; - + e.style.filter = "alpha(opacity=" + Math.floor( v * 100 ) + ")"; + } else { // lieve browsers - e.style[k] = v; + e.style[k] = v; } } else { e.style[k] = v + "px"; } - } + }; var combine = function(){ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments @@ -31,8 +31,8 @@ Cquence = function(){ for( var i=0; i t ){ - last.f( t - total ); - return; - } + last.f( t - total ); + return; + } if( !last.done ){ last.f( last.d ); last.done = true; @@ -77,37 +77,37 @@ Cquence = function(){ total = total + last.d; } } - } - } + }; + }; - var animate = function( transform ){ + var animate = function( transform ){ return function( id, dur, begin, fin ){ - return { - d: dur, + return { + d: dur, f: function( t ){ var e = elem( id ); for( var k in begin ){ - + var bv = begin[k]; // begin waarde var fv = fin[k]; // finish waarde var dx = fv - bv; // verschil (afstand) - - // p is nu een waarde tussen de 0 en 1 .. en geeft aan hoe ver de animatie is - var p = transform( Math.max( t/dur, 0 ) ); - + + // p is nu een waarde tussen de 0 en 1 .. en geeft aan hoe ver de animatie is + var p = transform( Math.max( t/dur, 0 ) ); + // nieuwe waarde is de factor maal de afstand - var nv = bv + (p * dx); + var nv = bv + (p * dx); style( e, k, nv ); } } - } - } - } + }; + }; + }; // animation variants // http://upshots.org/actionscript/jsas-understanding-easing - var linear = animate( function( p ){ - return p; + var linear = animate( function( p ){ + return p; }); var easeIn = animate( function( p ){ return Math.pow( p, 5 ); @@ -116,8 +116,8 @@ Cquence = function(){ return 1 - Math.pow( 1 - p, 5 ); }); var sleep = function( d ){ - return { d: d, f: function(t){} } - } + return { d: d, f: function(t){} }; + }; /* from: http://stackoverflow.com/questions/10964966/detect-ie-version-in-javascript */ function getInternetExplorerVersion() @@ -129,14 +129,14 @@ Cquence = function(){ { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); - if (re.exec(ua) != null) + if (re.exec(ua) !== null) rv = parseFloat( RegExp.$1 ); } return rv; } var timeline = []; - var start = (+new Date); // unix timestamp + var start = (+new Date()); // unix timestamp var second = 1000; var stop = 15 * second; var render = null; @@ -144,12 +144,12 @@ Cquence = function(){ // gets called recursive by request-animation-frame var renderloop = function(){ // console.log('1. ', window.render ); - var now = (+new Date) - start; // relatieve tijd vanaf begin animatie + var now = (+new Date()) - start; // relatieve tijd vanaf begin animatie if( now < stop ) raf( renderloop ); // recursion, baby // console.log('2. ', window.render ); if( window.render ) window.render.f( now ); - - } + + }; return { combine: combine, @@ -160,8 +160,6 @@ Cquence = function(){ easeOut: easeOut, sleep: sleep, renderloop: renderloop - } + }; }(); - - diff --git a/Gulpfile.js b/Gulpfile.js index 69df5d6..f999ef5 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -1,9 +1,17 @@ -var gulp=require("gulp"), -uglify = require("gulp-uglify"); +var gulp = require("gulp"), +uglify = require("gulp-uglify"), +jshint = require('gulp-jshint'), +stylish = require('jshint-stylish'); + +gulp.task('lint', function() { + return gulp.src('./Cquence.js') + .pipe(jshint()) + .pipe(jshint.reporter( stylish )); +}); gulp.task("compress", function(){ - gulp.src("Cquence.js").pipe( uglify() ).pipe( gulp.dest("minified") ) + gulp.src("./Cquence.js").pipe( uglify() ).pipe( gulp.dest("minified") ); }); -gulp.task('ci', ['compress']); \ No newline at end of file +gulp.task('ci', ['lint', 'compress']); diff --git a/minified/Cquence.js b/minified/Cquence.js index f3f0841..a2fccb1 100644 --- a/minified/Cquence.js +++ b/minified/Cquence.js @@ -1 +1 @@ -var Cquence;Cquence=function(){function n(){var n=-1;if("Microsoft Internet Explorer"==navigator.appName){var e=navigator.userAgent,t=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");null!=t.exec(e)&&(n=parseFloat(RegExp.$1))}return n}var e=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(n){setTimeout(n,1e3/60)},t=function(n){return document.getElementById(n)},r=function(n,e,t){"opacity"===e?s?(n.style["-ms-filter"]="progid:DXImageTransform.Microsoft.Alpha(Opacity="+Math.floor(100*t)+")",n.style.filter="alpha(opacity="+Math.floor(100*t)+")"):n.style[e]=t:n.style[e]=t+"px"},o=function(){for(var n=Array.prototype.slice.call(arguments,0),e=0,t=0;te?r.f(e):r.done||(r.f(r.d),r.done=!0)}}}},a=function(){for(var n=Array.prototype.slice.call(arguments,0),e=0,t=0;te)return void t.f(e-r);t.done||(t.f(t.d),t.done=!0),r+=t.d}}}},i=function(n){return function(e,o,a,i){return{d:o,f:function(u){var f=t(e);for(var c in a){var l=a[c],d=i[c],s=d-l,m=n(Math.max(u/o,0)),p=l+m*s;r(f,c,p)}}}}},u=i(function(n){return n}),f=i(function(n){return Math.pow(n,5)}),c=i(function(n){return 1-Math.pow(1-n,5)}),l=function(n){return{d:n,f:function(){}}},d=n(),s=8===d,m=+new Date,p=1e3,w=15*p,v=function(){var n=+new Date-m;w>n&&e(v),window.render&&window.render.f(n)};return{combine:o,sequence:a,linear:u,animate:i,easeIn:f,easeOut:c,sleep:l,renderloop:v}}(); \ No newline at end of file +var Cquence;Cquence=function(){function n(){var n=-1;if("Microsoft Internet Explorer"==navigator.appName){var e=navigator.userAgent,t=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");null!==t.exec(e)&&(n=parseFloat(RegExp.$1))}return n}var e=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(n){setTimeout(n,1e3/60)},t=function(n){return document.getElementById(n)},r=n(),o=8===r,a=function(n,e,t){"opacity"===e?o?(n.style["-ms-filter"]="progid:DXImageTransform.Microsoft.Alpha(Opacity="+Math.floor(100*t)+")",n.style.filter="alpha(opacity="+Math.floor(100*t)+")"):n.style[e]=t:n.style[e]=t+"px"},i=function(){for(var n=Array.prototype.slice.call(arguments,0),e=0,t=0;te?r.f(e):r.done||(r.f(r.d),r.done=!0)}}}},u=function(){for(var n=Array.prototype.slice.call(arguments,0),e=0,t=0;te)return void t.f(e-r);t.done||(t.f(t.d),t.done=!0),r+=t.d}}}},f=function(n){return function(e,r,o,i){return{d:r,f:function(u){var f=t(e);for(var c in o){var l=o[c],d=i[c],s=d-l,m=n(Math.max(u/r,0)),p=l+m*s;a(f,c,p)}}}}},c=f(function(n){return n}),l=f(function(n){return Math.pow(n,5)}),d=f(function(n){return 1-Math.pow(1-n,5)}),s=function(n){return{d:n,f:function(){}}},m=+new Date,p=1e3,w=15*p,v=function(){var n=+new Date-m;w>n&&e(v),window.render&&window.render.f(n)};return{combine:i,sequence:u,linear:c,animate:f,easeIn:l,easeOut:d,sleep:s,renderloop:v}}(); \ No newline at end of file diff --git a/package.json b/package.json index 892036e..047b230 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "version": "1.0.0", "devDependencies": { "gulp": "^3.8.10", - "gulp-uglify": "^1.0.2" + "gulp-jshint": "^1.9.0", + "gulp-uglify": "^1.0.2", + "jshint-stylish": "^1.0.0" } }