Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1st off, i mainly work with single page applications.</p> <p>This is how i usually operate:</p> <pre><code>// Main module ;(function($, win, undefined) { var module = { _currentPanel, initialize: function() { // all my global bindings here }, // Only included to understand whats going on in the sub-module below displayPanel: function(panelName) { if (!!module._currentPanel) { $(module._currentPanel) .hide(0) .triggerHandler('hide.panel'); } module._currentPanel = panelName; $(panelName) .show(0) .triggerHandler('show.panel'); }, }; $.extend("namespace", module); })(jQuery, window); // Sub modules ;(function($, win, undefined) { var module = { something: function() { // ..nothing to see here, this is just how i construct my modules } }; // Event bindings specific to this module $('#geo-panel').bind('show.panel', function() { // wire up init() stuff }); $('#geo-panel').bind('hide.panel', function() { // wire up dispose() stuff }); $.extend("namespace", module); })(jQuery, window); </code></pre> <p>So whats going on there ?</p> <p>My main module holds all the global stuff ..that was logical :) With a initialize() function that i call somewhere when i load the page. This hooks up all my generic bindings/selectors that are useful on all pages (or views in this case).</p> <p>Then my sub-modules hold bindings to events that i trigger when i display the various pseudo-pages in my application. They all react to .triggerHandler() which i use quite a bit to be able to separate my logic throughout the site.</p> <p>displayPanel("#geo-panel");</p> <p>displayPanel("#someother-panel");</p> <p>Both the main module &amp; the sub-modules are then aggregate into a big js file. There's some redundant $.extend() going on here (i use it to create namespaces on the fly), and it allows me to split everything into specialized sub-module (preferences, profile, search, ..) that get automatically built/aggregated on application build.</p> <p>However if i wasn't using a single page application, then i would either:</p> <ol> <li>just change all the references from <code>#panel-geo</code>, to something more like <code>#pageX #panel-geo</code></li> <li>or go for 1 common js for all pages, and 1 specific js for each page</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload