From 8f6cd99ff676ab026c35516da7f98f0448dfec2c Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Thu, 5 Jul 2012 13:53:07 +0100 Subject: [PATCH] changed notification triggers from wrapped functions to simple function calls --- WebContent/base/OSRM.Map.js | 1 + WebContent/base/osrm/OSRM.Marker.js | 1 + WebContent/gui/OSRM.Notifications.js | 162 +++++++++++++++++++ WebContent/gui/OSRM.Timers.js | 102 ------------ WebContent/localization/OSRM.Localization.js | 5 +- WebContent/main.css | 10 +- WebContent/main.html | 30 ++-- WebContent/main.js | 50 +----- 8 files changed, 188 insertions(+), 173 deletions(-) create mode 100644 WebContent/gui/OSRM.Notifications.js delete mode 100644 WebContent/gui/OSRM.Timers.js diff --git a/WebContent/base/OSRM.Map.js b/WebContent/base/OSRM.Map.js index 6a298fc04..b53ffd89c 100644 --- a/WebContent/base/OSRM.Map.js +++ b/WebContent/base/OSRM.Map.js @@ -86,6 +86,7 @@ zoomed: function(e) { contextmenu: function(e) {;}, mousemove: function(e) { OSRM.Via.drawDragMarker(e); }, click: function(e) { + 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 ); diff --git a/WebContent/base/osrm/OSRM.Marker.js b/WebContent/base/osrm/OSRM.Marker.js index 7b6d402e7..aa7560330 100644 --- a/WebContent/base/osrm/OSRM.Marker.js +++ b/WebContent/base/osrm/OSRM.Marker.js @@ -99,6 +99,7 @@ onDrag: function(e) { OSRM.Geocoder.updateLocation( this.parent.label ); }, onDragStart: function(e) { + OSRM.GUI.deactivateTooltip( "dragging" ); OSRM.G.dragging = true; this.switchIcon(this.options.dragicon); diff --git a/WebContent/gui/OSRM.Notifications.js b/WebContent/gui/OSRM.Notifications.js new file mode 100644 index 000000000..e9098651d --- /dev/null +++ b/WebContent/gui/OSRM.Notifications.js @@ -0,0 +1,162 @@ +/* +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. +*/ + +// OSRM Notifications +// [handles notifications: timed tooltips and exclusive notifications] + + +OSRM.GUI.extend( { + +// tooltips +tooltips: { + localization: + { timeout: 4000, + header: "[Tooltip] Localization", + body: "You can use the pulldown menu in the upper left corner to select your favorite language. " + + "

" + + "Don't despair if you cannot find your language of choice. " + + "If you want, you can help to provide additional translations! " + + "Visit here for more information." + // triggered by OSRM.Localization.setLanguageWrapper + }, + clicking: + { timeout: 6000, + header: "[Tooltip] Clicking to set 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. " + + "

" + + "You can delete a marker by clicking on it again with the left mouse button." + // triggered by OSRM.Map.click + }, + dragging: + { timeout: 8000, + header: "[Tooltip] Dragging markers", + 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. " + + "

" + + "You can even create additional markers by dragging them off of the main route! " + // triggered by OSRM.Routing.getRoute_Dragging + } +}, + + +// initialize notifications and tooltip timers +init: function() { + // notifications + // [nothing to be done at the moment] + + // tooltip timers + var tooltips = OSRM.GUI.tooltips; + for( id in tooltips ) { + // start timer + tooltips[id]._timer = setTimeout( + function(_id){ return function(){OSRM.GUI._showTooltip(_id);}; }(id), + tooltips[id].timeout + ); + + // mark tooltip as pending + tooltips[id]._pending = true; + } +}, + + +// deactivate pending tooltip +deactivateTooltip: function(id) { + var tooltips = OSRM.GUI.tooltips; + if(tooltips[id] == undefined) + return; + + // mark tooltip as no longer pending + tooltips[id]._pending = false; +}, +// show tooltip after timer expired +_showTooltip: function(id) { + var tooltips = OSRM.GUI.tooltips; + if(tooltips[id] == undefined) + return; + + // only show tooltip if it is still pending + if( tooltips[id]._pending == false ) { + return; + } + + // if a notification is currently shown, restart timer + if( OSRM.GUI.isTooltipVisible() ) { + tooltips[id]._timer = setTimeout( + function(_id){ return function(){OSRM.GUI._showTooltip(_id);}; }(id), + tooltips[id].timeout + ); + return; + } + + // show notification + OSRM.GUI.tooltipNotify( tooltips[id].header, tooltips[id].body ); + + // mark tooltip as no longer pending + tooltips[id]._pending = false; +}, + + +// exclusive notification +exclusiveNotify: function( header, text, closable ){ + document.getElementById('exclusive-notification-blanket').style.display = "block"; + document.getElementById('exclusive-notification-label').innerHTML = header; + document.getElementById('exclusive-notification-box').innerHTML = text; + if( closable ) + document.getElementById('exclusive-notification-toggle').onclick = OSRM.GUI.exclusiveDenotify; + else + document.getElementById('exclusive-notification-toggle').style.display = "none"; +}, +exclusiveDenotify: function() { + document.getElementById('exclusive-notification-blanket').style.display = "none"; +}, + + +// tooltip notification +tooltipNotify: function( header, text ){ + document.getElementById('tooltip-notification-wrapper').style.display = "block"; + document.getElementById('tooltip-notification-label').innerHTML = header; + document.getElementById('tooltip-notification-box').innerHTML = text; + document.getElementById('tooltip-notification-box').style.display = "block"; // simple trick to always start with a minimized tooltip + OSRM.GUI.tooltipResize(); + + document.getElementById('tooltip-notification-toggle').onclick = OSRM.GUI.tooltipDenotify; + document.getElementById('tooltip-notification-resize').onclick = OSRM.GUI.tooltipResize; +}, +tooltipResize: function() { + if( document.getElementById('tooltip-notification-box').style.display == "none" ) { + document.getElementById('tooltip-notification-box').style.display = "block"; + var height = document.getElementById('tooltip-notification-box').clientHeight; + document.getElementById('tooltip-notification-content').style.height = (height + 28) + "px"; + document.getElementById('tooltip-notification-wrapper').style.height = (height + 48) + "px"; + document.getElementById('tooltip-notification-resize').className = "iconic-button up-marker top-right-button"; + } else { + document.getElementById('tooltip-notification-box').style.display = "none"; + document.getElementById('tooltip-notification-content').style.height = "18px"; + document.getElementById('tooltip-notification-wrapper').style.height = "38px"; + 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"; +} + +}); diff --git a/WebContent/gui/OSRM.Timers.js b/WebContent/gui/OSRM.Timers.js deleted file mode 100644 index 9f5d87c8e..000000000 --- a/WebContent/gui/OSRM.Timers.js +++ /dev/null @@ -1,102 +0,0 @@ -/* -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU AFFERO General Public License as published by -the Free Software Foundation; either version 3 of the License, or -any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -or see http://www.gnu.org/licenses/agpl.txt. -*/ - -// OSRM Timers -// [handles notification timers] - - -OSRM.GUI.extend( { - -// notifications -notifications: [ - { time: 4000, - header: "[Tooltip] Localization", - body: "You can use the pulldown menu in the upper left corner to select your favorite language. " + - "

