aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/io-mediator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r--js/mediators/io-mediator.js47
1 files changed, 42 insertions, 5 deletions
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 }