portal highlighter system
- add an alternative API that includes a setSelected callback, so highlighters know when they're turned on/off - fix bug where highlighters were selected multiple times - a few other cleanups
This commit is contained in:
parent
be5f365ff6
commit
7fc13f0c9e
@ -1,37 +1,49 @@
|
|||||||
// Portal Highlighter //////////////////////////////////////////////////////////
|
// Portal Highlighter //////////////////////////////////////////////////////////
|
||||||
// these functions handle portal highlighters
|
// these functions handle portal highlighters
|
||||||
|
|
||||||
|
// an object mapping highlighter names to the object containing callback functions
|
||||||
window._highlighters = null;
|
window._highlighters = null;
|
||||||
|
|
||||||
|
// the name of the current highlighter
|
||||||
window._current_highlighter = localStorage.portal_highlighter;
|
window._current_highlighter = localStorage.portal_highlighter;
|
||||||
|
|
||||||
window._no_highlighter = 'No Highlights';
|
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, data) {
|
||||||
window.addPortalHighlighter = function(name, callback) {
|
|
||||||
if(_highlighters === null) {
|
if(_highlighters === null) {
|
||||||
_highlighters = {};
|
_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)
|
if (typeof android !== 'undefined' && android && android.addPortalHighlighter)
|
||||||
android.addPortalHighlighter(name);
|
android.addPortalHighlighter(name);
|
||||||
|
|
||||||
if(localStorage.portal_highlighter === undefined) {
|
if(window._current_highlighter === undefined) {
|
||||||
_current_highlighter = name;
|
_current_highlighter = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_current_highlighter == name) {
|
||||||
if (typeof android !== 'undefined' && android && android.setActiveHighlighter)
|
if (typeof android !== 'undefined' && android && android.setActiveHighlighter)
|
||||||
android.setActiveHighlighter(name);
|
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) {
|
if (typeof android !== 'undefined' && android && android.addPortalHighlighter) {
|
||||||
$('#portal_highlight_select').remove();
|
$('#portal_highlight_select').remove();
|
||||||
return;
|
return;
|
||||||
@ -40,6 +52,9 @@ window.portalHighlighterControl = function() {
|
|||||||
if(_highlighters !== null) {
|
if(_highlighters !== null) {
|
||||||
if($('#portal_highlight_select').length === 0) {
|
if($('#portal_highlight_select').length === 0) {
|
||||||
$("body").append("<select id='portal_highlight_select'></select>");
|
$("body").append("<select id='portal_highlight_select'></select>");
|
||||||
|
$("#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").html('');
|
||||||
$("#portal_highlight_select").append($("<option>").attr('value',_no_highlighter).text(_no_highlighter));
|
$("#portal_highlight_select").append($("<option>").attr('value',_no_highlighter).text(_no_highlighter));
|
||||||
@ -48,17 +63,27 @@ window.portalHighlighterControl = function() {
|
|||||||
$.each(h_names, function(i, name) {
|
$.each(h_names, function(i, name) {
|
||||||
$("#portal_highlight_select").append($("<option>").attr('value',name).text(name));
|
$("#portal_highlight_select").append($("<option>").attr('value',name).text(name));
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#portal_highlight_select").val(_current_highlighter);
|
$("#portal_highlight_select").val(_current_highlighter);
|
||||||
$("#portal_highlight_select").change(function(){ changePortalHighlights($(this).val());});
|
|
||||||
$(".leaflet-top.leaflet-left").css('padding-top', '20px');
|
|
||||||
$(".leaflet-control-scale-line").css('margin-top','25px');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.changePortalHighlights = function(name) {
|
window.changePortalHighlights = function(name) {
|
||||||
|
|
||||||
|
// first call any previous highlighter select callback
|
||||||
|
if (_current_highlighter && _highlighters[_current_highlighter] && _highlighters[_current_highlighter].setSelected) {
|
||||||
|
_highlighters[_current_highlighter].setSelected(false);
|
||||||
|
}
|
||||||
|
|
||||||
_current_highlighter = name;
|
_current_highlighter = name;
|
||||||
if (typeof android !== 'undefined' && android && android.setActiveHighlighter)
|
if (typeof android !== 'undefined' && android && android.setActiveHighlighter)
|
||||||
android.setActiveHighlighter(name);
|
android.setActiveHighlighter(name);
|
||||||
|
|
||||||
|
// now call the setSelected callback for the new highlighter
|
||||||
|
if (_current_highlighter && _highlighters[_current_highlighter] && _highlighters[_current_highlighter].setSelected) {
|
||||||
|
_highlighters[_current_highlighter].setSelected(true);
|
||||||
|
}
|
||||||
|
|
||||||
resetHighlightedPortals();
|
resetHighlightedPortals();
|
||||||
localStorage.portal_highlighter = name;
|
localStorage.portal_highlighter = name;
|
||||||
}
|
}
|
||||||
@ -66,7 +91,7 @@ window.changePortalHighlights = function(name) {
|
|||||||
window.highlightPortal = function(p) {
|
window.highlightPortal = function(p) {
|
||||||
|
|
||||||
if(_highlighters !== null && _highlighters[_current_highlighter] !== undefined) {
|
if(_highlighters !== null && _highlighters[_current_highlighter] !== undefined) {
|
||||||
_highlighters[_current_highlighter]({portal: p});
|
_highlighters[_current_highlighter].highlight({portal: p});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user