[Mapbender-commits] r3294 - branches/beck_dev/http/javascripts

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Dec 11 02:55:12 EST 2008


Author: beck
Date: 2008-12-11 02:55:12 -0500 (Thu, 11 Dec 2008)
New Revision: 3294

Modified:
   branches/beck_dev/http/javascripts/mod_mapCookie.php
Log:


Modified: branches/beck_dev/http/javascripts/mod_mapCookie.php
===================================================================
--- branches/beck_dev/http/javascripts/mod_mapCookie.php	2008-12-11 07:32:53 UTC (rev 3293)
+++ branches/beck_dev/http/javascripts/mod_mapCookie.php	2008-12-11 07:55:12 UTC (rev 3294)
@@ -25,10 +25,10 @@
 var mod_mapCookie_cookieLifetime = 7;
 var mod_mapCookie_cookieName     = 'stored_map_state';
 
-eventInit.register(restoreMapState);
-eventInit.register(triggerUnload);
+eventInit.register(mod_mapCookie_restoreMapState);
+eventInit.register(mod_mapCookie_triggerUnload);
 
-function restoreMapState() {
+function mod_mapCookie_restoreMapState() {
 	if(!document.cookie) {
 		return;
 	}
@@ -45,32 +45,58 @@
 		
 		var storedMapState = eval('(' + cookieData[i].replace(cookieName + '=','') + ')');
 		
+		if(storedMapState.frameName != mod_mapCookie_target) {
+			continue;
+		}
+		
+		currentMapState.epsg   = storedMapState.epsg;
 		currentMapState.extent = storedMapState.extent;
-		currentMapState.epsg   = storedMapState.epsg;
 	}
 }
 
-function storeMapState() {
+function mod_mapCookie_storeMapState() {
 	var currentMapState = mb_mapObj[getMapObjIndexByName(mod_mapCookie_target)];
 	var cookieExpires   = new Date();
 	var cookieData      = {}
-	
+
+	mod_mapCookie_removeCookie();
+
 	cookieExpires.setTime(cookieExpires.getTime() + (parseInt(mod_mapCookie_cookieLifetime) * 24 * 60 * 60 * 1000));
 
-	cookieData.extent = currentMapState.extent;
-	cookieData.epsg   = currentMapState.epsg;
+	cookieData.frameName = currentMapState.frameName;
+	cookieData.epsg      = currentMapState.epsg;
+	cookieData.extent    = currentMapState.extent;
 
-	document.cookie = 'stored_map_state=' + $.toJSON(cookieData) + ';expires=' + cookieExpires.toGMTString();
+	document.cookie = mod_mapCookie_cookieName + '=' + $.toJSON(cookieData) + ';expires=' + cookieExpires.toGMTString() + ';';
 }
 
-function triggerUnload() {
+function mod_mapCookie_removeCookie() {
+	if(!document.cookie) {
+		return;
+	}
+	
+	var cookieExpires = new Date("01 01, 1970 00:00:01"); 
+	var cookieData    = document.cookie.split(';');
+	
+	for(var i = 0; i < cookieData.length; i++) {
+		var cookieName = new RegExp(mod_mapCookie_cookieName);
+		
+		if(!cookieData[i].match(cookieName)) {
+			continue;
+		}
+		
+		document.cookie = mod_mapCookie_cookieName + '=;expires=' + cookieExpires + ';';
+	}
+}
+
+function mod_mapCookie_triggerUnload() {
 	if(ie) {
 		document.getElementById('body').onunload = function() {
-			var trigger = new Function ('','storeMapState()');
+			var trigger = new Function ('','mod_mapCookie_storeMapState()');
 			trigger(); 
 		};
 	}
 	else {
-		document.getElementById('body').setAttribute('onunload','storeMapState();');
+		document.getElementById('body').setAttribute('onunload','mod_mapCookie_storeMapState();');
 	}
 }
\ No newline at end of file



More information about the Mapbender_commits mailing list