" + - "Don't despair if you cannot find your language of choice. " + - "If you want, you can help to provide additional translations! " + - "Visit here for more information.", - _classes: ["Localization"], - _funcs: ["setLanguageWrapper"] - }, - { time: 6000, - header: "[Tooltip] Clicking to set 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. " + - "

" + - "You can delete a marker by clicking on it again with the left mouse button.", - _classes: ["Map"], - _funcs: ["click"] - }, - { time: 8000, - header: "[Tooltip] Dragging markers", - 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. " + - "

" + - "You can even create additional markers by dragging them off of the main route! ", - _classes: ["Routing"], - _funcs: ["getRoute_Dragging"] - } -], - -// initialize notification timers -init: function() { - // init timers - var notifications = OSRM.GUI.notifications; - OSRM.G.notification_timers = new Array( notifications.length ); - for( var i=0, iEnd=notifications.length; i - + @@ -87,31 +87,31 @@ or see http://www.gnu.org/licenses/agpl.txt.
- -
-
-
+ +
+
+
-
-
Notification
+
+
Notification
-
+
- -
-
+ +
+
-
+
-
-
Notification
+
+
Notification
-
+
diff --git a/WebContent/main.js b/WebContent/main.js index 4c757b664..d9af675d2 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -284,60 +284,12 @@ OSRM.parseParameters = function(){ // check whether to activate maintenance mode OSRM.inMaintenance = function(){ if( OSRM.DEFAULTS.MAINTENANCE == true ) { - OSRM.xnotify( OSRM.DEFAULTS.MAINTENANCE_HEADER, OSRM.DEFAULTS.MAINTENANCE_TEXT, false); + OSRM.GUI.exclusiveNotify( OSRM.DEFAULTS.MAINTENANCE_HEADER, OSRM.DEFAULTS.MAINTENANCE_TEXT, false); return true; } return false; }; -// important notifications -OSRM.xnotify = function( header, text, closable ){ - document.getElementById('important-notification-blanket').style.display = "block"; - document.getElementById('important-notification-label').innerHTML = header; - document.getElementById('important-notification-box').innerHTML = text; - if( closable ) - document.getElementById('important-notification-toggle').onclick = OSRM.xdenotify; - else - document.getElementById('important-notification-toggle').style.display = "none"; -}; -OSRM.xdenotify = function() { - document.getElementById('important-notification-blanket').style.display = "none"; -}; - - -// normal notification box -OSRM.notify = function( header, text ){ - document.getElementById('notification-wrapper').style.display = "block"; - document.getElementById('notification-label').innerHTML = header; - document.getElementById('notification-box').innerHTML = text; - document.getElementById('notification-box').style.display = "block"; // trick to always obtain a closed notification box - OSRM.resizeNotify(); - - document.getElementById('notification-toggle').onclick = OSRM.denotify; - document.getElementById('notification-resize').onclick = OSRM.resizeNotify; -}; -OSRM.resizeNotify = function() { - if( document.getElementById('notification-box').style.display == "none" ) { - document.getElementById('notification-box').style.display = "block"; - var height = document.getElementById('notification-box').clientHeight; - document.getElementById('notification-content').style.height = (height + 28) + "px"; - document.getElementById('notification-wrapper').style.height = (height + 48) + "px"; - document.getElementById('notification-resize').className = "iconic-button up-marker top-right-button"; - } else { - document.getElementById('notification-box').style.display = "none"; - document.getElementById('notification-content').style.height = "18px"; - document.getElementById('notification-wrapper').style.height = "38px"; - document.getElementById('notification-resize').className = "iconic-button down-marker top-right-button"; - } -}; -OSRM.denotify = function() { - document.getElementById('notification-wrapper').style.display = "none"; -}; -OSRM.isNotifyVisible = function() { - return document.getElementById('notification-wrapper').style.display == "block"; -}; - - // onload event OSRM.Browser.onLoadHandler( OSRM.init ); \ No newline at end of file