.. _nhmc.cleanup: ############ nhmc.cleanup ############ This package contains a variety of utility functions that remove application elements when they're no longer needed. It also contains a few objects that store references to these elements so that the cleanup functions know what they're looking for. *********************** General-purpose garbage *********************** .. _nhmc.cleanup.futureGarbage: nhmc.cleanup.futureGarbage ========================== *Array* This is a standard JavaScript array that holds jQuery objects that might need removal later. It's meant for use with the convenience function :ref:`nhmc.cleanup.clearGarbage`, which just calls ``.remove()`` on all elements of this array. .. _nhmc.cleanup.clearGarbage: nhmc.cleanup.clearGarbage ========================= *Function* ``nhmc.cleanup.clearGarbage()`` This calls ``.remove()`` on all elements of :ref:`nhmc.cleanup.futureGarbage`, which should be jQuery objects referring to elements on the page. ************ Map graphics ************ .. _nhmc.cleanup.clearPathColors: nhmc.cleanup.clearPathColors ============================ *Function* ``nhmc.cleanup.clearPathColors()`` This function simply clears the color of every state and county path drawn on the map; more specifically, it sets the fill color of each of those paths to :ref:`nhmc.config.defaultAttributes.fill `. ************ Dialog boxes ************ .. _nhmc.cleanup.activeDialogs: nhmc.cleanup.activeDialogs ========================== *Array* Sometimes the Map Center interface makes use of `jQuery UI dialog boxes`_ to request or present additional information; for example, the :ref:`Electoral College calculator ` uses them to allow users to split certain states' electoral votes where that is possible. ``nhmc.cleanup.activeDialogs`` is a standard JavaScript array that stores jQuery objects referring to these dialog boxes for easy reference later--primarily by :ref:`nhmc.cleanup.closeDialogs`. .. _jQuery UI dialog boxes: http://jqueryui.com/demos/dialog/ .. _nhmc.cleanup.closeDialogs: nhmc.cleanup.closeDialogs ========================= *Function* ``nhmc.cleanup.closeDialogs()`` This function just closes any dialogs stored in :ref:`nhmc.cleanup.activeDialogs` by calling ``.dialog("close")`` on each object therein. ************** Event handlers ************** .. _nhmc.cleanup.clickHandlerTokens: nhmc.cleanup.clickHandlerTokens =============================== *Array* This is a standard JavaScript array that contains zero or more handles returned by `dojo.connect`_. Dojo's event handling for graphics objects (and other items in general, but we only use it for graphics objects) is powerful in that it doesn't require DOM elements to exist as in jQuery--but it introduces a bit more complexity in that binding an event handler returns a handle that must be passed later to `dojo.disconnect`_ in order to unbind that handler. .. _dojo.connect: http://dojotoolkit.org/reference-guide/1.6/dojo/connect.html .. _dojo.disconnect: http://dojotoolkit.org/reference-guide/1.6/dojo/disconnect.html This array specifically is meant to hold handles related to event handlers for click events on map areas. An example of its use from the :ref:`Electoral College calculator `: .. code-block:: javascript var eventToken = nhmc.geo.usGeo['Nebraska'].statePath.connect( 'onclick', nhmc.geo.usGeo['Nebraska'].statePath, nebraskaHandler ); nhmc.cleanup.clickHandlerTokens.push(eventToken); This is done to make it easier to unbind all such handlers at once when needed by using `nhmc.cleanup.clearClickHandlers`_, described below. .. _nhmc.cleanup.clearClickHandlers: nhmc.cleanup.clearClickHandlers =============================== *Function* ``nhmc.cleanup.clearClickHandlers()`` This function simply goes through all handles stored in `nhmc.cleanup.clickHandlerTokens`_ and passes them to `dojo.disconnect`_. It's a handy way to unbind all click handlers at the same time when needed. .. _dojo.disconnect: http://dojotoolkit.org/reference-guide/1.6/dojo/disconnect.html ****** Charts ****** .. _nhmc.cleanup.clearCharts: nhmc.cleanup.clearCharts ======================== *Function* ``nhmc.cleanup.clearCharts()`` This function checks for the existence of the chart objects described in :ref:`nhmc.charts`; if any of those objects are found, they are destroyed using the Highcharts `Chart.destroy`_ method. .. _Chart.destroy: http://www.highcharts.com/ref/#chart-object ********** Everything ********** .. _nhmc.cleanup.clearMap: nhmc.cleanup.clearMap ===================== *Function* ``nhmc.cleanup.clearMap()`` This calls all of the above cleanup functions and removes all tooltips using :ref:`nhmc.tooltips.destroy` and :ref:`nhmc.tooltips.unbindHover`. It's a nuclear option for getting everything you can off of the map.