From 9185145b3ab37070c7f32befaec1ab38486745b3 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 14 Jun 2012 16:00:53 -0700 Subject: Save user's html and body styles and inline body styles for 3d so they don't get saved out with the document. This still requires some changes by Jose. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/body-controller.js | 3 ++- js/document/views/design.js | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'js') diff --git a/js/controllers/elements/body-controller.js b/js/controllers/elements/body-controller.js index 27989c65..0ca6c417 100755 --- a/js/controllers/elements/body-controller.js +++ b/js/controllers/elements/body-controller.js @@ -13,7 +13,8 @@ exports.BodyController = Montage.create(ElementController, { set3DProperties: { value: function(el, props, update3DModel) { var dist = props["dist"], mat = props["mat"]; - this.application.ninja.stylesController.setElementStyle(el, "-webkit-transform", "perspective(" + dist + ") " + "matrix3d(" + MathUtils.scientificToDecimal(mat, 5) + ")"); +// this.application.ninja.stylesController.setElementStyle(el, "-webkit-transform", "perspective(" + dist + ") " + "matrix3d(" + MathUtils.scientificToDecimal(mat, 5) + ")"); + el.style["-webkit-transform"] = "perspective(" + dist + ") " + "matrix3d(" + MathUtils.scientificToDecimal(mat, 5) + ")"; el.elementModel.props3D.matrix3d = mat; el.elementModel.props3D.perspectiveDist = dist; diff --git a/js/document/views/design.js b/js/document/views/design.js index 1a5b071e..325259ea 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -280,7 +280,10 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { //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'), + var htags = this.document.getElementsByTagName('html'), + btags = this.document.getElementsByTagName('body'), + userStyles, + stags = this.document.getElementsByTagName('style'), ltags = this.document.getElementsByTagName('link'), i, orgNodes, scripttags = this.document.getElementsByTagName('script'); //Temporarily checking for disabled special case (we must enabled for Ninja to access styles) @@ -319,7 +322,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { //Else there is not data to parse if(this._viewCallback) { this._viewCallback.viewCallback.call(this._viewCallback.context); - } + } } //TODO: Verify appropiate location for this operation if (this._template && this._template.type === 'banner') { @@ -335,7 +338,18 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { for (var n in orgNodes) { if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true'); } - + + // Save initial HTML and Body style attributes so we don't override them on save + if(htags.length) { + if(userStyles = htags[0].getAttribute('style')) { + htags[0].setAttribute('data-ninja-style', userStyles); + } + } + if(btags.length) { + if(userStyles = btags[0].getAttribute('style')) { + btags[0].setAttribute('data-ninja-style', userStyles); + } + } //Makign callback if specified if (this._callback) this._callback(); } -- cgit v1.2.3 From 0d6693f1a6af1303e99ee72794eb879be8665610 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 14 Jun 2012 16:46:01 -0700 Subject: Adding clean up for ninja style attributes. I/O step in template. --- js/document/mediators/template.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'js') diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index 50fad1c3..0d48355f 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js @@ -155,6 +155,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, { //Copying attributes to maintain same properties as the var htmlTagMem = template.document.getElementsByTagName('html')[0], htmlTagDoc = template.file.content.document.getElementsByTagName('html')[0]; wipeAttributes(htmlTagDoc); + // for (var m in htmlTagMem.attributes) { if (htmlTagMem.attributes[m].value) { if (htmlTagMem.attributes[m].value.replace(/montage-app-bootstrapping/gi, '').length>0) { @@ -162,16 +163,33 @@ exports.TemplateDocumentMediator = Montage.create(Component, { } } } + // + if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') !== null) { + htmlTagDoc.setAttribute('style', htmlTagMem.getAttribute('data-ninja-style')); + htmlTagDoc.removeAttribute('data-ninja-style'); + } else if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') === null) { + htmlTagDoc.removeAttribute('style'); + htmlTagDoc.removeAttribute('data-ninja-style'); + } //Getting list of current nodes (Ninja DOM) presentNodes = template.file.content.document.getElementsByTagName('*'); //Looping through nodes to determine origin and removing if not inserted by Ninja for (var n in presentNodes) { + // if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { toremovetags.push(presentNodes[n]); } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { //Removing attribute presentNodes[n].removeAttribute('data-ninja-node'); } + // + if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-style') !== null) { + presentNodes[n].setAttribute('style', presentNodes[n].getAttribute('data-ninja-style')); + presentNodes[n].removeAttribute('data-ninja-style'); + } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-style') === null) { + presentNodes[n].removeAttribute('style'); + presentNodes[n].removeAttribute('data-ninja-style'); + } } //Getting all CSS (style or link) tags var styletags = template.file.content.document.getElementsByTagName('style'), -- cgit v1.2.3 From b39e13b9a53e6c75f4f9364e686dc90df02b09bb Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 14 Jun 2012 16:54:54 -0700 Subject: Moving location to copy body style attribute Fixes issue with removing styles from other elements. This now only applies to HTML and Body tags --- js/document/mediators/template.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'js') diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index 0d48355f..e770e07f 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js @@ -145,6 +145,14 @@ exports.TemplateDocumentMediator = Montage.create(Component, { template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); } } + // + if (template.body && template.body.getAttribute('data-ninja-style') !== null) { + template.file.content.document.body.setAttribute('style', template.body.getAttribute('data-ninja-style')); + template.file.content.document.body.removeAttribute('data-ninja-style'); + } else if (template.body && template.body.getAttribute('data-ninja-style') === null) { + template.file.content.document.body.removeAttribute('style'); + template.file.content.document.body.removeAttribute('data-ninja-style'); + } wipeAttributes(template.file.content.document.head); //Copying attributes to maintain same properties as the for (var m in template.document.head.attributes) { @@ -182,14 +190,6 @@ exports.TemplateDocumentMediator = Montage.create(Component, { //Removing attribute presentNodes[n].removeAttribute('data-ninja-node'); } - // - if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-style') !== null) { - presentNodes[n].setAttribute('style', presentNodes[n].getAttribute('data-ninja-style')); - presentNodes[n].removeAttribute('data-ninja-style'); - } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-style') === null) { - presentNodes[n].removeAttribute('style'); - presentNodes[n].removeAttribute('data-ninja-style'); - } } //Getting all CSS (style or link) tags var styletags = template.file.content.document.getElementsByTagName('style'), -- cgit v1.2.3 From 965557ffb8e11918ebc1215738a8a9657a172a84 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 14 Jun 2012 22:11:39 -0700 Subject: Remove ninja's author-time styles for banner and animation templates on publish/save. Missed the banner and animation case in the previous checkin. Signed-off-by: Nivesh Rajbhandari --- js/document/mediators/template.js | 29 ++++++++++++++++++++++------- js/document/views/design.js | 11 +++++------ 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'js') diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js index e770e07f..c5b46c3a 100755 --- a/js/document/mediators/template.js +++ b/js/document/mediators/template.js @@ -146,13 +146,28 @@ exports.TemplateDocumentMediator = Montage.create(Component, { } } // - if (template.body && template.body.getAttribute('data-ninja-style') !== null) { - template.file.content.document.body.setAttribute('style', template.body.getAttribute('data-ninja-style')); - template.file.content.document.body.removeAttribute('data-ninja-style'); - } else if (template.body && template.body.getAttribute('data-ninja-style') === null) { - template.file.content.document.body.removeAttribute('style'); - template.file.content.document.body.removeAttribute('data-ninja-style'); - } + if(template.template) { + // + // TODO - Need to handle banner and animation templates. + //Copying attributes to maintain same properties as + var ninjaContentTagMem = template.document.getElementsByTagName('ninja-content')[0], ninjaContentTagDoc = template.file.content.document.getElementsByTagName('ninja-content')[0]; + if (ninjaContentTagMem && ninjaContentTagMem.getAttribute('data-ninja-style') !== null) { + ninjaContentTagDoc.setAttribute('style', ninjaContentTagMem.getAttribute('data-ninja-style')); + ninjaContentTagDoc.removeAttribute('data-ninja-style'); + } else if (ninjaContentTagMem && ninjaContentTagMem.getAttribute('data-ninja-style') === null) { + ninjaContentTagDoc.removeAttribute('style'); + ninjaContentTagDoc.removeAttribute('data-ninja-style'); + } + } else { + if (template.body && template.body.getAttribute('data-ninja-style') !== null) { + template.file.content.document.body.setAttribute('style', template.body.getAttribute('data-ninja-style')); + template.file.content.document.body.removeAttribute('data-ninja-style'); + } else if (template.body && template.body.getAttribute('data-ninja-style') === null) { + template.file.content.document.body.removeAttribute('style'); + template.file.content.document.body.removeAttribute('data-ninja-style'); + } + } + wipeAttributes(template.file.content.document.head); //Copying attributes to maintain same properties as the for (var m in template.document.head.attributes) { diff --git a/js/document/views/design.js b/js/document/views/design.js index 325259ea..44c61617 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -281,7 +281,6 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { this.document.body.removeChild(this.document.getElementsByTagName('ninjaloadinghack')[0]); //Getting style and link tags in document var htags = this.document.getElementsByTagName('html'), - btags = this.document.getElementsByTagName('body'), userStyles, stags = this.document.getElementsByTagName('style'), ltags = this.document.getElementsByTagName('link'), i, orgNodes, @@ -339,18 +338,18 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true'); } - // Save initial HTML and Body style attributes so we don't override them on save + // Save initial HTML and Body/ninja-content style attributes so we don't override them on save if(htags.length) { if(userStyles = htags[0].getAttribute('style')) { htags[0].setAttribute('data-ninja-style', userStyles); } } - if(btags.length) { - if(userStyles = btags[0].getAttribute('style')) { - btags[0].setAttribute('data-ninja-style', userStyles); + if(this.documentRoot) { + if(userStyles = this.documentRoot.getAttribute('style')) { + this.documentRoot.setAttribute('data-ninja-style', userStyles); } } - //Makign callback if specified + //Making callback if specified if (this._callback) this._callback(); } }, -- cgit v1.2.3