Created
June 15, 2015 00:42
-
-
Save cristianobecker/b76e42115004469dee0c to your computer and use it in GitHub Desktop.
Main.js file when using jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global jQuery */ | |
/*jslint browser: true */ | |
(function (win, $) { | |
'use strict'; | |
// helpers | |
var Util, Globals; | |
Util = { | |
safeEvent: function (callback) { | |
var a = false; | |
return function () { | |
var args = arguments; | |
if (!a) { | |
a = true; | |
win.requestAnimationFrame(function () { | |
callback.apply(null, args); | |
a = false; | |
}); | |
} | |
}; | |
}, | |
timeoutEvent: function (timeout, callback) { | |
var interval = null; | |
return function () { | |
var args = arguments; | |
clearTimeout(interval); | |
setTimeout(function () { | |
callback.apply(null, args); | |
}, timeout); | |
}; | |
} | |
}; | |
Globals = { | |
$win: $(win), | |
$body: $('body'), | |
$html: $('html') | |
}; | |
// events | |
Globals.$win.on('scroll', Util.safeEvent(function () { | |
Globals.$win.trigger('safescroll', { | |
top: Globals.$win.scrollTop(), | |
viewport: Globals.$win.height(), | |
height: Globals.$html.height() | |
}); | |
})); | |
// configuration | |
win.Util = Util; | |
win.Globals = Globals; | |
}(window, jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment