diff --git a/code/portal_highlighter.js b/code/portal_highlighter.js index ba72f52e..bb2ee292 100644 --- a/code/portal_highlighter.js +++ b/code/portal_highlighter.js @@ -1,37 +1,49 @@ // Portal Highlighter ////////////////////////////////////////////////////////// // these functions handle portal highlighters - +// an object mapping highlighter names to the object containing callback functions window._highlighters = null; + +// the name of the current highlighter window._current_highlighter = localStorage.portal_highlighter; + window._no_highlighter = 'No Highlights'; -if(window._current_highlighter !== undefined) { - if (typeof android !== 'undefined' && android && android.setActiveHighlighter) - android.setActiveHighlighter(window._current_highlighter); -} - -window.addPortalHighlighter = function(name, callback) { +window.addPortalHighlighter = function(name, data) { if(_highlighters === null) { _highlighters = {}; } - _highlighters[name] = callback; + + // old-format highlighters just passed a callback function. this is the same as just a highlight method + if (!data.highlight) { + data = {highlight: data} + } + + _highlighters[name] = data; if (typeof android !== 'undefined' && android && android.addPortalHighlighter) android.addPortalHighlighter(name); - if(localStorage.portal_highlighter === undefined) { + if(window._current_highlighter === undefined) { _current_highlighter = name; + } + + if (_current_highlighter == name) { if (typeof android !== 'undefined' && android && android.setActiveHighlighter) android.setActiveHighlighter(name); - localStorage.portal_highlighter = name; + // call the setSelected callback + if (_highlighters[_current_highlighter].setSelected) { + _highlighters[_current_highlighter].setSelected(true); + } + } - portalHighlighterControl(); + updatePortalHighlighterControl(); } -window.portalHighlighterControl = function() { +// (re)creates the highlighter dropdown list +window.updatePortalHighlighterControl = function() { if (typeof android !== 'undefined' && android && android.addPortalHighlighter) { $('#portal_highlight_select').remove(); return; @@ -40,6 +52,9 @@ window.portalHighlighterControl = function() { if(_highlighters !== null) { if($('#portal_highlight_select').length === 0) { $("body").append(""); + $("#portal_highlight_select").change(function(){ changePortalHighlights($(this).val());}); + $(".leaflet-top.leaflet-left").css('padding-top', '20px'); + $(".leaflet-control-scale-line").css('margin-top','25px'); } $("#portal_highlight_select").html(''); $("#portal_highlight_select").append($("