diff options
Diffstat (limited to 'js/mediators')
-rw-r--r-- | js/mediators/io-mediator.js | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index c9c7203f..8346c75e 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -77,13 +77,14 @@ exports.IoMediator = Montage.create(Component, { | |||
77 | //TODO: Improve template data injection | 77 | //TODO: Improve template data injection |
78 | function parseTemplate (content, template) { | 78 | function parseTemplate (content, template) { |
79 | // | 79 | // |
80 | if (template.name.toLowerCase() === 'banner') { | 80 | if (template.name.toLowerCase() === 'banner' || template.name.toLowerCase() === 'animation') { |
81 | //Getting dimensions of banner | 81 | //Getting dimensions of banner |
82 | var dimensions = template.id.split('x'); | 82 | var dimensions = template.id.split('x'); |
83 | dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'}; | 83 | dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'}; |
84 | // | 84 | // |
85 | content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id); | 85 | content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id); |
86 | content = content.replace(/ninja-banner {}/gi, "ninja-banner {overflow: hidden; width: "+dimensions.width+"; height: "+dimensions.height+"}"); | 86 | content = content.replace(/ninja-banner {}/gi, "ninja-banner {overflow: visible; width: "+dimensions.width+"; height: "+dimensions.height+"}"); |
87 | content = content.replace(/ninja-content-wrapper {}/gi, "ninja-content-wrapper {overflow: hidden; width: "+dimensions.width+"; height: "+dimensions.height+"}"); | ||
87 | } | 88 | } |
88 | // | 89 | // |
89 | return content; | 90 | return content; |
@@ -168,7 +169,11 @@ exports.IoMediator = Montage.create(Component, { | |||
168 | switch (doc.mode) { | 169 | switch (doc.mode) { |
169 | case 'html': | 170 | case 'html': |
170 | //Getting content from function to properly handle saving assets (as in external if flagged) | 171 | //Getting content from function to properly handle saving assets (as in external if flagged) |
171 | contents = this.parseNinjaTemplateToHtml(doc); | 172 | if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) { |
173 | contents = this.parseNinjaTemplateToHtml(doc, true); | ||
174 | } else { | ||
175 | contents = this.parseNinjaTemplateToHtml(doc); | ||
176 | } | ||
172 | break; | 177 | break; |
173 | default: | 178 | default: |
174 | contents = doc.content; | 179 | contents = doc.content; |
@@ -213,14 +218,20 @@ exports.IoMediator = Montage.create(Component, { | |||
213 | //TODO: Expand to allow more templates, clean up variables | 218 | //TODO: Expand to allow more templates, clean up variables |
214 | parseNinjaTemplateToHtml: { | 219 | parseNinjaTemplateToHtml: { |
215 | enumerable: false, | 220 | enumerable: false, |
216 | value: function (template) { | 221 | value: function (template, ninjaWrapper) { |
217 | var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); | 222 | var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); |
218 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); | 223 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); |
219 | //Injecting head and body into old document | 224 | //Injecting head and body into old document |
220 | template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); | 225 | template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); |
221 | template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); | 226 | template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); |
222 | 227 | //Copying attributes to maintain same properties as the <body> | |
223 | 228 | for (var n in template.body.attributes) { | |
229 | if (template.body.attributes[n].value) { | ||
230 | // | ||
231 | template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); | ||
232 | } | ||
233 | } | ||
234 | //TODO: Add attribute copying for <HEAD> and <HTML> | ||
224 | 235 | ||
225 | /* | 236 | /* |
226 | //Testing using montage clean up method | 237 | //Testing using montage clean up method |
@@ -445,7 +456,11 @@ exports.IoMediator = Montage.create(Component, { | |||
445 | webglrdgetag.setAttribute('type', 'text/javascript'); | 456 | webglrdgetag.setAttribute('type', 'text/javascript'); |
446 | webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); | 457 | webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); |
447 | webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); | 458 | webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); |
448 | template.file.content.document.head.appendChild(webglrdgetag); | 459 | if (ninjaWrapper) { |
460 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); | ||
461 | } else { | ||
462 | template.file.content.document.head.appendChild(webglrdgetag); | ||
463 | } | ||
449 | } | 464 | } |
450 | // | 465 | // |
451 | if (!webgllibtag) { | 466 | if (!webgllibtag) { |
@@ -453,20 +468,32 @@ exports.IoMediator = Montage.create(Component, { | |||
453 | webgllibtag.setAttribute('type', 'text/javascript'); | 468 | webgllibtag.setAttribute('type', 'text/javascript'); |
454 | webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); | 469 | webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); |
455 | webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); | 470 | webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); |
456 | template.file.content.document.head.appendChild(webgllibtag); | 471 | if (ninjaWrapper) { |
472 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); | ||
473 | } else { | ||
474 | template.file.content.document.head.appendChild(webgllibtag); | ||
475 | } | ||
457 | } | 476 | } |
458 | // | 477 | // |
459 | if (!webgltag) { | 478 | if (!webgltag) { |
460 | webgltag = template.file.content.document.createElement('script'); | 479 | webgltag = template.file.content.document.createElement('script'); |
461 | webgltag.setAttribute('data-ninja-webgl', 'true'); | 480 | webgltag.setAttribute('data-ninja-webgl', 'true'); |
462 | template.file.content.document.head.appendChild(webgltag); | 481 | if (ninjaWrapper) { |
482 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag); | ||
483 | } else { | ||
484 | template.file.content.document.head.appendChild(webgltag); | ||
485 | } | ||
463 | } | 486 | } |
464 | //TODO: Remove this tag and place inside JS file | 487 | //TODO: Remove this tag and place inside JS file |
465 | if (!webgljstag) { | 488 | if (!webgljstag) { |
466 | webgljstag = template.file.content.document.createElement('script'); | 489 | webgljstag = template.file.content.document.createElement('script'); |
467 | webgljstag.setAttribute('type', 'text/javascript'); | 490 | webgljstag.setAttribute('type', 'text/javascript'); |
468 | webgljstag.setAttribute('data-ninja-webgl-js', 'true'); | 491 | webgljstag.setAttribute('data-ninja-webgl-js', 'true'); |
469 | template.file.content.document.head.appendChild(webgljstag); | 492 | if (ninjaWrapper) { |
493 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgljstag); | ||
494 | } else { | ||
495 | template.file.content.document.head.appendChild(webgljstag); | ||
496 | } | ||
470 | } | 497 | } |
471 | //TODO: Decide if this should be over-writter or only written on creation | 498 | //TODO: Decide if this should be over-writter or only written on creation |
472 | var rootElement = 'document.body'; //TODO: Set actual root element | 499 | var rootElement = 'document.body'; //TODO: Set actual root element |
@@ -548,10 +575,15 @@ for (var m in template.mjs) { | |||
548 | 575 | ||
549 | 576 | ||
550 | 577 | ||
551 | 578 | ||
552 | 579 | ||
553 | //Cleaning URLs from HTML | 580 | //Cleaning URLs from HTML |
554 | var cleanHTML = template.file.content.document.documentElement.outerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this)); | 581 | var cleanHTML; |
582 | if (ninjaWrapper) { | ||
583 | cleanHTML = template.file.content.document.body.innerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this)); | ||
584 | } else { | ||
585 | cleanHTML = template.file.content.document.documentElement.outerHTML.replace(/(\b(?:(?:https?|ftp|file|[A-Za-z]+):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/gi, parseNinjaRootUrl.bind(this)); | ||
586 | } | ||
555 | // | 587 | // |
556 | function parseNinjaRootUrl(url) { | 588 | function parseNinjaRootUrl(url) { |
557 | if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { | 589 | if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { |
@@ -561,6 +593,12 @@ for (var m in template.mjs) { | |||
561 | } | 593 | } |
562 | } | 594 | } |
563 | // | 595 | // |
596 | if (ninjaWrapper) { | ||
597 | cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div'); | ||
598 | cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div'); | ||
599 | } | ||
600 | |||
601 | // | ||
564 | return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); | 602 | return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); |
565 | } | 603 | } |
566 | }, | 604 | }, |