notifications can be switched on/off in OSRM.config,

notifications can be localized
This commit is contained in:
shiin 2012-07-30 14:40:56 +02:00
parent 1f7a724ded
commit ecd342224e
8 changed files with 111 additions and 60 deletions

View File

@ -92,7 +92,13 @@ OSRM.DEFAULTS = {
}
],
MAINTENANCE: false,
MAINTENANCE_HEADER: "Scheduled Maintenance",
MAINTENANCE_TEXT: "The OSRM Website is down for a scheduled maintenance. Please be patient while required updates are performed. The site will be back online shortly.<br/><br/>In the meantime you may want to go out an map a friendly neighborhood near you...<br/><br/><br/>[OSRM]",
NOTIFICATIONS: {
LOCALIZATION: 1800000, // 30min
CLICKING: 60000, // 1min
DRAGGING: 120000, // 2min
MAINTENANCE: false
},
OVERRIDE_MAINTENANCE_HEADER: undefined,
OVERRIDE_MAINTENANCE_BODY: undefined
};

View File

@ -86,7 +86,7 @@ zoomed: function(e) {
contextmenu: function(e) {;},
mousemove: function(e) { OSRM.Via.drawDragMarker(e); },
click: function(e) {
OSRM.GUI.deactivateTooltip( "clicking" );
OSRM.GUI.deactivateTooltip( "CLICKING" );
if( !OSRM.G.markers.hasSource() ) {
var index = OSRM.G.markers.setSource( e.latlng );
OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );

View File

@ -99,7 +99,7 @@ onDrag: function(e) {
OSRM.Geocoder.updateLocation( this.parent.label );
},
onDragStart: function(e) {
OSRM.GUI.deactivateTooltip( "dragging" );
OSRM.GUI.deactivateTooltip( "DRAGGING" );
OSRM.G.dragging = true;
this.switchIcon(this.options.dragicon);

View File

@ -74,6 +74,7 @@ setLabels: function() {
document.getElementById("gui-units-toggle").getElementsByTagName("option")[0].innerHTML = OSRM.loc("GUI_KILOMETERS");
document.getElementById("gui-units-toggle").getElementsByTagName("option")[1].innerHTML = OSRM.loc("GUI_MILES");
OSRM.GUI.selectorOnChange( document.getElementById("gui-units-toggle") );
OSRM.GUI.updateNotifications();
},
// clear output area

View File

@ -22,51 +22,40 @@ or see http://www.gnu.org/licenses/agpl.txt.
OSRM.GUI.extend( {
// tooltips
tooltips: {
// triggered in OSRM.Localization.setLanguageWrapper
localization:
{ timeout: 1800000, // 30min
header: "Did you know? You can change the display language.",
body: "You can use the pulldown menu in the upper left corner to select your favorite language. " +
"<br/><br/>" +
"Don't despair if you cannot find your language of choice. " +
"If you want, you can help to provide additional translations! " +
"Visit <a href='https://github.com/DennisSchiefer/Project-OSRM-Web'>here</a> for more information."
},
// triggered in OSRM.Map.click
clicking:
{ timeout: 60000, // 1min
header: "Did you know? You can click on the map to set route markers.",
body: "You can click on the map with the left mouse button to set a source marker (green) or a target marker (red), " +
"if the source marker already exists. " +
"The address of the selected location will be displayed in the boxes to the left. " +
"<br/><br/>" +
"You can delete a marker by clicking on it again with the left mouse button."
},
// triggered in OSRM.Routing.getRoute_Dragging
dragging:
{ timeout: 120000, // 2min
header: "Did you know? You can drag each route marker on the map.",
body: "You can drag a marker by clicking on it with the left mouse button and holding the button pressed. " +
"Then you can move the marker around the map and the route will be updated instantaneously. " +
"<br/><br/>" +
"You can even create intermediate markers by dragging them off of the main route! "
}
},
activeExclusive: undefined,
activeTooltip: undefined,
tooltips: {},
// LOCALIZATION: deactivation triggered in OSRM.Localization.setLanguageWrapper
// CLICKING: deactivation triggered in OSRM.Map.click
// DRAGGING: deactivation triggered in OSRM.Routing.getRoute_Dragging
// MAINTENANCE: deactivation only by config
// initialize notifications and tooltip timers
init: function() {
// notifications
// [nothing to be done at the moment]
// exclusive notifications
var config = OSRM.DEFAULTS.NOTIFICATIONS;
if( config["MAINTENANCE"] == true ) {
var header = OSRM.DEFAULTS.OVERRIDE_MAINTENANCE_HEADER || OSRM.loc("NOTIFICATION_MAINTENANCE_HEADER");
var body = OSRM.DEFAULTS.OVERRIDE_MAINTENANCE_BODY || OSRM.loc("NOTIFICATION_MAINTENANCE_BODY");
OSRM.GUI.exclusiveNotify( header, body, false);
OSRM.GUI.activeExclusive = "MAINTENANCE";
return;
}
// tooltip timers
var config = OSRM.DEFAULTS.NOTIFICATIONS;
var tooltips = OSRM.GUI.tooltips;
for( id in tooltips ) {
for( id in config ) {
// skip notification?
if( !OSRM.Utils.isNumber( config[id] ) )
continue;
// create structure to hold timer data
tooltips[id] = {};
// start timer
tooltips[id]._timer = setTimeout(
function(_id){ return function(){OSRM.GUI._showTooltip(_id);}; }(id),
tooltips[id].timeout
config[id]
);
// mark tooltip as pending
@ -87,6 +76,7 @@ deactivateTooltip: function(id) {
// show tooltip after timer expired
_showTooltip: function(id) {
var tooltips = OSRM.GUI.tooltips;
// only show tooltip if it exists
if(tooltips[id] == undefined)
return;
@ -96,16 +86,18 @@ _showTooltip: function(id) {
}
// if a notification is currently shown, restart timer
var config = OSRM.DEFAULTS.NOTIFICATIONS;
if( OSRM.GUI.isTooltipVisible() ) {
tooltips[id]._timer = setTimeout(
function(_id){ return function(){OSRM.GUI._showTooltip(_id);}; }(id),
tooltips[id].timeout
config[id]
);
return;
}
// show notification
OSRM.GUI.tooltipNotify( tooltips[id].header, tooltips[id].body );
OSRM.GUI.tooltipNotify( OSRM.loc("NOTIFICATION_"+id+"_HEADER"), OSRM.loc("NOTIFICATION_"+id+"_BODY") );
OSRM.GUI.activeTooltip = id;
// mark tooltip as no longer pending
tooltips[id]._pending = false;
@ -121,11 +113,32 @@ exclusiveNotify: function( header, text, closable ){
document.getElementById('exclusive-notification-toggle').onclick = OSRM.GUI.exclusiveDenotify;
else
document.getElementById('exclusive-notification-toggle').style.display = "none";
OSRM.GUI.exclusiveResize();
},
exclusiveDenotify: function() {
document.getElementById('exclusive-notification-blanket').style.display = "none";
OSRM.GUI.activeExclusive = undefined;
},
exclusiveUpdate: function() {
if( OSRM.GUI.activeExclusive == undefined )
return;
// override mainly intended for maintenance mode
var header = OSRM.DEFAULTS["OVERRIDE_"+OSRM.GUI.activeExclusive+"_HEADER"] || OSRM.loc("NOTIFICATION_MAINTENANCE_HEADER");
var body = OSRM.DEFAULTS["OVERRIDE_"+OSRM.GUI.activeExclusive+"_BODY"] || OSRM.loc("NOTIFICATION_MAINTENANCE_BODY");
document.getElementById('exclusive-notification-label').innerHTML = header;
document.getElementById('exclusive-notification-box').innerHTML = body;
OSRM.GUI.exclusiveResize();
},
exclusiveResize: function() {
var height = document.getElementById('exclusive-notification-box').clientHeight;
document.getElementById('exclusive-notification-content').style.height = (height + 28) + "px";
document.getElementById('exclusive-notification-wrapper').style.height = (height + 48) + "px";
},
inMaintenance: function() {
return OSRM.GUI.activeExclusive == "MAINTENANCE";
},
// tooltip notification
tooltipNotify: function( header, text ){
@ -138,6 +151,18 @@ tooltipNotify: function( header, text ){
document.getElementById('tooltip-notification-toggle').onclick = OSRM.GUI.tooltipDenotify;
document.getElementById('tooltip-notification-resize').onclick = OSRM.GUI.tooltipResize;
},
tooltipDenotify: function() {
document.getElementById('tooltip-notification-wrapper').style.display = "none";
OSRM.GUI.activeTooltip = undefined;
},
tooltipUpdate: function() {
if( OSRM.GUI.activeTooltip == undefined )
return;
document.getElementById('tooltip-notification-label').innerHTML = OSRM.loc("NOTIFICATION_"+OSRM.GUI.activeTooltip+"_HEADER");
document.getElementById('tooltip-notification-box').innerHTML = OSRM.loc("NOTIFICATION_"+OSRM.GUI.activeTooltip+"_BODY");
OSRM.GUI.tooltipResize();
OSRM.GUI.tooltipResize(); // simple trick to retain opened/closed state of tooltip
},
tooltipResize: function() {
if( document.getElementById('tooltip-notification-box').style.display == "none" ) {
document.getElementById('tooltip-notification-box').style.display = "block";
@ -152,11 +177,15 @@ tooltipResize: function() {
document.getElementById('tooltip-notification-resize').className = "iconic-button down-marker top-right-button";
}
},
tooltipDenotify: function() {
document.getElementById('tooltip-notification-wrapper').style.display = "none";
},
isTooltipVisible: function() {
return document.getElementById('tooltip-notification-wrapper').style.display == "block";
},
// update language of any notification
updateNotifications: function() {
OSRM.GUI.exclusiveUpdate();
OSRM.GUI.tooltipUpdate();
}
});

View File

@ -98,7 +98,32 @@ OSRM.Localization["en"] = {
"DIRECTION_11-8":"Enter roundabout and leave at eighth exit[ onto <b>%s</b>]",
"DIRECTION_11-9":"Enter roundabout and leave at nineth exit[ onto <b>%s</b>]",
"DIRECTION_11-x":"Enter roundabout and leave at one of the too many exits[ onto <b>%s</b>]",
"DIRECTION_15":"You have reached your destination"
"DIRECTION_15":"You have reached your destination",
// notifications
"NOTIFICATION_MAINTENANCE_HEADER": "Scheduled Maintenance",
"NOTIFICATION_MAINTENANCE_BODY": "The OSRM Website is down for a scheduled maintenance. " +
"Please be patient while required updates are performed. " +
"The site will be back online shortly." +
"<br/><br/>" +
"In the meantime you may want to go out an map a friendly neighborhood near you..." +
"<br/><br/><br/>[OSRM]",
"NOTIFICATION_LOCALIZATION_HEADER": "Did you know? You can change the display language.",
"NOTIFICATION_LOCALIZATION_BODY": "You can use the pulldown menu in the upper left corner to select your favorite language. " +
"<br/><br/>" +
"Don't despair if you cannot find your language of choice. " +
"If you want, you can help to provide additional translations! " +
"Visit <a href='https://github.com/DennisSchiefer/Project-OSRM-Web'>here</a> for more information.",
"NOTIFICATION_CLICKING_HEADER": "Did you know? You can click on the map to set route markers.",
"NOTIFICATION_CLICKING_BODY": "You can click on the map with the left mouse button to set a source marker (green) or a target marker (red), " +
"if the source marker already exists. " +
"The address of the selected location will be displayed in the boxes to the left. " +
"<br/><br/>" +
"You can delete a marker by clicking on it again with the left mouse button.",
"NOTIFICATION_DRAGGING_HEADER": "Did you know? You can drag each route marker on the map.",
"NOTIFICATION_DRAGGING_BODY": "You can drag a marker by clicking on it with the left mouse button and holding the button pressed. " +
"Then you can move the marker around the map and the route will be updated instantaneously. " +
"<br/><br/>" +
"You can even create intermediate markers by dragging them off of the main route! "
};
// set GUI language on load

View File

@ -49,7 +49,7 @@ init: function() {
OSRM.Localization.setLanguage( OSRM.DEFAULTS.LANGUAGE );
},
setLanguageWrapper: function(language) { // wrapping required to correctly prevent localization tooltip from showing
OSRM.GUI.deactivateTooltip( "localization" );
OSRM.GUI.deactivateTooltip( "LOCALIZATION" );
OSRM.Localization.setLanguage(language);
},
setLanguage: function(language) {

View File

@ -33,7 +33,7 @@ OSRM.init = function() {
OSRM.Localization.init();
// stop if in maintenance mode
if( OSRM.inMaintenance() == true )
if( OSRM.GUI.inMaintenance() == true )
return;
// check if the URL contains some GET parameter, e.g. for showing a route
@ -291,15 +291,5 @@ OSRM.parseParameters = function(){
};
// check whether to activate maintenance mode
OSRM.inMaintenance = function(){
if( OSRM.DEFAULTS.MAINTENANCE == true ) {
OSRM.GUI.exclusiveNotify( OSRM.DEFAULTS.MAINTENANCE_HEADER, OSRM.DEFAULTS.MAINTENANCE_TEXT, false);
return true;
}
return false;
};
// onload event
OSRM.Browser.onLoadHandler( OSRM.init );