From 77c0f0b369d431f6824906c91753b934f749c5d8 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 15 May 2012 11:15:27 -0700 Subject: Finalizing open for new banner templates Moving to implement save. --- js/document/views/design.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'js') diff --git a/js/document/views/design.js b/js/document/views/design.js index 4c91ff39..48c91aad 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -160,16 +160,23 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { value: function (e) { //Getting first element in DOM (assumes it's root) //TODO: Ensure wrapper logic is proper - var banner = this._bodyFragment.getElementsByTagName('*')[2], - ninjaBanner = this.document.body.getElementsByTagName('ninja-content')[0]; - //Copying attributes to maintain same properties as the banner root + var wrapper = this._bodyFragment.getElementsByTagName('*')[1], + banner = this._bodyFragment.getElementsByTagName('*')[2], + ninjaBanner = this.document.body.getElementsByTagName('ninja-content')[0], + ninjaWrapper = this.document.body.getElementsByTagName('ninja-viewport')[0]; + //Copying attributes to maintain same properties as the banner wrapper + for (var n in wrapper.attributes) { + if (wrapper.attributes[n].value) { + ninjaWrapper.setAttribute(wrapper.attributes[n].name, wrapper.attributes[n].value); + } + } + //Copying attributes to maintain same properties as the banner content for (var n in banner.attributes) { if (banner.attributes[n].value) { ninjaBanner.setAttribute(banner.attributes[n].name, banner.attributes[n].value); } } //Adjusting margin per size of document - //this.document.head.getElementsByTagName('style')[0].innerHTML += '\n ninja-banner {overflow: visible !important; margin-top: -'+Math.floor(this._template.size.height/2)+'px; margin-left: -'+Math.floor(this._template.size.width/2)+'px}'; this.document.head.getElementsByTagName('style')[0].innerHTML += '\n ninja-content {overflow: visible !important;} ninja-content, ninja-viewport {width: ' + this._template.size.width + 'px; height: ' + this._template.size.height + 'px;}'; //Setting content in template ninjaBanner.innerHTML = banner.innerHTML; @@ -204,7 +211,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { //Removing event, only needed on initial load this._observer.body.disconnect(); this._observer.body = null; - //Removing loading container + //Removing loading container (should be removed) this.document.body.removeChild(this.document.getElementsByTagName('ninjaloadinghack')[0]); //Getting style and link tags in document var stags = this.document.getElementsByTagName('style'), @@ -218,8 +225,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { for (i = 0; i < ltags.length; i++) { // if (ltags[i].href) { - //TODO: Verify this works for tags in body as well (working in head) - this.document.head.insertBefore(this.getStyleTagFromCssFile(ltags[i]), ltags[i]) || this.document.body.insertBefore(this.getStyleTagFromCssFile(ltags[i]), ltags[i]); + //Inseting + + + + \ No newline at end of file diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 7a905fc6..696a69dc 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -77,7 +77,7 @@ exports.IoMediator = Montage.create(Component, { //TODO: Improve template data injection function parseTemplate (content, template) { // - if (template.name.toLowerCase() === 'banner') { + if (template.name.toLowerCase() === 'banner' || template.name.toLowerCase() === 'animation') { //Getting dimensions of banner var dimensions = template.id.split('x'); dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'}; -- cgit v1.2.3 From bffc9b2a4bd3480a6e369a36660ce402f7e16aba Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 15 May 2012 12:01:37 -0700 Subject: File save for banner template Adding file save for templates, completing I/O. --- js/document/models/base.js | 2 ++ js/mediators/io-mediator.js | 47 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 8 deletions(-) (limited to 'js') 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, { file: this.file, webgl: this.webGlHelper.glData, styles: this.getStyleSheets(), + template: this.fileTemplate, document: this.views.design.iframe.contentWindow.document, head: this.views.design.iframe.contentWindow.document.head, body: this.views.design.iframe.contentWindow.document.body @@ -165,6 +166,7 @@ exports.BaseDocumentModel = Montage.create(Component, { file: this.file, webgl: this.webGlHelper.glData, css: this.getStyleSheets(), + template: this.fileTemplate, document: this.views.design.iframe.contentWindow.document, head: this.views.design.iframe.contentWindow.document.head, 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, { switch (doc.mode) { case 'html': //Getting content from function to properly handle saving assets (as in external if flagged) - contents = this.parseNinjaTemplateToHtml(doc); + if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) { + contents = this.parseNinjaTemplateToHtml(doc, true); + } else { + contents = this.parseNinjaTemplateToHtml(doc); + } break; default: contents = doc.content; @@ -214,7 +218,7 @@ exports.IoMediator = Montage.create(Component, { //TODO: Expand to allow more templates, clean up variables parseNinjaTemplateToHtml: { enumerable: false, - value: function (template) { + value: function (template, ninjaWrapper) { var regexRootUrl, rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])); regexRootUrl = new RegExp(rootUrl.replace(/\//gi, '\\\/'), 'gi'); //Injecting head and body into old document @@ -446,7 +450,11 @@ exports.IoMediator = Montage.create(Component, { webglrdgetag.setAttribute('type', 'text/javascript'); webglrdgetag.setAttribute('src', rdgeDirName + '/rdge-compiled.js'); webglrdgetag.setAttribute('data-ninja-webgl-rdge', 'true'); - template.file.content.document.head.appendChild(webglrdgetag); + if (ninjaWrapper) { + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webglrdgetag); + } else { + template.file.content.document.head.appendChild(webglrdgetag); + } } // if (!webgllibtag) { @@ -454,20 +462,32 @@ exports.IoMediator = Montage.create(Component, { webgllibtag.setAttribute('type', 'text/javascript'); webgllibtag.setAttribute('src', rdgeDirName + '/canvas-runtime.js'); webgllibtag.setAttribute('data-ninja-webgl-lib', 'true'); - template.file.content.document.head.appendChild(webgllibtag); + if (ninjaWrapper) { + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgllibtag); + } else { + template.file.content.document.head.appendChild(webgllibtag); + } } // if (!webgltag) { webgltag = template.file.content.document.createElement('script'); webgltag.setAttribute('data-ninja-webgl', 'true'); - template.file.content.document.head.appendChild(webgltag); + if (ninjaWrapper) { + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgltag); + } else { + template.file.content.document.head.appendChild(webgltag); + } } //TODO: Remove this tag and place inside JS file if (!webgljstag) { webgljstag = template.file.content.document.createElement('script'); webgljstag.setAttribute('type', 'text/javascript'); webgljstag.setAttribute('data-ninja-webgl-js', 'true'); - template.file.content.document.head.appendChild(webgljstag); + if (ninjaWrapper) { + template.file.content.document.body.getElementsByTagName('ninja-content')[0].appendChild(webgljstag); + } else { + template.file.content.document.head.appendChild(webgljstag); + } } //TODO: Decide if this should be over-writter or only written on creation var rootElement = 'document.body'; //TODO: Set actual root element @@ -549,10 +569,15 @@ for (var m in template.mjs) { - + //Cleaning URLs from HTML - 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)); + var cleanHTML; + if (ninjaWrapper) { + 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)); + } else { + 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)); + } // function parseNinjaRootUrl(url) { if (url.indexOf(this.application.ninja.coreIoApi.rootUrl) !== -1) { @@ -561,6 +586,12 @@ for (var m in template.mjs) { return url; } } + // + if (ninjaWrapper) { + cleanHTML = cleanHTML.replace(/ninja-viewport/gi, 'div'); + cleanHTML = cleanHTML.replace(/ninja-content/gi, 'div'); + } + // return this.getPrettyHtml(cleanHTML.replace(this.getAppTemplatesUrlRegEx(), '')); } -- cgit v1.2.3 From 374ab6d8980b810a1c943b14a1aea07cb85389ad Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 15 May 2012 13:26:07 -0700 Subject: Saving body attributes --- js/mediators/io-mediator.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index aa2165c7..8346c75e 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -224,8 +224,14 @@ exports.IoMediator = Montage.create(Component, { //Injecting head and body into old document template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); - - + //Copying attributes to maintain same properties as the + for (var n in template.body.attributes) { + if (template.body.attributes[n].value) { + // + template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); + } + } + //TODO: Add attribute copying for and /* //Testing using montage clean up method -- cgit v1.2.3