From 11a5be59ff80e0672e9ecf36679be28effb7696c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 21 May 2012 18:28:38 -0700 Subject: Modifying Canvas Data I/O Changing methods to save all data to external files, this will be optional for the user. Currently save will only save to external files, but UI will allow user to save in file. Need to implement loading data on file open for external file, only works for in file currently. Modified the Runtime file to load all data itself to not bulk up the user document. --- assets/canvas-runtime.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'assets') 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 @@ -7,10 +7,38 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot // namespace for the Ninja Canvas Runtime var NinjaCvsRt = NinjaCvsRt || {}; +/////////////////////////////////////////////////////////////////////// +//Loading webGL/canvas data on window load +window.addEventListener('load', loadCanvasData, false); +//Load data function (on document loaded) +function loadCanvasData (e) { + //Cleaning up events + window.removeEventListener('load', loadCanvasData, false); + //Getting tag with data, MUST contain attribute + var xhr, tag = document.querySelectorAll(['script[data-ninja-canvas-lib]'])[0]; + //Checking for data to be external file + if (tag.getAttribute('data-ninja-canvas-json') !== null) { + //Loading JSON data + xhr = new XMLHttpRequest(); + xhr.open("GET", tag.getAttribute('data-ninja-canvas-json'), false); + xhr.send(); + //Checking for data + if (xhr.readyState === 4) { + //Calling method to initialize all webGL/canvas(es) + NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), xhr.response); + } else { + //TODO: Add error for users + } + } else {//Data in document itself + //Calling method to initialize all webGL/canvas(es) + NinjaCvsRt.initWebGl(document.body, tag.getAttribute('data-ninja-canvas-libpath'), document.querySelectorAll(['script[data-ninja-canvas]'])[0].innerHTML); + } +} + /////////////////////////////////////////////////////////////////////// //Loading webGL/canvas data -NinjaCvsRt.initWebGl = function (rootElement, directory) { - var cvsDataMngr, ninjaWebGlData = JSON.parse((document.querySelectorAll(['script[data-ninja-webgl]'])[0].innerHTML.replace('(', '')).replace(')', '')); +NinjaCvsRt.initWebGl = function (rootElement, directory, data) { + var cvsDataMngr, ninjaWebGlData = JSON.parse((data.replace('(', '')).replace(')', '')); if (ninjaWebGlData && ninjaWebGlData.data) { for (var n=0; ninjaWebGlData.data[n]; n++) { ninjaWebGlData.data[n] = unescape(ninjaWebGlData.data[n]); -- cgit v1.2.3