Created
August 15, 2013 01:14
-
-
Save kitwalker12/6237406 to your computer and use it in GitHub Desktop.
Clean way of making jQuery Initializers
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
// handle window.console if console.log isn't available. Define an empty function here | |
function emptyFunction() { } | |
if (window.console === undefined) { | |
window.console = { | |
log: emptyFunction, | |
error: emptyFunction, | |
info: emptyFunction, | |
trace: emptyFunction | |
}; | |
} | |
// init namespace | |
window.app = {}; | |
window.app.myapp = {}; | |
//Following code can be put in other JS files which are included in the tree | |
(function ($, app) { | |
var $window = $(window), $nav = $('#nav'); | |
app.home = { | |
fit: function() { | |
//Code to fit stuff on resize | |
}, | |
nav: function() { | |
//Code for Nav features | |
} | |
}; | |
if($('body#home').length > 0) { | |
app.home.fit(); | |
$(window).on('resize', app.home.fit); | |
$(document).ready(app.home.fit); | |
$(document).ready(app.home.nav); | |
} | |
$(document).ready(function() { | |
//Other Initializers for plugins | |
}); | |
}(jQuery, app.myapp)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment