diff options
-rwxr-xr-x | js/document/models/base.js | 2 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 47 |
2 files changed, 41 insertions, 8 deletions
diff --git a/js/document/models/base.js b/js/document/models/base.js index 0f58e75c..5f2a5893 100755 --- a/js/document/models/base.js +++ b/js/document/models/base.js | |||
@@ -138,6 +138,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
138 | file: this.file, | 138 | file: this.file, |
139 | webgl: this.webGlHelper.glData, | 139 | webgl: this.webGlHelper.glData, |
140 | styles: this.getStyleSheets(), | 140 | styles: this.getStyleSheets(), |
141 | template: this.fileTemplate, | ||
141 | document: this.views.design.iframe.contentWindow.document, | 142 | document: this.views.design.iframe.contentWindow.document, |
142 | head: this.views.design.iframe.contentWindow.document.head, | 143 | head: this.views.design.iframe.contentWindow.document.head, |
143 | body: this.views.design.iframe.contentWindow.document.body | 144 | body: this.views.design.iframe.contentWindow.document.body |
@@ -165,6 +166,7 @@ exports.BaseDocumentModel = Montage.create(Component, { | |||
165 | file: this.file, | 166 | file: this.file, |
166 | webgl: this.webGlHelper.glData, | 167 | webgl: this.webGlHelper.glData, |
167 | css: this.getStyleSheets(), | 168 | css: this.getStyleSheets(), |
169 | template: this.fileTemplate, | ||
168 | document: this.views.design.iframe.contentWindow.document, | 170 | document: this.views.design.iframe.contentWindow.document, |
169 | head: this.views.design.iframe.contentWindow.document.head, | 171 | head: this.views.design.iframe.contentWindow.document.head, |
170 | body: this.views.design.iframe.contentWindow.document.body | 172 | body: this.views.design.iframe.contentWindow.document.body |
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 696a69dc..aa2165c7 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -169,7 +169,11 @@ exports.IoMediator = Montage.create(Component, { | |||
169 | switch (doc.mode) { | 169 | switch (doc.mode) { |
170 | case 'html': | 170 | case 'html': |
171 | //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) |
172 | 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 | } | ||
173 | break; | 177 | break; |
174 | default: | 178 | default: |
175 | contents = doc.content; | 179 | contents = doc.content; |
@@ -214,7 +218,7 @@ exports.IoMediator = Montage.create(Component, { | |||
214 | //TODO: Expand to allow more templates, clean up variables | 218 | //TODO: Expand to allow more templates, clean up variables |
215 | parseNinjaTemplateToHtml: { | 219 | parseNinjaTemplateToHtml: { |
216 | enumerable: false, | 220 | enumerable: false, |
217 | value: function (template) { | 221 | value: function (template, ninjaWrapper) { |
218 | 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])); |
219 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); | 223 | regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); |
220 | //Injecting head and body into old document | 224 | //Injecting head and body into old document |
@@ -446,7 +450,11 @@ exports.IoMediator = Montage.create(Component, { | |||
446 | webglrdgetag.setAttribute('type', 'text/javascript'); | 450 | webglrdgetag.setAttribute('type', 'text/javascript'); |
447 | webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); | 451 | webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); |
448 | webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); | 452 | webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); |
449 | template.file.content.document.head.appendChild(webglrdgetag); | 453 | if (ninjaWrapper) { |
454 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); | ||
455 | } else { | ||
456 | template.file.content.document.head.appendChild(webglrdgetag); | ||
457 | } | ||
450 | } | 458 | } |
451 | // | 459 | // |
452 | if (!webgllibtag) { | 460 | if (!webgllibtag) { |
@@ -454,20 +462,32 @@ exports.IoMediator = Montage.create(Component, { | |||
454 | webgllibtag.setAttribute('type', 'text/javascript'); | 462 | webgllibtag.setAttribute('type', 'text/javascript'); |
455 | webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); | 463 | webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); |
456 | webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); | 464 | webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); |
457 | template.file.content.document.head.appendChild(webgllibtag); | 465 | if (ninjaWrapper) { |
466 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); | ||
467 | } else { | ||
468 | template.file.content.document.head.appendChild(webgllibtag); | ||
469 | } | ||
458 | } | 470 | } |
459 | // | 471 | // |
460 | if (!webgltag) { | 472 | if (!webgltag) { |
461 | webgltag = template.file.content.document.createElement('script'); | 473 | webgltag = template.file.content.document.createElement('script'); |
462 | webgltag.setAttribute('data-ninja-webgl', 'true'); | 474 | webgltag.setAttribute('data-ninja-webgl', 'true'); |
463 | template.file.content.document.head.appendChild(webgltag); | 475 | if (ninjaWrapper) { |
476 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag); | ||
477 | } else { | ||
478 | template.file.content.document.head.appendChild(webgltag); | ||
479 | } | ||
464 | } | 480 | } |
465 | //TODO: Remove this tag and place inside JS file | 481 | //TODO: Remove this tag and place inside JS file |
466 | if (!webgljstag) { | 482 | if (!webgljstag) { |
467 | webgljstag = template.file.content.document.createElement('script'); | 483 | webgljstag = template.file.content.document.createElement('script'); |
468 | webgljstag.setAttribute('type', 'text/javascript'); | 484 | webgljstag.setAttribute('type', 'text/javascript'); |
469 | webgljstag.setAttribute('data-ninja-webgl-js', 'true'); | 485 | webgljstag.setAttribute('data-ninja-webgl-js', 'true'); |
470 | template.file.content.document.head.appendChild(webgljstag); | 486 | if (ninjaWrapper) { |
487 | template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgljstag); | ||
488 | } else { | ||
489 | template.file.content.document.head.appendChild(webgljstag); | ||
490 | } | ||
471 | } | 491 | } |
472 | //TODO: Decide if this should be over-writter or only written on creation | 492 | //TODO: Decide if this should be over-writter or only written on creation |
473 | var rootElement = 'document.body'; //TODO: Set actual root element | 493 | var rootElement = 'document.body'; //TODO: Set actual root element |
@@ -549,10 +569,15 @@ for (var m in template.mjs) { | |||
549 | 569 | ||
550 | 570 | ||
551 | 571 | ||
552 | 572 | ||
553 | 573 | ||
554 | //Cleaning URLs from HTML | 574 | //Cleaning URLs from HTML |
555 | 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)); | 575 | var cleanHTML; |
576 | if (ninjaWrapper) { | ||
577 | 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)); | ||
578 | } else { | ||
579 | 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)); | ||
580 | } | ||
556 | // | 581 | // |
557 | function parseNinjaRootUrl(url) { | 582 | function parseNinjaRootUrl(url) { |
558 | if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { | 583 | if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { |
@@ -562,6 +587,12 @@ for (var m in template.mjs) { | |||
562 | } | 587 | } |
563 | } | 588 | } |
564 | // | 589 | // |
590 | if (ninjaWrapper) { | ||
591 | cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div'); | ||
592 | cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div'); | ||
593 | } | ||
594 | |||
595 | // | ||
565 | return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); | 596 | return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); |
566 | } | 597 | } |
567 | }, | 598 | }, |