From 4db744e186d8faab1bc95018b9dad73633c46ef5 Mon Sep 17 00:00:00 2001 From: i-like-robots Date: Mon, 6 Jan 2014 12:25:04 +0000 Subject: [PATCH] Wrap constructor in universal module definition --- .jshintrc | 6 ++- dist/echo.js | 111 +++++++++++++++++++++++++++-------------------- dist/echo.min.js | 4 +- src/echo.js | 109 +++++++++++++++++++++++++++------------------- 4 files changed, 136 insertions(+), 94 deletions(-) diff --git a/.jshintrc b/.jshintrc index 1d35ce1..2faac19 100644 --- a/.jshintrc +++ b/.jshintrc @@ -17,5 +17,9 @@ "unused": true, "strict": true, "trailing": true, - "smarttabs": true + "smarttabs": true, + "globals": { + "define": false, + "module": false + } } diff --git a/dist/echo.js b/dist/echo.js index d33b5ed..d62ea86 100644 --- a/dist/echo.js +++ b/dist/echo.js @@ -1,52 +1,71 @@ -/*! Echo v1.4.0 | (c) 2013 @toddmotto | MIT license | github.com/toddmotto/echo */ -window.Echo = (function (window, document, undefined) { +/*! Echo v1.4.0 | (c) 2014 @toddmotto | MIT license | github.com/toddmotto/echo */ +(function (name, context, definition) { 'use strict'; - var store = [], offset, throttle, poll; + if (typeof define === 'function' && define.amd) { + define(definition); + } + else if (typeof module !== 'undefined' && module.exports) { + module.exports = definition(); + } + else { + context[name] = definition(); + } +})('Echo', this, function() { - var _inView = function (el) { - var coords = el.getBoundingClientRect(); - return ((coords.top >= 0 && coords.left >= 0 && coords.top) <= (window.innerHeight || document.documentElement.clientHeight) + parseInt(offset)); - }; + 'use strict'; + + function Echo() { + + var store = [], offset, throttle, poll; + + var _inView = function (el) { + var coords = el.getBoundingClientRect(); + return ((coords.top >= 0 && coords.left >= 0 && coords.top) <= (window.innerHeight || document.documentElement.clientHeight) + parseInt(offset)); + }; + + var _pollImages = function () { + for (var i = store.length; i--;) { + var self = store[i]; + if (_inView(self)) { + self.src = self.getAttribute('data-echo'); + store.splice(i, 1); + } + } + }; + + var _throttle = function () { + clearTimeout(poll); + poll = setTimeout(_pollImages, throttle); + }; + + var init = function (obj) { + var nodes = document.querySelectorAll('[data-echo]'); + var opts = obj || {}; + offset = opts.offset || 0; + throttle = opts.throttle || 250; - var _pollImages = function () { - for (var i = store.length; i--;) { - var self = store[i]; - if (_inView(self)) { - self.src = self.getAttribute('data-echo'); - store.splice(i, 1); + for (var i = 0; i < nodes.length; i++) { + store.push(nodes[i]); } - } - }; - - var _throttle = function () { - clearTimeout(poll); - poll = setTimeout(_pollImages, throttle); - }; - - var init = function (obj) { - var nodes = document.querySelectorAll('[data-echo]'); - var opts = obj || {}; - offset = opts.offset || 0; - throttle = opts.throttle || 250; - - for (var i = 0; i < nodes.length; i++) { - store.push(nodes[i]); - } - - _throttle(); - - if (document.addEventListener) { - window.addEventListener('scroll', _throttle, false); - } else { - window.attachEvent('onscroll', _throttle); - } - }; - - return { - init: init, - render: _throttle - }; - -})(window, document); + + _throttle(); + + if (document.addEventListener) { + window.addEventListener('scroll', _throttle, false); + } else { + window.attachEvent('onscroll', _throttle); + } + }; + + return { + init: init, + render: _throttle + }; + + } + + return Echo; + +}); diff --git a/dist/echo.min.js b/dist/echo.min.js index 4dfeda4..01e8bc7 100644 --- a/dist/echo.min.js +++ b/dist/echo.min.js @@ -1,2 +1,2 @@ -/*! Echo v1.4.0 | (c) 2013 @toddmotto | MIT license | github.com/toddmotto/echo */ -window.Echo=function(a,b){"use strict";var c,d,e,f=[],g=function(d){var e=d.getBoundingClientRect();return(e.top>=0&&e.left>=0&&e.top)<=(a.innerHeight||b.documentElement.clientHeight)+parseInt(c)},h=function(){for(var a=f.length;a--;){var b=f[a];g(b)&&(b.src=b.getAttribute("data-echo"),f.splice(a,1))}},i=function(){clearTimeout(e),e=setTimeout(h,d)},j=function(e){var g=b.querySelectorAll("[data-echo]"),h=e||{};c=h.offset||0,d=h.throttle||250;for(var j=0;j=0&&c.left>=0&&c.top)<=(window.innerHeight||document.documentElement.clientHeight)+parseInt(a)},f=function(){for(var a=d.length;a--;){var b=d[a];e(b)&&(b.src=b.getAttribute("data-echo"),d.splice(a,1))}},g=function(){clearTimeout(c),c=setTimeout(f,b)},h=function(c){var e=document.querySelectorAll("[data-echo]"),f=c||{};a=f.offset||0,b=f.throttle||250;for(var h=0;h= 0 && coords.left >= 0 && coords.top) <= (window.innerHeight || document.documentElement.clientHeight) + parseInt(offset)); - }; + 'use strict'; + + function Echo() { + + var store = [], offset, throttle, poll; + + var _inView = function (el) { + var coords = el.getBoundingClientRect(); + return ((coords.top >= 0 && coords.left >= 0 && coords.top) <= (window.innerHeight || document.documentElement.clientHeight) + parseInt(offset)); + }; + + var _pollImages = function () { + for (var i = store.length; i--;) { + var self = store[i]; + if (_inView(self)) { + self.src = self.getAttribute('data-echo'); + store.splice(i, 1); + } + } + }; + + var _throttle = function () { + clearTimeout(poll); + poll = setTimeout(_pollImages, throttle); + }; + + var init = function (obj) { + var nodes = document.querySelectorAll('[data-echo]'); + var opts = obj || {}; + offset = opts.offset || 0; + throttle = opts.throttle || 250; - var _pollImages = function () { - for (var i = store.length; i--;) { - var self = store[i]; - if (_inView(self)) { - self.src = self.getAttribute('data-echo'); - store.splice(i, 1); + for (var i = 0; i < nodes.length; i++) { + store.push(nodes[i]); } - } - }; - - var _throttle = function () { - clearTimeout(poll); - poll = setTimeout(_pollImages, throttle); - }; - - var init = function (obj) { - var nodes = document.querySelectorAll('[data-echo]'); - var opts = obj || {}; - offset = opts.offset || 0; - throttle = opts.throttle || 250; - - for (var i = 0; i < nodes.length; i++) { - store.push(nodes[i]); - } - - _throttle(); - - if (document.addEventListener) { - window.addEventListener('scroll', _throttle, false); - } else { - window.attachEvent('onscroll', _throttle); - } - }; - - return { - init: init, - render: _throttle - }; - -})(window, document); + + _throttle(); + + if (document.addEventListener) { + window.addEventListener('scroll', _throttle, false); + } else { + window.attachEvent('onscroll', _throttle); + } + }; + + return { + init: init, + render: _throttle + }; + + } + + return Echo; + +});