瀏覽代碼

Added utils.js : contains two Dynamic js loading func for NaCl/em version

tweak MeshViewer html for dual NaCl/em version setup.
undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 年之前
父節點
當前提交
c60cc0794c
共有 4 個檔案被更改,包括 101 行新增50 行删除
  1. +8
    -0
      test/empty.html
  2. +33
    -15
      test/meshviewer_index.html
  3. +13
    -35
      test/nacl_loading.js
  4. +47
    -0
      test/utils.js

+ 8
- 0
test/empty.html 查看文件

@@ -0,0 +1,8 @@
<DOCTYPE html>
<html>
<head>
</head>
<body>
<!-- I'm only here to ensure embed viewport of NaCl/Emscripten is "not empty" -->
</body>
</html>

+ 33
- 15
test/meshviewer_index.html 查看文件

@@ -33,8 +33,9 @@ textarea
left: 30%;
right: 30%;
z-index: 3;
background-color:white;
border:1px solid #000000;
background-color:white;
border:1px solid #000000;
visibility: hidden;
}
progress
{
@@ -80,15 +81,14 @@ progress::-webkit-progress-value
}
</style>

<title>Mesh Viewer NaCl</title>
<title>Mesh Viewer Web Edition</title>

</head>

<script type="text/javascript">
//Base data Setup
//Base data Setup : GLOBAL STYLE
g_div_frame_embed_save = '';
g_div_frame_embed = null; // Global application object.
g_embed_nacl_module = null; // Global application object.
g_div_frame_embed = null;
g_txtarea_code_src = null;
g_div_helper_cmd = [null, null];
g_div_helper_args = null;
@@ -101,9 +101,6 @@ progress::-webkit-progress-value
g_var_progress_bar = -1;
g_frame_embed = null;

function GetNaClListenerDiv() { return g_frame_embed.contentDocument.getElementById('id_div_embed_data'); }
function GetNaClModuleVar() { return g_embed_nacl_module; }
function InitNaClModuleVar() { g_embed_nacl_module = g_frame_embed.contentDocument.getElementById('id_embed_nacl_module'); }
function GetTextAreaCodeSrc() { return g_txtarea_code_src; }
function GetDivProgress() { return g_div_progress; }
function GetProgressBar() { return g_progress_bar; }
@@ -111,20 +108,24 @@ progress::-webkit-progress-value
function GetDivEmbedData() { return g_div_frame_embed; }
function GetDivEmbedDataSave() { return g_div_frame_embed_save; }
function GetFrameData() { return g_frame_embed; }
function IsUsingNaCl() { return true; }
function GetiFrameDivEmbed() { return g_frame_embed.contentDocument.getElementById('id_div_embed_data'); }

//NaCl Specific
function GetiFrameModuleVar() { return g_frame_embed.contentDocument.getElementById('id_embed_nacl_module'); }
function IsUsingNaCl() { return false; /*window.chrome;*/ }
</script>

<script src="./utils.js"></script>
<script src="./type_dictionnary.js"></script>
<script type="text/javascript">
var EasyMeshDict = new TypeDictionnary("EasyMesh");
function GetCmdDictionnary() { return EasyMeshDict; }
</script>
<script src="./easy_mesh_dictionnary.js"></script>
<script src="./nacl_loading.js"></script>

<script type="text/javascript">
//Base init for all datas
function Init()
function VarInit()
{
//Init frame variable first.
g_frame_embed = document.getElementById('id_frame_embed');
@@ -141,8 +142,14 @@ progress::-webkit-progress-value
g_div_progress = document.getElementById('id_div_progress');
g_div_progress_status = document.getElementById('id_div_progress_status');
g_progress_bar = document.getElementById('id_progress_bar');
}

//Pulg here any cookie update
//Base init
function Init()
{
VarInit();

//Put here any cookie update
if (!g_txtarea_code_src.value)
g_txtarea_code_src.value = "//This is a comment\nsc#f8f afcb 1 1 1 0";

@@ -166,6 +173,17 @@ progress::-webkit-progress-value
g_div_alphabet.innerHTML += new_toc + ']&nbsp;<br>&nbsp;';
}

//NaCl Specific
if (IsUsingNaCl())
{
DynLoadFile("nacl_loading.js");
g_frame_embed.src = 'meshviewer_nacl.html';
}
else
g_frame_embed.src = 'meshviewer_em.html';

g_frame_embed.onload = function() { VarInit(); }

//Tick has been done, start Tick
window.setTimeout("Tick()", 200);
}
@@ -184,7 +202,7 @@ progress::-webkit-progress-value

<body>

<h1>Mesh Viewer : Native Client version.</h1>
<h1>Mesh Viewer : Web version.</h1>

