From 1eeb95fcde8e23ea9493d74232f9e38d3fad6d02 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Thu, 2 Feb 2012 22:39:09 -0800 Subject: Fix for JSON "MapData" div issue for search engines. --- includes/maps.php | 19 +++++++++++-------- js/mapspecs.js | 9 +++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/includes/maps.php b/includes/maps.php index 6a8512c..a6787a7 100644 --- a/includes/maps.php +++ b/includes/maps.php @@ -104,12 +104,9 @@ function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL) $i -= 1; $height = (($i * 35) + -1).'px'; //$height = (($i * 22) + 2).'px'; - - $jsonmap = json_encode($mapdata); - - - + $jsonmap = str_replace("'", "\'", json_encode($mapdata)); + //This works in chrome, not sure about others. $preloaddiv .= "
@@ -122,9 +119,15 @@ function DisplayMap($mapMatrix, $idprefix = 1, $style = 'normal', $speed = NULL)
"; - $mapdatadiv .= "'; + //$mapdatadiv .= "'; + + //JSON Fix for search-engine cache. + $mapdatadiv = ""; + $maptable = "$preloaddiv diff --git a/js/mapspecs.js b/js/mapspecs.js index 68be78c..5361d9d 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -27,6 +27,8 @@ var count = new Array(); var mapdata = new Array(); var mapjson = new Array(); var htmlscores = ''; +var jsonmapdata = new Object; + function loadSol(sol) { if (sol == null) @@ -113,12 +115,15 @@ function updateDsp(mapid, element, data) { } function getmapdata(mapid) { + var rawjson = jsonmapdata[mapid]; if (typeof(JSON) == 'undefined') { - text = document.getElementById(mapid+',mapdata').innerHTML; + //text = document.getElementById(mapid+',mapdata').innerHTML; + text = rawjson; mapdata[mapid] = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(text.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + text + ')'); //mapdata[mapid] = eval(document.getElementById(mapid+',mapdata').innerHTML); } else { - mapdata[mapid] = JSON.parse(document.getElementById(mapid+',mapdata').innerHTML); + //mapdata[mapid] = JSON.parse(document.getElementById(mapid+',mapdata').innerHTML); + mapdata[mapid] = JSON.parse(rawjson); } blocks[mapid] = mapdata[mapid].walls; -- cgit v1.2.3