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 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'js/document') 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; + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From c6b44313ff8bcc17835ca77793bf425c451a4e75 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sat, 25 Feb 2012 16:18:27 -0800 Subject: Cleaning up ninja-data attributes Added logic to load cross-domain CSS from CDN, but need to explore how to load without impacting permissions. --- js/document/html-document.js | 46 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 1901079d..4059c2a5 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -381,7 +381,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { // for (var k in this._document.styleSheets) { if (this._document.styleSheets[k].ownerNode && this._document.styleSheets[k].ownerNode.setAttribute) { - this._document.styleSheets[k].ownerNode.setAttribute('ninjatemplate', 'true'); + this._document.styleSheets[k].ownerNode.setAttribute('data-ninja-template', 'true'); } } // @@ -449,9 +449,10 @@ exports.HTMLDocument = Montage.create(TextDocument, { //Creating tag with file content tag = this.iframe.contentWindow.document.createElement('style'); tag.setAttribute('type', 'text/css'); - tag.setAttribute('ninjauri', fileUri); - tag.setAttribute('ninjafileurl', cssUrl); - tag.setAttribute('ninjafilename', cssUrl.split('/')[cssUrl.split('/').length-1]); + tag.setAttribute('data-ninja-uri', fileUri); + tag.setAttribute('data-ninja-file-url', cssUrl); + tag.setAttribute('data-ninja-file-read-only', JSON.parse(this.application.ninja.coreIoApi.isFileWritable({uri: fileUri}).content).readOnly); + tag.setAttribute('data-ninja-file-name', cssUrl.split('/')[cssUrl.split('/').length-1]); tag.innerHTML = cssData.content; //Looping through DOM to insert style tag at location of link element query = this._templateDocument.html.querySelectorAll(['link']); @@ -463,6 +464,43 @@ exports.HTMLDocument = Montage.create(TextDocument, { this._templateDocument.head.insertBefore(tag, query[j]); } } + } else { + //None local stylesheet, probably on a CDN (locked) + //this._document.styleSheets[i].href; + tag = this.iframe.contentWindow.document.createElement('style'); + tag.setAttribute('type', 'text/css'); + tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); + tag.setAttribute('data-ninja-file-read-only', "true"); + tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); + + + + //TODO: Figure out cross-domain XHR issue, might need cloud to handle + /* +var xhr = new XMLHttpRequest(); + xhr.open("GET", this._document.styleSheets[i].href, true); + xhr.send(); + // + if (xhr.readyState === 4) { + console.log(xhr); + } +*/ + + //TODO: Add rules content + //tag.innerHTML = xhr.responseText //xhr.response; + + + query = this._templateDocument.html.querySelectorAll(['link']); + for (var j in query) { + if (query[j].href === this._document.styleSheets[i].href) { + //Disabling style sheet to reload via inserting in style tag + query[j].setAttribute('disabled', 'true'); + //Inserting tag + this._templateDocument.head.insertBefore(tag, query[j]); + } + } + + } } } -- cgit v1.2.3 From d4ac479796f0341163e02ba50fa892773212a445 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sat, 25 Feb 2012 16:21:18 -0800 Subject: Cleaning up comments for external styles loading --- js/document/html-document.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 4059c2a5..472d15de 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -466,15 +466,12 @@ exports.HTMLDocument = Montage.create(TextDocument, { } } else { //None local stylesheet, probably on a CDN (locked) - //this._document.styleSheets[i].href; tag = this.iframe.contentWindow.document.createElement('style'); tag.setAttribute('type', 'text/css'); tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); tag.setAttribute('data-ninja-file-read-only', "true"); tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); - - //TODO: Figure out cross-domain XHR issue, might need cloud to handle /* var xhr = new XMLHttpRequest(); @@ -484,12 +481,12 @@ var xhr = new XMLHttpRequest(); if (xhr.readyState === 4) { console.log(xhr); } + //tag.innerHTML = xhr.responseText //xhr.response; */ - //TODO: Add rules content - //tag.innerHTML = xhr.responseText //xhr.response; - + //Currently no external styles will load if unable to load via XHR request + //Disabling external style sheets query = this._templateDocument.html.querySelectorAll(['link']); for (var j in query) { if (query[j].href === this._document.styleSheets[i].href) { @@ -499,8 +496,6 @@ var xhr = new XMLHttpRequest(); this._templateDocument.head.insertBefore(tag, query[j]); } } - - } } } -- cgit v1.2.3 From 3638492098a21aef63842366fbfc035fc6414fb0 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 26 Feb 2012 11:32:10 -0800 Subject: Fixed issue with losing track of Ninja template css Also cleaned up URL getter for app in cleaning string code. --- js/document/html-document.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/document') diff --git a/js/document/html-document.js b/js/document/html-document.js index 472d15de..76436732 100755 --- a/js/document/html-document.js +++ b/js/document/html-document.js @@ -465,7 +465,8 @@ exports.HTMLDocument = Montage.create(TextDocument, { } } } else { - //None local stylesheet, probably on a CDN (locked) + /* +//None local stylesheet, probably on a CDN (locked) tag = this.iframe.contentWindow.document.createElement('style'); tag.setAttribute('type', 'text/css'); tag.setAttribute('data-ninja-external-url', this._document.styleSheets[i].href); @@ -473,8 +474,7 @@ exports.HTMLDocument = Montage.create(TextDocument, { tag.setAttribute('data-ninja-file-name', this._document.styleSheets[i].href.split('/')[this._document.styleSheets[i].href.split('/').length-1]); //TODO: Figure out cross-domain XHR issue, might need cloud to handle - /* -var xhr = new XMLHttpRequest(); + var xhr = new XMLHttpRequest(); xhr.open("GET", this._document.styleSheets[i].href, true); xhr.send(); // @@ -482,7 +482,6 @@ var xhr = new XMLHttpRequest(); console.log(xhr); } //tag.innerHTML = xhr.responseText //xhr.response; -*/ //Currently no external styles will load if unable to load via XHR request @@ -496,6 +495,7 @@ var xhr = new XMLHttpRequest(); this._templateDocument.head.insertBefore(tag, query[j]); } } +*/ } } } -- cgit v1.2.3