diff options
author | Valerio Virgillito | 2012-05-22 14:47:17 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-05-22 14:47:17 -0700 |
commit | b3e85f609f704d668c8022c53418f8056bc71260 (patch) | |
tree | 122197204fff1b8adccfc089d6e6869e8c310550 /assets/canvas-runtime.js | |
parent | 9b6da637d9654727426c6d78f17e3804bbd84ce5 (diff) | |
parent | c5dad8ddc94b2e1c80565dfee072bda88e8880da (diff) | |
download | ninja-b3e85f609f704d668c8022c53418f8056bc71260.tar.gz |
Merge pull request #250 from joseeight/Document
Montage components mapping & External data webGL support
Diffstat (limited to 'assets/canvas-runtime.js')
-rw-r--r-- | assets/canvas-runtime.js | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js index eeafaab6..9bf22313 100644 --- a/assets/canvas-runtime.js +++ b/assets/canvas-runtime.js | |||
@@ -8,9 +8,37 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
8 | var NinjaCvsRt = NinjaCvsRt || {}; | 8 | var NinjaCvsRt = NinjaCvsRt || {}; |
9 | 9 | ||
10 | /////////////////////////////////////////////////////////////////////// | 10 | /////////////////////////////////////////////////////////////////////// |
11 | //Loading webGL/canvas data on window load | ||
12 | window.addEventListener('load', loadCanvasData, false); | ||
13 | //Load data function (on document loaded) | ||
14 | function loadCanvasData (e) { | ||
15 | //Cleaning up events | ||
16 | window.removeEventListener('load', loadCanvasData, false); | ||
17 | //Getting tag with data, MUST contain attribute | ||
18 | var xhr, tag = document.querySelectorAll(['script[data-ninja-canvas-lib]'])[0]; | ||
19 | //Checking for data to be external file | ||
20 | if (tag.getAttribute('data-ninja-canvas-json') !== null) { | ||
21 | //Loading JSON data | ||
22 | xhr = new XMLHttpRequest(); | ||
23 | xhr.open("GET", tag.getAttribute('data-ninja-canvas-json'), false); | ||
24 | xhr.send(); | ||
25 | //Checking for data | ||
26 | if (xhr.readyState === 4) { | ||
27 | //Calling method to initialize all webGL/canvas(es) | ||
28 | NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), xhr.response); | ||
29 | } else { | ||
30 | //TODO: Add error for users | ||
31 | } | ||
32 | } else {//Data in document itself | ||
33 | //Calling method to initialize all webGL/canvas(es) | ||
34 | NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), document.querySelectorAll(['script[data-ninja-canvas]'])[0].innerHTML); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | /////////////////////////////////////////////////////////////////////// | ||
11 | //Loading webGL/canvas data | 39 | //Loading webGL/canvas data |
12 | NinjaCvsRt.initWebGl = function (rootElement, directory) { | 40 | NinjaCvsRt.initWebGl = function (rootElement, directory, data) { |
13 | var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace('(', '')).replace(')', '')); | 41 | var cvsDataMngr, ninjaWebGlData = JSON.parse((data.replace('(', '')).replace(')', '')); |
14 | if (ninjaWebGlData && ninjaWebGlData.data) { | 42 | if (ninjaWebGlData && ninjaWebGlData.data) { |
15 | for (var n=0; ninjaWebGlData.data[n]; n++) { | 43 | for (var n=0; ninjaWebGlData.data[n]; n++) { |
16 | ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]); | 44 | ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]); |