diff --git a/WebContent/OSRM.base.js b/WebContent/OSRM.base.js index 492f210c0..783282ae4 100644 --- a/WebContent/OSRM.base.js +++ b/WebContent/OSRM.base.js @@ -26,32 +26,3 @@ OSRM.DEFAULTS = {}; OSRM.GLOBALS = {}; OSRM.G = OSRM.GLOBALS; // abbreviations OSRM.C = OSRM.CONSTANTS; - - -// declare one class to be a subclass of another class -// (runs anonymous function to prevent local functions cluttering global namespace) -(function() { -var _inheritFromHelper = function() {}; -OSRM.inheritFrom = function( sub_class, base_class ) { - _inheritFromHelper.prototype = base_class.prototype; - sub_class.prototype = new _inheritFromHelper(); - sub_class.prototype.constructor = sub_class; - sub_class.prototype.base = base_class.prototype; -}; -}()); - - -// extend prototypes of a class -> used to add member values and functions -OSRM.extend = function( target_class, properties ) { - for( property in properties ) { - target_class.prototype[property] = properties[property]; - } -}; - - -// [usage of convenience functions] -// SubClass = function() { -// SubClass.prototype.base.constructor.apply(this, arguments); -// } -// OSRM.inheritFrom( SubClass, BaseClass ); -// OSRM.extend( SubClass, { property:value } ); diff --git a/WebContent/OSRM.Geocoder.js b/WebContent/base/OSRM.Geocoder.js similarity index 100% rename from WebContent/OSRM.Geocoder.js rename to WebContent/base/OSRM.Geocoder.js diff --git a/WebContent/OSRM.Map.js b/WebContent/base/OSRM.Map.js similarity index 72% rename from WebContent/OSRM.Map.js rename to WebContent/base/OSRM.Map.js index a9d60c421..e26edb31c 100644 --- a/WebContent/OSRM.Map.js +++ b/WebContent/base/OSRM.Map.js @@ -22,45 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.GLOBALS.map = null; -// map view/model -// [extending Leaflet L.Map with setView/fitBounds methods that respect UI visibility] -OSRM.MapView = L.Map.extend({ - setViewUI: function(position, zoom, no_animation) { - if( OSRM.GUI.visible == true ) { - var point = this.project( position, zoom); - point.x-=OSRM.GUI.width/2; - position = this.unproject(point,zoom); - } - this.setView( position, zoom, no_animation); - }, - fitBoundsUI: function(bounds) { - var southwest = bounds.getSouthWest(); - var northeast = bounds.getNorthEast(); - var zoom = this.getBoundsZoom(bounds); - var sw_point = this.project( southwest, zoom); - if( OSRM.GUI.visible == true ) - sw_point.x-=OSRM.GUI.width+20; - else - sw_point.x-=20; - sw_point.y+=20; - var ne_point = this.project( northeast, zoom); - ne_point.y-=20; - sw_point.x+=20; - bounds.extend( this.unproject(sw_point,zoom) ); - bounds.extend( this.unproject(ne_point,zoom) ); - this.fitBounds( bounds ); - }, - getCenterUI: function(unbounded) { - var viewHalf = this.getSize(); - if( OSRM.GUI.visible == true ) - viewHalf.x += OSRM.GUI.width; - var centerPoint = this._getTopLeftPoint().add(viewHalf.divideBy(2)); - - return this.unproject(centerPoint, this._zoom, unbounded); - } -}); - - // map controller // [map initialization, event handling] OSRM.Map = { @@ -89,8 +50,8 @@ init: function() { }); // add layer control - var layersControl = new L.Control.Layers(base_maps, {}); - OSRM.G.map.addControl(layersControl); + var layerControl = new L.Control.QueryableLayers(base_maps, {}); + OSRM.G.map.addLayerControl(layerControl); // move zoom markers OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px"; diff --git a/WebContent/OSRM.Markers.js b/WebContent/base/OSRM.Markers.js similarity index 53% rename from WebContent/OSRM.Markers.js rename to WebContent/base/OSRM.Markers.js index ccd2f975b..09179abbb 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/base/OSRM.Markers.js @@ -15,159 +15,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ -// OSRM markers -// [base marker class, derived highlight marker and route marker classes, marker management] - - -// base marker class (wraps Leaflet markers) -OSRM.Marker = function( label, style, position ) { - this.label = label ? label : "marker"; - this.position = position ? position : new L.LatLng(0,0); - - this.marker = new L.MouseMarker( this.position, style ); - this.marker.parent = this; - - this.shown = false; - this.hint = null; -}; -OSRM.extend( OSRM.Marker,{ -show: function() { - OSRM.G.map.addLayer(this.marker); - this.shown = true; -}, -hide: function() { - OSRM.G.map.removeLayer(this.marker); - this.shown = false; -}, -setPosition: function( position ) { - this.position = position; - this.marker.setLatLng( position ); - this.hint = null; -}, -getPosition: function() { - return this.position; -}, -getLat: function() { - return this.position.lat; -}, -getLng: function() { - return this.position.lng; -}, -isShown: function() { - return this.shown; -}, -centerView: function(zoom) { - if( zoom == undefined ) - zoom = OSRM.DEFAULTS.ZOOM_LEVEL; - OSRM.G.map.setViewUI( this.position, zoom ); -}, -toString: function() { - return "OSRM.Marker: \""+this.label+"\", "+this.position+")"; -} -}); - - -// route marker class (draggable, invokes route drawing routines) -OSRM.RouteMarker = function ( label, style, position ) { - style.baseicon = style.icon; - OSRM.RouteMarker.prototype.base.constructor.apply( this, arguments ); - this.label = label ? label : "route_marker"; - - this.marker.on( 'click', this.onClick ); - this.marker.on( 'drag', this.onDrag ); - this.marker.on( 'dragstart', this.onDragStart ); - this.marker.on( 'dragend', this.onDragEnd ); -}; -OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker ); -OSRM.extend( OSRM.RouteMarker, { -onClick: function(e) { - for( var i=0; i1) - OSRM.Routing.getDragRoute(); - OSRM.Geocoder.updateLocation( this.parent.label ); -}, -onDragStart: function(e) { - OSRM.G.dragging = true; - this.switchIcon(this.options.dragicon); - - // store id of dragged marker - for( var i=0; i1) + OSRM.Routing.getDragRoute(); + OSRM.Geocoder.updateLocation( this.parent.label ); +}, +onDragStart: function(e) { + OSRM.G.dragging = true; + this.switchIcon(this.options.dragicon); + + // store id of dragged marker + for( var i=0; i - - - - + + + + + - + + - - + + + - - + + + + - + - - + + - + - + diff --git a/WebContent/main.js b/WebContent/main.js index 8755fbf8b..0631c3743 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -27,7 +27,7 @@ OSRM.init = function() { OSRM.Localization.init(); OSRM.GUI.init(); OSRM.Map.init(); - //OSRM.Printing.init(); + OSRM.Printing.init(); OSRM.Routing.init(); // check if the URL contains some GET parameter, e.g. for showing a route @@ -71,6 +71,7 @@ OSRM.prefetchImages = function() { {id:'direction_6', url:'images/slight-left.png'}, {id:'direction_7', url:'images/turn-left.png'}, {id:'direction_8', url:'images/sharp-left.png'}, + {id:'direction_10', url:'images/head.png'}, {id:'direction_11', url:'images/round-about.png'}, {id:'direction_15', url:'images/target.png'} ]; diff --git a/WebContent/printing/OSRM.Printing.js b/WebContent/printing/OSRM.Printing.js index b8a53428b..00cc2ae68 100644 --- a/WebContent/printing/OSRM.Printing.js +++ b/WebContent/printing/OSRM.Printing.js @@ -15,11 +15,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see http://www.gnu.org/licenses/agpl.txt. */ -// OSRM printer +// OSRM printing // [printing support] -OSRM.Printing = { +OSRM.Printing = { + // create UI for printing in mainwindow init: function() { var icon = document.createElement('div'); @@ -36,103 +37,92 @@ init: function() { document.getElementById("gui-printer").onclick = OSRM.Printing.print; }, + // create UI in printwindow show: function(response) { - // add events - OSRM.printwindow.document.getElementById('gui-printer').onclick = OSRM.printwindow.printWindow; - - // localization - OSRM.printwindow.document.getElementById('description-label').innerHTML = OSRM.loc( "ROUTE_DESCRIPTION" ); - OSRM.printwindow.document.getElementById('overview-map-label').innerHTML = OSRM.loc( "OVERVIEW_MAP" ); - // create header - header = + var header = + '' + + '
' + - '
' + + '
' + - '
' + - '
' + OSRM.loc("GUI_START")+ ':
' + - '
' + OSRM.loc("GUI_END")+ ':
' + + '
' + + '
' + + '
' + + '
' + OSRM.loc("GUI_START")+ ':
' + + '
' + document.getElementById("gui-input-source").value + '
' + '
' + - - '
' + - '
' + document.getElementById("gui-input-source").value + '
' + - '
' + document.getElementById("gui-input-target").value + '
' + - '
' + - - '
' + - '
' + OSRM.loc("DISTANCE")+':
' + - '
' + OSRM.loc("DURATION")+':
' + + '
' + + '
' + OSRM.loc("GUI_END")+ ':
' + + '
' + document.getElementById("gui-input-target").value + '
' + '
' + + '
' + + '
' + '
' + - '
' + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + '
' + - '
' + OSRM.Utils.secondsToTime(response.route_summary.total_time) + '
' + + '
' + + '
' + + '
' + OSRM.loc("DISTANCE")+':
' + + '
' + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + '
' + + '
' + + '
' + + '
' + OSRM.loc("DURATION")+':
' + + '
' + OSRM.Utils.secondsToTime(response.route_summary.total_time) + '
' + + '
' + + '
' + '
' + '
' + '
' + - '
'; + + '
' + + ''; // create route description - var route_desc = ''; - route_desc += ''; - route_desc += ''; - route_desc += ''; - + var body = ''; for(var i=0; i < response.route_instructions.length; i++){ //odd or even ? - var rowstyle='results-odd'; - if(i%2==0) { rowstyle='results-even'; } + var rowstyle='description-body-odd'; + if(i%2==0) { rowstyle='description-body-even'; } - route_desc += ''; + body += ''; - route_desc += '"; - - route_desc += '"; // build route description - if( i == 0 ) - route_desc += OSRM.loc(OSRM.RoutingDescription.getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"$1").replace(/%s/, OSRM.loc(response.route_instructions[i][6]) ); - else if( response.route_instructions[i][1] != "" ) - route_desc += OSRM.loc(OSRM.RoutingDescription.getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"$1").replace(/%s/, response.route_instructions[i][1]); + body += '"; + body += OSRM.loc(OSRM.RoutingDescription._getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"").replace(/%d/, OSRM.loc(response.route_instructions[i][6])); + body += ""; - route_desc += '"; + body += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; + body += ""; - route_desc += ""; + body += ""; } - route_desc += ''; - route_desc += '
'+header+'
'; - route_desc += ''; - route_desc += "'; - route_desc += '
'; + body += '
'; + body += ''; + body += "'; + if( response.route_instructions[i][1] != "" ) + body += OSRM.loc(OSRM.RoutingDescription._getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"$1").replace(/%s/, response.route_instructions[i][1]).replace(/%d/, OSRM.loc(response.route_instructions[i][6])); else - route_desc += OSRM.loc(OSRM.RoutingDescription.getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,""); - - route_desc += ''; - route_desc += "'; + body += ''; if( i != response.route_instructions.length-1 ) - route_desc += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; - route_desc += "
'; - - + body += ''; // put everything in DOM - OSRM.printwindow.document.getElementById('description').innerHTML = route_desc; - OSRM.printwindow.document.getElementById('overview-description').innerHTML = - '' + - ''+ - '
'+header+'
'; + OSRM.G.printwindow.document.getElementById('description').innerHTML = '' + header + body + '
'; + OSRM.G.printwindow.document.getElementById('overview-map-description').innerHTML = '' + header + '
'; - // init map - OSRM.Printing.map = OSRM.printwindow.initialize( OSRM.DEFAULTS.TILE_SERVERS[0] ); - var map = OSRM.Printing.map; + // draw map + var tile_server_id = OSRM.G.map.getActiveLayerId(); + var map = OSRM.G.printwindow.initialize( OSRM.DEFAULTS.TILE_SERVERS[tile_server_id] ); + // draw markers var markers = OSRM.G.markers.route; map.addLayer( new L.MouseMarker( markers[0].getPosition(), {draggable:false,clickable:false,icon:OSRM.G.icons['marker-source']} ) ); for(var i=1, size=markers.length-1; i td, +.description-body-odd > td +{ + border-bottom: 1px solid black; } } -@media screen { + + +/* utility styles */ .quad { min-width:10px; min-height:10px; } +@media print { +.pagebreak +{ + page-break-before:always; +} +.noprint +{ + display:none; +} +} + + +/* fonts */ +@media print { +.base-font { + font-family: Times New Roman, Times, serif; + font-size: 16px; + font-weight: normal; +} +.big-font { + font-family: Times New Roman, Times, serif; + font-size: 18px; + font-weight: bold; +} +.medium-font { + font-family: Times New Roman, Times, serif; + font-size: 14px; + font-weight: normal; +} +.small-font { + font-family: Times New Roman, Times, serif; + font-size: 12px; + font-weight: normal; +} +} + +@media screen { +.base-font { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 12px; + font-weight: normal; +} +.big-font { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 14px; + font-weight: bold; +} +.medium-font { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 10.5px; + font-weight: normal; +} +.small-font { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 9px; + font-weight: normal; +} } @@ -180,77 +219,35 @@ div.header-title } -/* fonts */ -@media print { - -.base-font { - font-family: Times New Roman, Times, serif; - font-size: 16px; - font-weight: normal; -} -.big-font { - font-family: Times New Roman, Times, serif; - font-size: 18px; - font-weight: bold; -} -.medium-font { - font-family: Times New Roman, Times, serif; - font-size: 14px; - font-weight: normal; -} -.small-font { - font-family: Times New Roman, Times, serif; - font-size: 12px; - font-weight: normal; -} - -} - -@media screen { -.base-font { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 12px; - font-weight: normal; -} -.big-font { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 14px; - font-weight: bold; -} -.medium-font { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 10.5px; - font-weight: normal; -} -.small-font { - font-family: Verdana, Arial, Helvetica, sans-serif; - font-size: 9px; - font-weight: normal; -} -} - - /* table */ .full { display:table; width:100%; } +.row +{ + display:table-row; +} .left { display:table-cell; text-align:left; - vertical-align:middle; + vertical-align:top; } .right { display:table-cell; text-align:right; - vertical-align:middle; + vertical-align:top; } .center { display:table-cell; text-align:center; - vertical-align:middle; + vertical-align:top; +} +.stretch +{ + width:100%; } \ No newline at end of file diff --git a/WebContent/printing/printing.html b/WebContent/printing/printing.html index e38518d57..9206de4fb 100644 --- a/WebContent/printing/printing.html +++ b/WebContent/printing/printing.html @@ -29,18 +29,15 @@ or see http://www.gnu.org/licenses/agpl.txt. - - - - - + + @@ -48,18 +45,20 @@ or see http://www.gnu.org/licenses/agpl.txt. -
+
-
Routenbeschreibung
-
+
Routenbeschreibung
+
-
-
Übersichtskarte
-
+
+
+
+
Übersichtskarte
+
diff --git a/WebContent/printing/printing.js b/WebContent/printing/printing.js index 8303bba42..32a5c7da7 100644 --- a/WebContent/printing/printing.js +++ b/WebContent/printing/printing.js @@ -28,7 +28,7 @@ function initialize(tile_server) { // setup map var tile_layer = new L.TileLayer(tile_server.url, tile_server.options); OSRM.G.map = new OSRM.MapView("overview-map", { - center: new L.LatLng(51.505, -0.09), + center: new L.LatLng(48.84, 10.10), zoom: 13, zoomAnimation: false, fadeAnimation: false, diff --git a/WebContent/routing/OSRM.RoutingDescription.js b/WebContent/routing/OSRM.RoutingDescription.js index efbc8e4df..03c91ab7d 100644 --- a/WebContent/routing/OSRM.RoutingDescription.js +++ b/WebContent/routing/OSRM.RoutingDescription.js @@ -58,72 +58,53 @@ show: function(response) { var gpx_link = '['+OSRM.loc("GPX_FILE")+']'; // create route description - var route_desc = ""; - route_desc += ''; - + var body = ""; + + body += '
'; for(var i=0; i < response.route_instructions.length; i++){ //odd or even ? - var rowstyle='results-odd'; - if(i%2==0) { rowstyle='results-even'; } + var rowstyle='description-body-odd'; + if(i%2==0) { rowstyle='description-body-even'; } - route_desc += ''; + body += ''; - route_desc += ''; + body += ''; - route_desc += '"; + body += ''; + body += ""; - route_desc += '"; + body += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; + body += ""; - route_desc += ""; + body += ""; } - route_desc += '
'; - route_desc += ''; - route_desc += ''; + body += ''; + body += ''; - route_desc += '
'; + body += '
'; + body += '
'; // build route description if( response.route_instructions[i][1] != "" ) - route_desc += OSRM.loc(OSRM.RoutingDescription.getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"$1").replace(/%s/, response.route_instructions[i][1]).replace(/%d/, OSRM.loc(response.route_instructions[i][6])); + body += OSRM.loc(OSRM.RoutingDescription._getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"$1").replace(/%s/, response.route_instructions[i][1]).replace(/%d/, OSRM.loc(response.route_instructions[i][6])); else - route_desc += OSRM.loc(OSRM.RoutingDescription.getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"").replace(/%d/, OSRM.loc(response.route_instructions[i][6])); + body += OSRM.loc(OSRM.RoutingDescription._getDrivingInstruction(response.route_instructions[i][0])).replace(/\[(.*)\]/,"").replace(/%d/, OSRM.loc(response.route_instructions[i][6])); - route_desc += '
'; - route_desc += "
'; + body += ''; if( i != response.route_instructions.length-1 ) - route_desc += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; - route_desc += "
'; + body += ''; - // create header - header = - '
' + OSRM.loc("ROUTE_DESCRIPTION") + '
' + - '
' + - '
' + - '
' + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + '
' + - '
' + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + '
' + - '
' + - '
' + - '' + - '
' + gpx_link + '
' + - '
' + - '
'; + // build header + header = OSRM.RoutingDescription._buildHeader(OSRM.Utils.metersToDistance(response.route_summary.total_distance), OSRM.Utils.secondsToTime(response.route_summary.total_time), route_link, gpx_link); // update DOM document.getElementById('information-box-header').innerHTML = header; - document.getElementById('information-box').innerHTML = route_desc; + document.getElementById('information-box').innerHTML = body; }, // simple description showSimple: function(response) { - header = - '
' + OSRM.loc("ROUTE_DESCRIPTION") + '
' + - '
' + - '
' + - '
' + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + '
' + - '
' + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + '
' + - '
' + - '
' + - '
' + - '
'; + // build header + header = OSRM.RoutingDescription._buildHeader(OSRM.Utils.metersToDistance(response.route_summary.total_distance), OSRM.Utils.secondsToTime(response.route_summary.total_time), "", ""); // update DOM document.getElementById('information-box-header').innerHTML = header; @@ -132,24 +113,68 @@ showSimple: function(response) { // no description showNA: function( display_text ) { - header = - '
' + OSRM.loc("ROUTE_DESCRIPTION") + '
' + - '
' + - '
' + - '
' + OSRM.loc("DISTANCE")+": N/A" + '
' + - '
' + OSRM.loc("DURATION")+": N/A" + '
' + - '
' + - '
' + - '
' + - '
'; + // build header + header = OSRM.RoutingDescription._buildHeader("N/A", "N/A", "", ""); // update DOM document.getElementById('information-box-header').innerHTML = header; document.getElementById('information-box').innerHTML = "
"+display_text+"
"; }, +// build header +_buildHeader: function(distance, duration, route_link, gpx_link) { + var temp = + '
' + OSRM.loc("ROUTE_DESCRIPTION") + '
' + + + '
' + + '
' + + + '
' + + '
' + + '
' + + '
' + OSRM.loc("DISTANCE")+":" + '
' + + '
' + distance + '
' + + '
' + + '
' + + '
' + OSRM.loc("DURATION")+":" + '
' + + '
' + duration + '
' + + '
' + + '
' + + '
' + + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + gpx_link + '
' + + '
' + + '
' + + '
' + + + '
' + + '
' + + + '
'; +// '
' + OSRM.loc("ROUTE_DESCRIPTION") + '
' + +// '
' + +// '
' + +// '
' + OSRM.loc("DISTANCE")+":" + '
' + +// '
' + distance + '
' + +// '' + +// '
' + +// '
' + +// '
' + OSRM.loc("DURATION")+":" + '
' + +// '
' + duration + '
' + +// '
' + gpx_link + '
' + +// '
' + +// '
'; + return temp; +}, + // retrieve driving instruction icon from instruction id -getDrivingInstructionIcon: function(server_instruction_id) { +_getDrivingInstructionIcon: function(server_instruction_id) { var local_icon_id = "direction_"; server_instruction_id = server_instruction_id.replace(/^11-\d{1,}$/,"11"); // dumb check, if there is a roundabout (all have the same icon) local_icon_id += server_instruction_id; @@ -161,7 +186,7 @@ getDrivingInstructionIcon: function(server_instruction_id) { }, // retrieve driving instructions from instruction ids -getDrivingInstruction: function(server_instruction_id) { +_getDrivingInstruction: function(server_instruction_id) { var local_instruction_id = "DIRECTION_"; server_instruction_id = server_instruction_id.replace(/^11-\d{2,}$/,"11-x"); // dumb check, if there are 10+ exits on a roundabout (say the same for exit 10+) local_instruction_id += server_instruction_id; diff --git a/WebContent/OSRM.EventHandler.js b/WebContent/utils/OSRM.EventHandler.js similarity index 100% rename from WebContent/OSRM.EventHandler.js rename to WebContent/utils/OSRM.EventHandler.js diff --git a/WebContent/OSRM.JSONP.js b/WebContent/utils/OSRM.JSONP.js similarity index 95% rename from WebContent/OSRM.JSONP.js rename to WebContent/utils/OSRM.JSONP.js index cd039987c..4d7d5fdc1 100644 --- a/WebContent/OSRM.JSONP.js +++ b/WebContent/utils/OSRM.JSONP.js @@ -41,7 +41,6 @@ OSRM.JSONP = { // wrap timeout function OSRM.JSONP.timeouts[id] = function(response) { - console.log("timeout",id); try { timeout_function(response, parameters); } finally { diff --git a/WebContent/OSRM.Utils.js b/WebContent/utils/OSRM.Utils.js similarity index 100% rename from WebContent/OSRM.Utils.js rename to WebContent/utils/OSRM.Utils.js diff --git a/WebContent/OSRM.browsers.js b/WebContent/utils/OSRM.browsers.js similarity index 70% rename from WebContent/OSRM.browsers.js rename to WebContent/utils/OSRM.browsers.js index 9247a60dd..923ac2b0a 100644 --- a/WebContent/OSRM.browsers.js +++ b/WebContent/utils/OSRM.browsers.js @@ -45,22 +45,25 @@ OSRM.Browser.getElementsByClassName = function( node, classname ) { return a; }; -// call a function when DOM has finished loading and remove event handler -OSRM.Browser.onLoadHandler = function( function_pointer ) { - if(document.addEventListener) { // FF, CH, IE9+ +// call a function when DOM has finished loading and remove event handler (optionally pass a different window object) +OSRM.Browser.onLoadHandler = function( function_pointer, the_document ) { + the_document = the_document || document; // default document + + if(the_document.addEventListener) { // FF, CH, IE9+ var temp_function = function() { - document.removeEventListener("DOMContentLoaded", arguments.callee, false); + the_document.removeEventListener("DOMContentLoaded", arguments.callee, false); function_pointer.call(); }; - document.addEventListener("DOMContentLoaded", temp_function, false); + the_document.addEventListener("DOMContentLoaded", temp_function, false); } - else if(document.attachEvent) { // IE8- + + else if(the_document.attachEvent) { // IE8- var temp_function = function() { - if ( document.readyState === "interactive" || document.readyState === "complete" ) { - document.detachEvent("onreadystatechange", arguments.callee); + if ( the_document.readyState === "interactive" || the_document.readyState === "complete" ) { + the_document.detachEvent("onreadystatechange", arguments.callee); function_pointer.call(); } }; - document.attachEvent("onreadystatechange", temp_function); + the_document.attachEvent("onreadystatechange", temp_function); } }; \ No newline at end of file diff --git a/WebContent/utils/OSRM.classes.js b/WebContent/utils/OSRM.classes.js new file mode 100644 index 000000000..4b21d653c --- /dev/null +++ b/WebContent/utils/OSRM.classes.js @@ -0,0 +1,47 @@ +/* +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 base class +// [support for inheritance] + +// declare one class to be a subclass of another class +// (runs anonymous function to prevent local functions cluttering global namespace) +(function() { +var _inheritFromHelper = function() {}; +OSRM.inheritFrom = function( sub_class, base_class ) { + _inheritFromHelper.prototype = base_class.prototype; + sub_class.prototype = new _inheritFromHelper(); + sub_class.prototype.constructor = sub_class; + sub_class.prototype.base = base_class.prototype; +}; +}()); + + +// extend prototypes of a class -> used to add member values and functions +OSRM.extend = function( target_class, properties ) { + for( property in properties ) { + target_class.prototype[property] = properties[property]; + } +}; + + +// [usage of convenience functions] +// SubClass = function() { +// SubClass.prototype.base.constructor.apply(this, arguments); +// } +// OSRM.inheritFrom( SubClass, BaseClass ); +// OSRM.extend( SubClass, { property:value } ); diff --git a/WebContent/OSRM.debug.js b/WebContent/utils/OSRM.debug.js similarity index 100% rename from WebContent/OSRM.debug.js rename to WebContent/utils/OSRM.debug.js