aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/document/html-document.js29
-rw-r--r--js/mediators/io-mediator.js47
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, {
162 cdm.collectGLData( elt, this._glData ); 162 cdm.collectGLData( elt, this._glData );
163 } 163 }
164 164
165 return this._glData 165 return this._glData;
166 }, 166 },
167 167
168 set: function(value) 168 set: function(value)
169 { 169 {
170 var elt = this.iframe.contentWindow.document.getElementById("UserContent"); 170 var elt = this.documentRoot;
171 if (elt) 171 if (elt)
172 { 172 {
173 console.log( "load canvas data: " + value ); 173 console.log( "load canvas data: " , value );
174 var cdm = new CanvasDataManager(); 174 var cdm = new CanvasDataManager();
175 cdm.loadGLData(elt, value); 175 cdm.loadGLData(elt, value);
176 } 176 }
@@ -374,6 +374,25 @@ exports.HTMLDocument = Montage.create(TextDocument, {
374 //Inserting user's document into template 374 //Inserting user's document into template
375 this._templateDocument.head.innerHTML = this._userDocument.content.head; 375 this._templateDocument.head.innerHTML = this._userDocument.content.head;
376 this._templateDocument.body.innerHTML = this._userDocument.content.body; 376 this._templateDocument.body.innerHTML = this._userDocument.content.body;
377 //TODO: Use querySelectorAll
378 var scripttags = this._templateDocument.html.getElementsByTagName('script'), webgldata;
379 //
380 for (var w in scripttags) {
381 if (scripttags[w].getAttribute) {
382 if (scripttags[w].getAttribute('data-ninja-webgl') !== null) {
383 //TODO: Add logic to handle more than one data tag
384 webgldata = JSON.parse((scripttags[w].innerHTML.replace("(", "")).replace(")", ""));
385 }
386 }
387 }
388 //
389 if (webgldata) {
390 for (var n=0; webgldata.data[n]; n++) {
391 webgldata.data[n] = unescape(webgldata.data[n]);
392 }
393 this._templateDocument.webgl = webgldata.data;
394 }
395
377 396
378 //Adding a handler for the main user document reel to finish loading 397 //Adding a handler for the main user document reel to finish loading
379 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false); 398 this._document.body.addEventListener("userTemplateDidLoad", this.userTemplateDidLoad.bind(this), false);
@@ -487,6 +506,10 @@ exports.HTMLDocument = Montage.create(TextDocument, {
487 506
488 this.callback(this); 507 this.callback(this);
489 508
509 //Setting webGL data
510 if (this._templateDocument.webgl) {
511 this.glData = this._templateDocument.webgl;
512 }
490 } 513 }
491 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 514 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
492 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 515 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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, {
195 } 195 }
196 }, 196 },
197 //////////////////////////////////////////////////////////////////// 197 ////////////////////////////////////////////////////////////////////
198 //TODO: Expand to allow more templates 198 //TODO: Expand to allow more templates, clean up variables
199 parseNinjaTemplateToHtml: { 199 parseNinjaTemplateToHtml: {
200 enumerable: false, 200 enumerable: false,
201 value: function (template) { 201 value: function (template) {
202 //TODO: Clean up variables
203 //Injecting head and body into old document 202 //Injecting head and body into old document
204 template.document.content.document.body.innerHTML = template.body; 203 template.document.content.document.body.innerHTML = template.body;
205 template.document.content.document.head.innerHTML = template.head; 204 template.document.content.document.head.innerHTML = template.head;
@@ -210,7 +209,7 @@ exports.IoMediator = Montage.create(Component, {
210 //Looping through link tags and removing file recreated elements 209 //Looping through link tags and removing file recreated elements
211 for (var j in styletags) { 210 for (var j in styletags) {
212 if (styletags[j].getAttribute) { 211 if (styletags[j].getAttribute) {
213 if(styletags[j].getAttribute('ninjauri') !== null) { 212 if(styletags[j].getAttribute('ninjauri') !== null) {//TODO: Use querySelectorAll
214 try { 213 try {
215 //Checking head first 214 //Checking head first
216 template.document.content.document.head.removeChild(styletags[j]); 215 template.document.content.document.head.removeChild(styletags[j]);
@@ -228,7 +227,7 @@ exports.IoMediator = Montage.create(Component, {
228 } 227 }
229 //TODO: Add logic to only enble tags we disabled 228 //TODO: Add logic to only enble tags we disabled
230 for (var l in linktags) { 229 for (var l in linktags) {
231 if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) { 230 if (linktags[l].getAttribute && linktags[l].getAttribute('disabled')) {//TODO: Use querySelectorAll
232 linktags[l].removeAttribute('disabled'); 231 linktags[l].removeAttribute('disabled');
233 } 232 }
234 } 233 }
@@ -259,7 +258,7 @@ exports.IoMediator = Montage.create(Component, {
259 for(var i in template.css) { 258 for(var i in template.css) {
260 if (template.css[i].ownerNode) { 259 if (template.css[i].ownerNode) {
261 if (template.css[i].ownerNode.getAttribute) { 260 if (template.css[i].ownerNode.getAttribute) {
262 if (template.css[i].ownerNode.getAttribute('ninjauri') === null) { 261 if (template.css[i].ownerNode.getAttribute('ninjauri') === null) {//TODO: Use querySelectorAll
263 //Inseting data from rules array into <style> as string 262 //Inseting data from rules array into <style> as string
264 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules); 263 docStyles[styleCounter].innerHTML = this.getCssFromRules(template.css[i].cssRules);
265 styleCounter++; 264 styleCounter++;
@@ -271,6 +270,44 @@ exports.IoMediator = Montage.create(Component, {
271 } 270 }
272 } 271 }
273 } 272 }
273 //Checking for webGL elements in document
274 if (template.webgl.length) {
275 //
276 var json, matchingtags = [], webgltag, scripts = template.document.content.document.getElementsByTagName('script');
277 //
278 for (var i in scripts) {
279 if (scripts[i].getAttribute) {
280 if (scripts[i].getAttribute('data-ninja-webgl') !== null) {//TODO: Use querySelectorAll
281 matchingtags.push(scripts[i]);
282 }
283 }
284 }
285 //
286 if (matchingtags.length) {
287 if (matchingtags.length === 1) {
288 webgltag = matchingtags[0];
289 } else {
290 //TODO: Add logic to handle multiple tags, perhaps combine to one
291 webgltag = matchingtags[matchingtags.length-1]; //Saving all data to last one...
292 }
293 }
294 //
295 if (!webgltag) {
296 webgltag = template.document.content.document.createElement('script');
297 webgltag.setAttribute('data-ninja-webgl', 'true');
298 template.document.content.document.head.appendChild(webgltag);
299 }
300 //
301 json = '\n\t\t({\n\t\t\t"version": "X.X.X.X",\n\t\t\t"data": [';
302 //
303 for (var j=0; template.webgl[j]; j++) {
304 json += '\n\t\t\t\t"'+escape(template.webgl[j])+'"';
305 }
306 //
307 json += ']\n\t\t})\n\t';
308 //
309 webgltag.innerHTML = json;
310 }
274 // 311 //
275 return template.document.content.document.documentElement.outerHTML.replace(url, ''); 312 return template.document.content.document.documentElement.outerHTML.replace(url, '');
276 } 313 }