From 0d9cd0d84d3bd816831aa02d76a71bca2e8230a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20=E2=80=98Touky=E2=80=99=20Huet?= Date: Tue, 8 Oct 2013 01:37:45 +0000 Subject: [PATCH] meshviewer html version now uses cookies to autosave command. --- test/javascript/naclloading.js | 2 ++ test/javascript/utils.js | 3 ++- test/meshviewer.em.html | 3 +++ test/meshviewer.index.html | 47 +++++++++++++++++++++------------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/test/javascript/naclloading.js b/test/javascript/naclloading.js index 58056af9..674eb2e3 100644 --- a/test/javascript/naclloading.js +++ b/test/javascript/naclloading.js @@ -64,6 +64,8 @@ function NaClModuleDidLoad() //Hide the progress div AddTextStatus('Module is live, thank you for your patience.'); window.setTimeout('HideProgressStatus(true)', GetMaxStatusTime(0.5) * 1000); + + ModuleIsLive(); } //Module did crash diff --git a/test/javascript/utils.js b/test/javascript/utils.js index 8c8e44f3..a6cf2dd6 100644 --- a/test/javascript/utils.js +++ b/test/javascript/utils.js @@ -28,7 +28,6 @@ function LolCookieDate(m_name, m_value, m_expire_date) //Set a cookie function StoreLolCookie(cookie) { - //Get the cookie and removes it if it exists. GetLolCookie(cookie.m_name, true); var enc_value = escape(cookie.m_value) + ";"; @@ -58,6 +57,8 @@ function GetLolCookie(name, remove) //Retrieve value var val_start = cki_doc.indexOf("=", cki_start) + 1; var val_end = cki_doc.indexOf(";", cki_start); + if (val_end < 0) + val_end = cki_doc.length; cookie.m_value = unescape(cki_doc.substring(val_start, val_end)); if (remove) diff --git a/test/meshviewer.em.html b/test/meshviewer.em.html index 772a1f5a..3e632343 100644 --- a/test/meshviewer.em.html +++ b/test/meshviewer.em.html @@ -139,7 +139,10 @@ canvas.emscripten if (left) Module.setStatus('Downloading dependencies ', (this.totalDependencies - left), this.totalDependencies); else + { Module.setStatus('All downloads complete.', 1, 1); + parent.ModuleIsLive(); + } }, //IMPORTANT : This is the C -> Javascript wraping, add your functions list here. wrapup_list: [ {src_obj: null, func_name: 'DoSendMessage', c_func_name: 'C_Send', return_var: 'number', args: ['string'] } ], diff --git a/test/meshviewer.index.html b/test/meshviewer.index.html index ff051048..5d68e2e0 100644 --- a/test/meshviewer.index.html +++ b/test/meshviewer.index.html @@ -107,13 +107,13 @@ progress::-webkit-progress-value var g_autosave_timer = 4.0; var g_autosave_time = 4.0; - var g_code_addin = ['custom setmesh "#CODE#"', '#CODE#']; + var g_code_addin = [' custom setmesh "#CODE#" ', '#CODE#']; var g_code_base = []; var CodeDictionnary = []; - g_code_id = 0; - g_code_base = ["//This is a comment\nsc#f8f afcb 1 1 1 0", - "//This is a comment\naddlight 0.0 position (4 -1 -4) color (.0 .2 .5 1)\naddlight 0.0 position (8 2 6) color #ffff\nshowgizmo true\nshowlight true"]; + var g_code_id = 0; + g_code_base[0] = "//This is a comment\nsc#f8f afcb 1 1 1 0"; + g_code_base[1] = "//This is a comment\naddlight 0.0 position (4 -1 -4) color (.0 .2 .5 1)\naddlight 0.0 position (8 2 6) color #ffff\nshowgizmo true\nshowlight true"; function machinchose() { return 'test machin '; } function GetTextAreaCodeSrc() { return g_txtarea_code_src; } @@ -184,11 +184,16 @@ function machinchose() { return 'test machin '; } //Put here any cookie update if (DoesLolCookieExist("LolMeshViewerAutosave")) { - var lol_cookie = GetLolCookie("LolMeshViewerAutosave"); - var value_list = lol_cookie.m_value.split(";"); - + var lol_cookie = GetLolCookie("LolMeshViewerAutosave", false); + var value_list = lol_cookie.m_value.split(";"); for (var i = 0; i < g_code_base.length && i < value_list.length; i++) + { g_code_base[i] = value_list[i]; + var addins = g_code_addin[i].split('#CODE#'); + for (var j = 0; j < addins.length; j++) + if (addins[j] && addins[j] != '') + g_code_base[i] = g_code_base[i].replace(addins[j], ""); + } g_txtarea_code_src.value = g_code_base[g_code_id]; } else if (!g_txtarea_code_src.value) @@ -249,20 +254,16 @@ function machinchose() { return 'test machin '; } if (g_autosave_timer < 0.0) { g_autosave_timer = g_autosave_time; - StoreLolCookie("LolMeshViewerAutosave", GetTextValue(true), 10); + StoreCodeCookie(); } } - function GetTextValue(getall) + function StoreCodeCookie() { var result = ''; - for (var i = (getall)?(0):(g_code_id); i < g_code_base.length; i++) - { - result += g_code_addin[i].replace('#CODE#', g_code_base[i]) + (getall)?(';'):(''); - if (getall && i == g_code_id) - break; - } - return result; + for (var i = 0; i < g_code_base.length; i++) + { result += g_code_addin[i].replace('#CODE#', g_code_base[i]) + ";"; } + StoreLolCookie(new LolCookieDays("LolMeshViewerAutosave", result, 10)); } function StoreTextAreaValue() @@ -289,14 +290,24 @@ function machinchose() { return 'test machin '; } alert('Module sent message: ' + message.data); } + //When module is live, it calls this. + function ModuleIsLive() + { + for (var i = 0; i < g_code_base.length; i++) + { + SendMessageToModule(); + ExchangeSetup(); + } + } + //Called by the "Send Mesh Command !" button function SendMessageToModule() { StoreTextAreaValue(); if (g_embed_module) { - StoreLolCookie("LolMeshViewerAutosave", GetTextValue(true), 10); - g_embed_module.SendMessage(GetTextValue(false)); + StoreCodeCookie(); + g_embed_module.SendMessage(g_code_addin[g_code_id].replace('#CODE#', g_code_base[g_code_id])); } else alert("Module not loaded !");