From c9df78338eeefe874b148a240e1bd32851a6b1d1 Mon Sep 17 00:00:00 2001 From: edoardoo Date: Sun, 9 Aug 2015 03:27:25 +0200 Subject: [PATCH] fixed multiple object local json --- public/scripts/functions.js | 14 +++++++++++++- public/scripts/socketSetup.js | 10 +--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/public/scripts/functions.js b/public/scripts/functions.js index 6f6cc67..33c5bf7 100644 --- a/public/scripts/functions.js +++ b/public/scripts/functions.js @@ -3,6 +3,18 @@ var totalRenders = 0; function updateDimensions( dimension ){ less.modifyVars({"@sizeWidth":dimension+"px"}); } +function prePopulate(honeyCells){ + var honeyCells = JSON.parse(honeyCells); + + if( honeyCells.constructor === Array){ + for (var i = 0; i < honeyCells.length; i++) { + populateHoneycomb( honeyCells[i], i ); + + }; + }else{ + populateHoneycomb( honeyCells , 0); + } +} function populateHoneycomb( honeyCells , index){ @@ -256,7 +268,7 @@ document.onkeydown = checkKey; function sendJson(){ // console.log("sending mama some json.") // socket.emit("jsonToParse", document.getElementById("sendHCJson").value); - populateHoneycomb( JSON.parse(document.getElementById("sendHCJson").value) , 0); + prePopulate( document.getElementById("sendHCJson").value); } function checkKey(e) { diff --git a/public/scripts/socketSetup.js b/public/scripts/socketSetup.js index 8bc08ee..f09c71f 100644 --- a/public/scripts/socketSetup.js +++ b/public/scripts/socketSetup.js @@ -9,15 +9,7 @@ socket.on("jsonHoneycomb",function(message){ be executed . The Callback function gets the dat sent from the server */ console.log("Message from the server arrived") - var honeyCells = JSON.parse(message); - if( honeyCells.constructor === Array){ - for (var i = 0; i < honeyCells.length; i++) { - populateHoneycomb( honeyCells[i], i ); - - }; - }else{ - populateHoneycomb( honeyCells , 0); - } + prePopulate(message); socket.emit('ackMessage', "true"); });