aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorJonathan Duran2012-06-18 08:34:58 -0700
committerJonathan Duran2012-06-18 08:34:58 -0700
commitf8f7754ff19a8d2bc7f66fbaa3feb13082076dc5 (patch)
tree1169413a30c74b87e973cbd2c77e1b6f90c762d0 /js/document
parent0639b36bd4dc9c4c7659b87c05a22a08a4c49221 (diff)
parente570fc8518cf03dd03c15982edcf17c5ba0a293d (diff)
downloadninja-f8f7754ff19a8d2bc7f66fbaa3feb13082076dc5.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/mediators/template.js33
-rwxr-xr-xjs/document/views/design.js21
2 files changed, 50 insertions, 4 deletions
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js
index 50fad1c3..c5b46c3a 100755
--- a/js/document/mediators/template.js
+++ b/js/document/mediators/template.js
@@ -145,6 +145,29 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
145 template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); 145 template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value);
146 } 146 }
147 } 147 }
148 //
149 if(template.template) {
150 //
151 // TODO - Need to handle banner and animation templates.
152 //Copying attributes to maintain same properties as <ninja-content>
153 var ninjaContentTagMem = template.document.getElementsByTagName('ninja-content')[0], ninjaContentTagDoc = template.file.content.document.getElementsByTagName('ninja-content')[0];
154 if (ninjaContentTagMem && ninjaContentTagMem.getAttribute('data-ninja-style') !== null) {
155 ninjaContentTagDoc.setAttribute('style', ninjaContentTagMem.getAttribute('data-ninja-style'));
156 ninjaContentTagDoc.removeAttribute('data-ninja-style');
157 } else if (ninjaContentTagMem && ninjaContentTagMem.getAttribute('data-ninja-style') === null) {
158 ninjaContentTagDoc.removeAttribute('style');
159 ninjaContentTagDoc.removeAttribute('data-ninja-style');
160 }
161 } else {
162 if (template.body && template.body.getAttribute('data-ninja-style') !== null) {
163 template.file.content.document.body.setAttribute('style', template.body.getAttribute('data-ninja-style'));
164 template.file.content.document.body.removeAttribute('data-ninja-style');
165 } else if (template.body && template.body.getAttribute('data-ninja-style') === null) {
166 template.file.content.document.body.removeAttribute('style');
167 template.file.content.document.body.removeAttribute('data-ninja-style');
168 }
169 }
170
148 wipeAttributes(template.file.content.document.head); 171 wipeAttributes(template.file.content.document.head);
149 //Copying attributes to maintain same properties as the <head> 172 //Copying attributes to maintain same properties as the <head>
150 for (var m in template.document.head.attributes) { 173 for (var m in template.document.head.attributes) {
@@ -155,6 +178,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
155 //Copying attributes to maintain same properties as the <html> 178 //Copying attributes to maintain same properties as the <html>
156 var htmlTagMem = template.document.getElementsByTagName('html')[0], htmlTagDoc = template.file.content.document.getElementsByTagName('html')[0]; 179 var htmlTagMem = template.document.getElementsByTagName('html')[0], htmlTagDoc = template.file.content.document.getElementsByTagName('html')[0];
157 wipeAttributes(htmlTagDoc); 180 wipeAttributes(htmlTagDoc);
181 //
158 for (var m in htmlTagMem.attributes) { 182 for (var m in htmlTagMem.attributes) {
159 if (htmlTagMem.attributes[m].value) { 183 if (htmlTagMem.attributes[m].value) {
160 if (htmlTagMem.attributes[m].value.replace(/montage-app-bootstrapping/gi, '').length>0) { 184 if (htmlTagMem.attributes[m].value.replace(/montage-app-bootstrapping/gi, '').length>0) {
@@ -162,10 +186,19 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
162 } 186 }
163 } 187 }
164 } 188 }
189 //
190 if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') !== null) {
191 htmlTagDoc.setAttribute('style', htmlTagMem.getAttribute('data-ninja-style'));
192 htmlTagDoc.removeAttribute('data-ninja-style');
193 } else if (htmlTagMem && htmlTagMem.getAttribute('data-ninja-style') === null) {
194 htmlTagDoc.removeAttribute('style');
195 htmlTagDoc.removeAttribute('data-ninja-style');
196 }
165 //Getting list of current nodes (Ninja DOM) 197 //Getting list of current nodes (Ninja DOM)
166 presentNodes = template.file.content.document.getElementsByTagName('*'); 198 presentNodes = template.file.content.document.getElementsByTagName('*');
167 //Looping through nodes to determine origin and removing if not inserted by Ninja 199 //Looping through nodes to determine origin and removing if not inserted by Ninja
168 for (var n in presentNodes) { 200 for (var n in presentNodes) {
201 //
169 if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) { 202 if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') === null) {
170 toremovetags.push(presentNodes[n]); 203 toremovetags.push(presentNodes[n]);
171 } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) { 204 } else if (presentNodes[n].getAttribute && presentNodes[n].getAttribute('data-ninja-node') !== null) {
diff --git a/js/document/views/design.js b/js/document/views/design.js
index 1a5b071e..44c61617 100755
--- a/js/document/views/design.js
+++ b/js/document/views/design.js
@@ -280,7 +280,9 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
280 //Removing loading container (should be removed) 280 //Removing loading container (should be removed)
281 this.document.body.removeChild(this.document.getElementsByTagName('ninjaloadinghack')[0]); 281 this.document.body.removeChild(this.document.getElementsByTagName('ninjaloadinghack')[0]);
282 //Getting style and link tags in document 282 //Getting style and link tags in document
283 var stags = this.document.getElementsByTagName('style'), 283 var htags = this.document.getElementsByTagName('html'),
284 userStyles,
285 stags = this.document.getElementsByTagName('style'),
284 ltags = this.document.getElementsByTagName('link'), i, orgNodes, 286 ltags = this.document.getElementsByTagName('link'), i, orgNodes,
285 scripttags = this.document.getElementsByTagName('script'); 287 scripttags = this.document.getElementsByTagName('script');
286 //Temporarily checking for disabled special case (we must enabled for Ninja to access styles) 288 //Temporarily checking for disabled special case (we must enabled for Ninja to access styles)
@@ -319,7 +321,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
319 //Else there is not data to parse 321 //Else there is not data to parse
320 if(this._viewCallback) { 322 if(this._viewCallback) {
321 this._viewCallback.viewCallback.call(this._viewCallback.context); 323 this._viewCallback.viewCallback.call(this._viewCallback.context);
322 } 324 }
323 } 325 }
324 //TODO: Verify appropiate location for this operation 326 //TODO: Verify appropiate location for this operation
325 if (this._template && this._template.type === 'banner') { 327 if (this._template && this._template.type === 'banner') {
@@ -335,8 +337,19 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
335 for (var n in orgNodes) { 337 for (var n in orgNodes) {
336 if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true'); 338 if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true');
337 } 339 }
338 340
339 //Makign callback if specified 341 // Save initial HTML and Body/ninja-content style attributes so we don't override them on save
342 if(htags.length) {
343 if(userStyles = htags[0].getAttribute('style')) {
344 htags[0].setAttribute('data-ninja-style', userStyles);
345 }
346 }
347 if(this.documentRoot) {
348 if(userStyles = this.documentRoot.getAttribute('style')) {
349 this.documentRoot.setAttribute('data-ninja-style', userStyles);
350 }
351 }
352 //Making callback if specified
340 if (this._callback) this._callback(); 353 if (this._callback) this._callback();
341 } 354 }
342 }, 355 },