Created
April 9, 2011 15:52
-
-
Save brentertz/911494 to your computer and use it in GitHub Desktop.
Simple JS setup
This file contains 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
var App = App || {}; | |
App = { | |
/** | |
* Default configuration settings. | |
* | |
* Examples of how to override defaults | |
* App.defaults.message = 'Foo bar'; | |
* App.init({'message': 'Bas bat'}); | |
* Note that the original "App.defaults" will always remain available. | |
* App.settings will contain the modified configuration | |
*/ | |
defaults: { | |
message: 'Hello App!', | |
}, | |
/** | |
* Primary initialization function | |
*/ | |
init: function(options) { | |
// Allow overriding defaults, without overwriting them | |
App.settings = $.extend(true, {}, App.defaults, options); | |
App.setup(); | |
}, | |
/** | |
* Perform any setup to get page ready | |
*/ | |
setup: function() { | |
App.initAjax(); | |
}, | |
/** | |
* Ajax Event Handlers | |
* @see http://docs.jquery.com/Ajax_Events | |
*/ | |
initAjax: function() { | |
$('html, body') | |
.ajaxStart(function() { | |
App.showBusyCursor(this); | |
}) | |
.ajaxStop(function() { | |
App.hideBusyCursor(this); | |
}) | |
.ajaxError(function() { | |
App.hideBusyCursor(this); | |
}); | |
}, | |
/** | |
* Show busy cursor for a given element | |
*/ | |
showBusyCursor: function(el) { | |
$(el).css('cursor','wait'); | |
}, | |
/** | |
* Hide busy cursor for a given element | |
*/ | |
hideBusyCursor: function(el) { | |
$(el).css('cursor','auto'); | |
} | |
}; | |
window.App = App; | |
$(document).ready(App.init); | |
---------------------------------------------------- | |
var App = window.App || App || {}; | |
App.home = App.home || {}; | |
App.home.Index = { | |
/** | |
* Default configuration settings | |
*/ | |
defaults: {}, | |
/** | |
* Primary initialization function | |
*/ | |
init: function(options) { | |
// Allow overriding defaults, without overwriting them | |
App.home.Index.settings = $.extend(true, {}, App.home.Index.defaults, options); | |
App.home.Index.setup(); | |
}, | |
/** | |
* Perform any setup to get page ready | |
*/ | |
setup: function() { | |
console.log('App.home.Index'); | |
} | |
}; | |
window.App = App; | |
$(document).ready(App.home.Index.init); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment