Mercurial > hg > orthanc-stone
annotate Samples/WebAssembly/app.js @ 1037:4e713ef78a5a
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 18:01:03 +0200 |
parents | d71cf8504159 |
children |
rev | line source |
---|---|
831
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * This is a generic bootstrap code that is shared by all the Stone |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * sample applications. |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 **/ |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 // Check support for WebAssembly |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 if (!('WebAssembly' in window)) { |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 alert('Sorry, your browser does not support WebAssembly :('); |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 } else { |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 // Wait for the module to be loaded (the event "WebAssemblyLoaded" |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 // must be emitted by the "main" function) |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 window.addEventListener('WebAssemblyLoaded', function() { |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 // Loop over the GET arguments |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 var parameters = window.location.search.substr(1); |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 if (parameters != null && parameters != '') { |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 var tokens = parameters.split('&'); |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 for (var i = 0; i < tokens.length; i++) { |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 var arg = tokens[i].split('='); |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 if (arg.length == 2) { |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 // Send each GET argument to WebAssembly |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 Module.ccall('SetArgument', null, [ 'string', 'string' ], |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 [ arg[0], decodeURIComponent(arg[1]) ]); |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 } |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 } |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 } |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 // Inform the WebAssembly module that it can start |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 Module.ccall('Initialize', null, null, null); |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 }); |
d71cf8504159
handling of GET arguments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 } |