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