Module referenceΒΆ

Individual Map Center pages often make use of additional functionality that isn’t included in the core nhmc package; without such additional functionality, all that would appear is a blank map! The Map Center implements these extras in the form of “modules”, which are simply JavaScript functions that are executed when the coreInitialized signal fires.

The general organization of a module consists of:

  • Declaring which core packages are in use by calling the namespace function.

  • Defining an handler for the coreInitialized signal. This signal should only fire once, but existing modules tend to bind to it using $(document).one() for additional safety.

    The body of that handler generally includes:

    • Any module-specific data to display or global-ish (within the scope of the handler) objects for intermediate storage of the module’s state.
    • Configuration options.
    • Utility functions to handle different calculation or rendering tasks that will be needed.
    • Binding of UI event handlers.
    • Initialization of the module.

A simple stub module might look something like this:

$(document).one('coreInitialized', function() {
    // Module body goes here.


Project Versions

Previous topic

Signal reference

Next topic

Electoral College results and calculator

This Page