Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Initializing the Application Now that we have the individual pages in place, we can start thinking about filling them in with data. It's useful to wrap application initialization in a jQuery plug-in that ini- tializes each page in a different method. Here's the basic pattern, applied to jqmTweet: (function($) { var methods = { initMainPage : function() { }, initDetailPage : function() { }, initSettingsPage : function() { }, initAll : function() { $().initApp("initMainPage"); $().initApp("initDetailPage"); $().initApp("initSettingsPage"); } } $.fn.initApp = function(method) { // Method calling logic if ( methods[method] ) { return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); } else if ( typeof method === 'object' || ! method ) { return methods.initAll.apply( this, arguments ); } else { $.error( 'Method ' + method + ' does not exist' ); } } })(jQuery); Then on document ready we can just call the new jQuery.initApp() function and everything will be initialized. This is almost a straight up copy-and-paste of the jQuery plug-in pattern. I've left out the options since we don't need them, and I've altered method calling logic so that initAll is the default method for the plug-in, but otherwise it's the same. The jQuery plug-in pattern is very useful; if you don't already know about it, you can read more on the jQuery documentation site at http://docs.jquery.com/Plugins/Authoring. The initMainPage Method We'll start with the main page. The main page needs to display the Twitter feed when the app first loads, and it needs to refresh the feed if the user changes something on the Initializing the Application | 97