<p>
<div id="final_div">
@@ -196,7 +214,7 @@ progress::-webkit-progress-value
<div id="id_div_progress_status">....</div>&nbsp;
</div>
<div id="id_div_frame_embed">
<iframe onload="Init(); PageDidLoad();" id="id_frame_embed" src="meshviewer_nacl.html" width=770 height=200 frameborder=0 scrolling=no></iframe>
<iframe onload="Init();" id="id_frame_embed" src="empty.html" width=770 height=200 frameborder=0 scrolling=no></iframe>
</div>
</div>
</div>


+ 13
- 35
test/nacl_loading.js 查看文件

@@ -2,12 +2,16 @@ g_status_text = [null];
g_status_timer = [-1.0];
g_var_progress_bar = -1;

//window.setTimeout("RegisterListener()", 200);
g_embed_nacl_module = null;

if (IsUsingNaCl()) NaClLoadingInit();

function InitNaClModuleVar() { g_embed_nacl_module = GetiFrameModuleVar(); }

function RegisterListener()
{
//Register all the correct functions to the listener
var div_listener = GetNaClListenerDiv();
var div_listener = GetiFrameDivEmbed();
if (div_listener)
{
div_listener.addEventListener('loadstart', ModuleStartedLoad, true);
@@ -26,10 +30,11 @@ function RegisterListener()
// MODULE LOADING FUNCTIONS
//-------------------------------------------------------------------------
//Indicate page has been loaded.
function PageDidLoad()
function NaClLoadingInit()
{
HideProgressStatus(false);
//Page did load before NaCl module
if (!GetNaClModuleVar())
if (!g_embed_nacl_module)
AddTextStatus('Please wait for module loading');
RegisterListener();
}
@@ -69,7 +74,7 @@ function ModuleLoadUpdate(event)
//Indicate module load success.
function ModuleDidLoad()
{
if (!GetNaClModuleVar())
if (!g_embed_nacl_module)
InitNaClModuleVar();

//Hide the progress div
@@ -104,34 +109,6 @@ function RestartModule()
HideProgressStatus(false);
window.setTimeout('GetFrameData().contentDocument.location.reload(true)', 1000);
}
/*
var div_embed_data = GetDivEmbedData();
var div_embed_data_save = GetDivEmbedDataSave();

if (div_embed_data)
{
HideProgressStatus(false);

div_embed_data_save = div_embed_data.innerHTML;
div_embed_data.innerHTML = '';
}
*/
}

//Called after the Restart to effectively do it
function RestartModuleRestoreEmbed()
{
/*
var div_embed_data = GetDivEmbedData();
var div_embed_data_save = GetDivEmbedDataSave();

if (div_embed_data)
{
div_embed_data.innerHTML = div_embed_data_save;
div_embed_data_save = '';
HideProgressStatus(false);
}
*/
}

//-------------------------------------------------------------------------
@@ -147,8 +124,8 @@ function ModuleSentMessage(message)
//Called by the "Send Mesh Command !" button
function SendMessageToModule()
{
if (GetNaClModuleVar())
GetNaClModuleVar().postMessage(GetTextAreaCodeSrc().value);
if (g_embed_nacl_module)
g_embed_nacl_module.postMessage(GetTextAreaCodeSrc().value);
else
alert("Module not loaded !");
}
@@ -230,3 +207,4 @@ function HideProgressStatus(should_hide)
}
}
}


+ 47
- 0
test/utils.js 查看文件

@@ -0,0 +1,47 @@
function DynLoadFile(filename)
{
var filetype = filename.match(/\.[a-zA-Z]+$/);
//if filename is a external JavaScript file
if (filetype == ".js")
{
var fileref = document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", filename);
}
//if filename is an external CSS file
else if (filetype == ".css")
{
var fileref = document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", filename);
}
if (fileref)
document.getElementsByTagName("head")[0].appendChild(fileref);
}

function DynRemoveFile(filename)
{
var filetype = filename.match(/\.[a-zA-Z]+$/);
var targetelement = "none";
var targetattr = "none";
//Determine element type to create nodelist from and corresponding attribute to test for
if (filetype==".js")
{
targetelement = "script";
targetattr = "src";
}
else if (filetype == ".css")
{
targetelement = "link";
targetattr = "href";
}

var allsuspects = document.getElementsByTagName(targetelement);
//Search backwards within nodelist for matching elements to remove
for (var i = allsuspects.length; i >= 0; i--)
if (allsuspects[i] &&
allsuspects[i].getAttribute(targetattr) &&
allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1)
allsuspects[i].parentNode.removeChild(allsuspects[i]); //remove element by calling parentNode.removeChild()
}

Loading…
取消
儲存