added cross-browser support for onload event,
made IE8 work again
This commit is contained in:
parent
8845c070a2
commit
596e7fc60a
@ -87,15 +87,15 @@ setLabels: function() {
|
||||
toggleMain: function() {
|
||||
// show main-gui
|
||||
if( OSRM.GUI.visible == false ) {
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.visibility="hidden";
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px";;
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.visibility="hidden";
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px";;
|
||||
|
||||
document.getElementById('blob-wrapper').style.visibility="hidden";
|
||||
document.getElementById('main-wrapper').style.left="5px";
|
||||
// hide main-gui
|
||||
} else {
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.visibility="hidden";
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.left="30px";
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.visibility="hidden";
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left="30px";
|
||||
|
||||
document.getElementById('main-wrapper').style.left=-OSRM.GUI.width+"px";
|
||||
}
|
||||
@ -110,11 +110,11 @@ onMainTransitionEnd: function() {
|
||||
// after hiding main-gui
|
||||
if( OSRM.GUI.visible == true ) {
|
||||
document.getElementById('blob-wrapper').style.visibility="visible";
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.visibility="visible";
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.visibility="visible";
|
||||
OSRM.GUI.visible = false;
|
||||
// after showing main-gui
|
||||
} else {
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.visibility="visible";
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.visibility="visible";
|
||||
OSRM.GUI.visible = true;
|
||||
}
|
||||
},
|
||||
|
@ -25,13 +25,13 @@ 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) {
|
||||
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);
|
||||
this.setView( position, zoom, no_animation);
|
||||
},
|
||||
fitBoundsUI: function(bounds) {
|
||||
var southwest = bounds.getSouthWest();
|
||||
@ -93,12 +93,12 @@ init: function() {
|
||||
OSRM.G.map.addControl(layersControl);
|
||||
|
||||
// move zoom markers
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px";
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px";
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px";
|
||||
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px";
|
||||
|
||||
// initial correct map position and zoom (respect UI visibility, use browser position)
|
||||
var position = new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE);
|
||||
OSRM.G.map.setViewUI( position, OSRM.DEFAULTS.ONLOAD_ZOOM_LEVEL);
|
||||
OSRM.G.map.setViewUI( position, OSRM.DEFAULTS.ONLOAD_ZOOM_LEVEL, true);
|
||||
if (navigator.geolocation && document.URL.indexOf("file://") == -1) // convenience during development, as FF doesn't save rights for local files
|
||||
navigator.geolocation.getCurrentPosition(OSRM.Map.geolocationResponse);
|
||||
|
||||
|
@ -15,8 +15,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM old browser support
|
||||
// [simple browser detection and routines to support some old browsers]
|
||||
// OSRM old/cross browser support
|
||||
// [browser detection and routines for old/cross browser support]
|
||||
|
||||
|
||||
// browser detection (runs anonymous function to prevent local variables cluttering global namespace)
|
||||
@ -30,13 +30,37 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
}());
|
||||
|
||||
|
||||
// compatibility tools for old browsers
|
||||
function getElementsByClassName(node, classname) {
|
||||
// compatibility tools
|
||||
|
||||
//add document.head reference for older browsers
|
||||
document.head = document.head || document.getElementsByTagName('head')[0];
|
||||
|
||||
// supply getElementsByClassName method for older browser
|
||||
OSRM.Browser.getElementsByClassName = function( node, classname ) {
|
||||
var a = [];
|
||||
var re = new RegExp('(^| )'+classname+'( |$)');
|
||||
var els = node.getElementsByTagName("*");
|
||||
for(var i=0,j=els.length; i<j; i++)
|
||||
if(re.test(els[i].className))a.push(els[i]);
|
||||
return a;
|
||||
}
|
||||
document.head = document.head || document.getElementsByTagName('head')[0];
|
||||
};
|
||||
|
||||
// call a function when DOM has finished loading and remove event handler
|
||||
OSRM.Browser.onLoadHandler = function( function_pointer ) {
|
||||
if(document.addEventListener) { // FF, CH, IE9+
|
||||
var temp_function = function() {
|
||||
document.removeEventListener("DOMContentLoaded", arguments.callee, false);
|
||||
function_pointer.call();
|
||||
};
|
||||
document.addEventListener("DOMContentLoaded", temp_function, false);
|
||||
}
|
||||
else if(document.attachEvent) { // IE8-
|
||||
var temp_function = function() {
|
||||
if ( document.readyState === "interactive" || document.readyState === "complete" ) {
|
||||
document.detachEvent("onreadystatechange", arguments.callee);
|
||||
function_pointer.call();
|
||||
}
|
||||
};
|
||||
document.attachEvent("onreadystatechange", temp_function);
|
||||
}
|
||||
};
|
@ -63,7 +63,4 @@ OSRM.debug.init = function() {
|
||||
|
||||
|
||||
// onload event
|
||||
if(document.addEventListener) // FF, CH
|
||||
document.addEventListener("DOMContentLoaded", OSRM.debug.init, false);
|
||||
else if(document.attachEvent) // IE
|
||||
document.attachEvent("onreadystatechange", function() { if ( document.readyState === "interactive" ) OSRM.debug.init(); });
|
||||
OSRM.Browser.onLoadHandler( OSRM.debug.init );
|
@ -43,8 +43,10 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
<script src="OSRM.base.js" type="text/javascript"></script>
|
||||
<script src="OSRM.config.js" type="text/javascript"></script>
|
||||
<!-- <script defer="defer" src="OSRM.debug.js" type="text/javascript"></script> -->
|
||||
<script src="OSRM.browsers.js" type="text/javascript"></script>
|
||||
|
||||
<script src="main.js" type="text/javascript"></script>
|
||||
<!-- <script defer="defer" src="OSRM.debug.js" type="text/javascript"></script> -->
|
||||
|
||||
<script src="OSRM.Markers.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Route.js" type="text/javascript"></script>
|
||||
@ -59,7 +61,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
<script src="OSRM.Via.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Geocoder.js" type="text/javascript"></script>
|
||||
|
||||
<script src="OSRM.Browser.js" type="text/javascript"></script>
|
||||
<script src="OSRM.JSONP.js" type="text/javascript"></script>
|
||||
<script src="localization/OSRM.Localization.js" type="text/javascript"></script>
|
||||
<script src="printing/OSRM.Printing.js" type="text/javascript"></script>
|
||||
|
@ -203,7 +203,4 @@ OSRM.parseParameters = function(){
|
||||
|
||||
|
||||
// onload event
|
||||
if(document.addEventListener) // FF, CH
|
||||
document.addEventListener("DOMContentLoaded", OSRM.init, false);
|
||||
else if(document.attachEvent)
|
||||
document.attachEvent("onreadystatechange", function() { if ( document.readyState === "interactive" ) OSRM.init(); });
|
||||
OSRM.Browser.onLoadHandler( OSRM.init );
|
Loading…
Reference in New Issue
Block a user