mirror of https://github.com/toddmotto/echo.git
Todd Motto
11 years ago
9 changed files with 132 additions and 50 deletions
@ -1,5 +1,7 @@
|
||||
language: node_js |
||||
node_js: |
||||
- "0.11" |
||||
- "0.10" |
||||
- "0.8" |
||||
- "0.11" |
||||
before_script: |
||||
- npm install -g gulp |
||||
script: gulp |
||||
|
@ -1,2 +1,2 @@
|
||||
/*! echo.js v1.6.0 | (c) 2014 @toddmotto | MIT license | github.com/toddmotto/echo */ |
||||
!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b:a.echo=b(a)}(this,function(a){"use strict";var b,c,d,e,f={},g=function(){},h=function(a,b){var c=a.getBoundingClientRect();return c.right>=b.l&&c.bottom>=b.t&&c.left<=b.r&&c.top<=b.b},i=function(){clearTimeout(c),c=setTimeout(f.render,d)};return f.init=function(c){c=c||{};var h=c.offset||0,j=c.offsetVertical||h,k=c.offsetHorizontal||h,l=function(a,b){return parseInt(a||b,10)};b={t:l(c.offsetTop,j),b:l(c.offsetBottom,j),l:l(c.offsetLeft,k),r:l(c.offsetRight,k)},d=l(c.throttle,250),e=!!c.unload,g=c.callback||g,f.render(),document.addEventListener?(a.addEventListener("scroll",i,!1),a.addEventListener("load",i,!1)):(a.attachEvent("onscroll",i),a.attachEvent("onload",i))},f.render=function(){for(var c,d,i=document.querySelectorAll("img[data-echo]"),j=i.length,k={l:0-b.l,t:0-b.t,b:(a.innerHeight||document.documentElement.clientHeight)+b.b,r:(a.innerWidth||document.documentElement.clientWidth)+b.r},l=0;j>l;l++)d=i[l],h(d,k)?(e&&d.setAttribute("data-echo-placeholder",d.src),d.src=d.getAttribute("data-echo"),e||d.removeAttribute("data-echo"),g(d,"load")):e&&(c=d.getAttribute("data-echo-placeholder"))&&(d.src=c,d.removeAttribute("data-echo-placeholder"),g(d,"unload"));j||f.detach()},f.detach=function(){document.removeEventListener?a.removeEventListener("scroll",i):a.detachEvent("onscroll",i),clearTimeout(c)},f}); |
||||
/*! echo.js v1.6.0 | (c) 2014 @toddmotto | https://github.com/echo */ |
||||
!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e:t.echo=e(t)}(this,function(t){"use strict";var e,o,n,r,c={},i=function(){},a=function(t,e){var o=t.getBoundingClientRect();return o.right>=e.l&&o.bottom>=e.t&&o.left<=e.r&&o.top<=e.b},d=function(){clearTimeout(o),o=setTimeout(c.render,n)};return c.init=function(o){o=o||{};var a=o.offset||0,l=o.offsetVertical||a,u=o.offsetHorizontal||a,f=function(t,e){return parseInt(t||e,10)};e={t:f(o.offsetTop,l),b:f(o.offsetBottom,l),l:f(o.offsetLeft,u),r:f(o.offsetRight,u)},n=f(o.throttle,250),r=!!o.unload,i=o.callback||i,c.render(),document.addEventListener?(t.addEventListener("scroll",d,!1),t.addEventListener("load",d,!1)):(t.attachEvent("onscroll",d),t.attachEvent("onload",d))},c.render=function(){for(var o,n,d=document.querySelectorAll("img[data-echo]"),l=d.length,u={l:0-e.l,t:0-e.t,b:(t.innerHeight||document.documentElement.clientHeight)+e.b,r:(t.innerWidth||document.documentElement.clientWidth)+e.r},f=0;l>f;f++)n=d[f],a(n,u)?(r&&n.setAttribute("data-echo-placeholder",n.src),n.src=n.getAttribute("data-echo"),r||n.removeAttribute("data-echo"),i(n,"load")):r&&(o=n.getAttribute("data-echo-placeholder"))&&(n.src=o,n.removeAttribute("data-echo-placeholder"),i(n,"unload"));l||c.detach()},c.detach=function(){document.removeEventListener?t.removeEventListener("scroll",d):t.detachEvent("onscroll",d),clearTimeout(o)},c}); |
@ -0,0 +1,68 @@
|
||||
var gulp = require('gulp'), |
||||
karma = require('gulp-karma'), |
||||
jshint = require('gulp-jshint'), |
||||
stylish = require('jshint-stylish'), |
||||
header = require('gulp-header'), |
||||
uglify = require('gulp-uglify'), |
||||
plumber = require('gulp-plumber'), |
||||
clean = require('gulp-clean'), |
||||
rename = require('gulp-rename'), |
||||
package = require('./package.json'); |
||||
|
||||
var paths = { |
||||
output : 'dist/', |
||||
scripts : [ |
||||
'src/echo.js' |
||||
], |
||||
test: [ |
||||
'test/spec/**/*.js' |
||||
] |
||||
}; |
||||
|
||||
var banner = [ |
||||
'/*! ', |
||||
'<%= package.name %> ', |
||||
'v<%= package.version %> | ', |
||||
'(c) ' + new Date().getFullYear() + ' <%= package.author %> |', |
||||
' <%= package.homepage %>', |
||||
' */', |
||||
'\n' |
||||
].join(''); |
||||
|
||||
gulp.task('scripts', ['clean'], function() { |
||||
return gulp.src(paths.scripts) |
||||
.pipe(plumber()) |
||||
.pipe(header(banner, { package : package })) |
||||
.pipe(gulp.dest('dist/')) |
||||
.pipe(rename({ suffix: '.min' })) |
||||
.pipe(uglify()) |
||||
.pipe(header(banner, { package : package })) |
||||
.pipe(gulp.dest('dist/')); |
||||
}); |
||||
|
||||
gulp.task('lint', function () { |
||||
return gulp.src(paths.scripts) |
||||
.pipe(plumber()) |
||||
.pipe(jshint()) |
||||
.pipe(jshint.reporter('jshint-stylish')); |
||||
}); |
||||
|
||||
gulp.task('clean', function () { |
||||
return gulp.src(paths.output, { read: false }) |
||||
.pipe(plumber()) |
||||
.pipe(clean()); |
||||
}); |
||||
|
||||
gulp.task('test', function() { |
||||
return gulp.src(paths.scripts.concat(paths.test)) |
||||
.pipe(plumber()) |
||||
.pipe(karma({ configFile: 'test/karma.conf.js' })) |
||||
.on('error', function(err) { throw err; }); |
||||
}); |
||||
|
||||
gulp.task('default', [ |
||||
'lint', |
||||
'clean', |
||||
'scripts', |
||||
'test' |
||||
]); |
@ -1,34 +1,23 @@
|
||||
{ |
||||
"name": "echo.js", |
||||
"version": "1.6.0", |
||||
"homepage": "https://github.com/toddmotto/echo", |
||||
"author": "Todd Motto", |
||||
"description": "Lazy-loading with data-* attributes, offset and throttle options", |
||||
"author": { |
||||
"name": "Todd Motto", |
||||
"email": "todd@toddmotto.com", |
||||
"url": "http://toddmotto.com", |
||||
"github" : "https://github.com/toddmotto" |
||||
}, |
||||
"licenses": [{ |
||||
"type": "MIT" |
||||
}], |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "http://github.com/toddmotto/echo.git" |
||||
}, |
||||
"author": "@toddmotto", |
||||
"license": "MIT", |
||||
"homepage": "https://github.com/echo", |
||||
"devDependencies": { |
||||
"grunt": "~0.4.1", |
||||
"grunt-contrib-jshint": "~0.7.1", |
||||
"grunt-contrib-concat": "~0.3.0", |
||||
"grunt-contrib-uglify": "~0.2.7", |
||||
"grunt-contrib-connect": "~0.3.0", |
||||
"grunt-contrib-watch": "~0.4.4", |
||||
"connect-livereload": "~0.2.0", |
||||
"grunt-open": "~0.2.0", |
||||
"matchdep": "~0.1.2" |
||||
}, |
||||
"peerDependencies": { |
||||
"grunt-cli": "*" |
||||
"gulp": "~3.7.0", |
||||
"gulp-uglify": "~0.3.0", |
||||
"gulp-rename": "~1.1.0", |
||||
"gulp-clean": "^0.2.4", |
||||
"gulp-plumber": "~0.6.2", |
||||
"gulp-header": "^1.0.2", |
||||
"gulp-jshint": "^1.6.1", |
||||
"jshint-stylish": "^0.2.0", |
||||
"gulp-karma": "0.0.4", |
||||
"karma": "^0.12.16", |
||||
"karma-jasmine": "~0.2.0", |
||||
"karma-phantomjs-launcher": "^0.1.4", |
||||
"karma-spec-reporter": "0.0.13" |
||||
} |
||||
} |
||||
|
@ -0,0 +1,14 @@
|
||||
module.exports = function (config) { |
||||
config.set({ |
||||
basePath : '', |
||||
autoWatch : true, |
||||
frameworks: ['jasmine'], |
||||
browsers : ['PhantomJS'], |
||||
plugins : [ |
||||
'karma-spec-reporter', |
||||
'karma-phantomjs-launcher', |
||||
'karma-jasmine' |
||||
], |
||||
reporters : ['spec'] |
||||
}); |
||||
}; |
Loading…
Reference in new issue