From 9a87513929290b6f84a090b4b4cca8fab0f2ab81 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 24 Feb 2012 14:51:29 -0800 Subject: Added import/export of RDGE data This is only the IO aspect, the data getter seems broken for 2D canvas and does not allow for save, and nothing works for setting the data on load. However, the IO aspect of saving and opening the data are not incorporated. --- js/document/html-document.js | 29 ++++++++++++++++++++++++--- js/mediators/io-mediator.js | 47 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/js/document/html-document.js b/js/document/html-document.js index 6394e3ce..ca1b0886 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -162,15 +162,15 @@ exports.HTMLDocument = Montage.create(TextDocument, { cdm.collectGLData( elt, this._glData ); } - return this._glData + return this._glData; }, set: function(value) { - var elt = this.iframe.contentWindow.document.getElementById("UserContent"); + var elt = this.documentRoot; if (elt) { - console.log( "load canvas data: " + value ); + console.log( "load canvas data: " , value ); var cdm = new CanvasDataManager(); cdm.loadGLData(elt, value); } @@ -374,6 +374,25 @@ exports.HTMLDocument = Montage.create(TextDocument, { //Inserting user's document into template this._templateDocument.head.innerHTML = this._userDocument.content.head; this._templateDocument.body.innerHTML = this._userDocument.content.body; + //TODO: Use querySelectorAll + var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata; + // + for (var w in scripttags) { + if (scripttags[w].getAttribute) { + if (scripttags[w].getAttribute('data-ninja-webgl') !== null) { + //TODO: Add logic to handle more than one data tag + webgldata = JSON.parse((scripttags[w].innerHTML.replace("(", "")).replace(")", "")); + } + } + } + // + if (webgldata) { + for (var n=0; webgldata.data[n]; n++) { + webgldata.data[n] = unescape(webgldata.data[n]); + } + this._templateDocument.webgl = webgldata.data; + } + //Adding a handler for the main user document reel to finish loading this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); @@ -487,6 +506,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { this.callback(this); + //Setting webGL data + if (this._templateDocument.webgl) { + this.glData = this._templateDocument.webgl; + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index c4f3b361..e5eb1fc6 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -195,11 +195,10 @@ exports.IoMediator = Montage.create(Component, { } }, //////////////////////////////////////////////////////////////////// - //TODO: Expand to allow more templates + //TODO: Expand to allow more templates, clean up variables parseNinjaTemplateToHtml: { enumerable: false, value: function (template) { - //TODO: Clean up variables //Injecting head and body into old document template.document.content.document.body.innerHTML = template.body; template.document.content.document.head.innerHTML = template.head; @@ -210,7 +209,7 @@ exports.IoMediator = Montage.create(Component, { //Looping through link tags and removing file recreated elements for (var j in styletags) { if (styletags[j].getAttribute) { - if(styletags[j].getAttribute('ninjauri') !== null) { + if(styletags[j].getAttribute('ninjauri') !== null) {//TODO: Use querySelectorAll try { //Checking head first template.document.content.document.head.removeChild(styletags[j]); @@ -228,7 +227,7 @@ exports.IoMediator = Montage.create(Component, { } //TODO: Add logic to only enble tags we disabled for (var l in linktags) { - if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) { + if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {//TODO: Use querySelectorAll linktags[l].removeAttribute('disabled'); } } @@ -259,7 +258,7 @@ exports.IoMediator = Montage.create(Component, { for(var i in template.css) { if (template.css[i].ownerNode) { if (template.css[i].ownerNode.getAttribute) { - if (template.css[i].ownerNode.getAttribute('ninjauri') === null) { + if (template.css[i].ownerNode.getAttribute('ninjauri') === null) {//TODO: Use querySelectorAll //Inseting data from rules array into