aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xjs/document/mediators/template.js47
-rwxr-xr-xjs/document/views/design.js14
2 files changed, 50 insertions, 11 deletions
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js
index c9d46f79..5692ca2d 100755
--- a/js/document/mediators/template.js
+++ b/js/document/mediators/template.js
@@ -84,9 +84,22 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
84 parseHtmlToNinjaTemplate: { 84 parseHtmlToNinjaTemplate: {
85 value: function (html) { 85 value: function (html) {
86 //Creating temp object to mimic HTML 86 //Creating temp object to mimic HTML
87 var doc = window.document.implementation.createHTMLDocument(), template; 87 var doc = window.document.implementation.createHTMLDocument(), template, docHtmlTag,
88 hackHtml = document.createElement('html'), hackTag;
88 //Setting content to temp 89 //Setting content to temp
89 doc.getElementsByTagName('html')[0].innerHTML = html; 90 doc.getElementsByTagName('html')[0].innerHTML = html;
91 //TODO: Improve this, very bad way of copying attributes (in a pinch to get it working)
92 hackHtml.innerHTML = html.replace(/html/gi, 'ninjahtmlhack');
93 hackTag = hackHtml.getElementsByTagName('ninjahtmlhack')[0];
94 docHtmlTag = doc.getElementsByTagName('html')[0];
95 //Looping through the attributes to copy them
96 for (var m in hackTag.attributes) {
97 if (hackTag.attributes[m].value) {
98 docHtmlTag.setAttribute(hackTag.attributes[m].name.replace(/ninjahtmlhack/gi, 'html'), hackTag.attributes[m].value.replace(/ninjahtmlhack/gi, 'html'));
99 }
100 }
101 //Garbage collection
102 hackHtml = hackTag = null;
90 //Creating return object 103 //Creating return object
91 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc}; 104 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc};
92 } 105 }
@@ -117,20 +130,34 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
117 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); 130 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, '');
118 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); 131 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, '');
119 } 132 }
133 //Removes all attributes from node
134 function wipeAttributes (node) {
135 for (var f in node.attributes) {
136 node.removeAttribute(node.attributes[f].name);
137 }
138 }
120 //Copying attributes to maintain same properties as the <body> 139 //Copying attributes to maintain same properties as the <body>
140 wipeAttributes(template.file.content.document.body);
121 for (var n in template.body.attributes) { 141 for (var n in template.body.attributes) {
122 if (template.body.attributes[n].value) { 142 if (template.body.attributes[n].value) {
123 //
124 template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value); 143 template.file.content.document.body.setAttribute(template.body.attributes[n].name, template.body.attributes[n].value);
125 } 144 }
126 } 145 }
127 146 wipeAttributes(template.file.content.document.head);
128 147 //Copying attributes to maintain same properties as the <head>
129 148 for (var m in template.document.head.attributes) {
130 //TODO: Add attribute copying for <HEAD> and <HTML> 149 if (template.document.head.attributes[m].value) {
131 150 template.file.content.document.head.setAttribute(template.document.head.attributes[m].name, template.document.head.attributes[m].value);
132 151 }
133 152 }
153 //Copying attributes to maintain same properties as the <html>
154 var htmlTagMem = template.document.getElementsByTagName('html')[0], htmlTagDoc = template.file.content.document.getElementsByTagName('html')[0];
155 wipeAttributes(htmlTagDoc);
156 for (var m in htmlTagMem.attributes) {
157 if (htmlTagMem.attributes[m].value) {
158 htmlTagDoc.setAttribute(htmlTagMem.attributes[m].name, htmlTagMem.attributes[m].value.replace(/ montage-app-bootstrapping/gi, ''));
159 }
160 }
134 //Getting list of current nodes (Ninja DOM) 161 //Getting list of current nodes (Ninja DOM)
135 presentNodes = template.file.content.document.getElementsByTagName('*'); 162 presentNodes = template.file.content.document.getElementsByTagName('*');
136 //Looping through nodes to determine origin and removing if not inserted by Ninja 163 //Looping through nodes to determine origin and removing if not inserted by Ninja
@@ -370,7 +397,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
370 var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1, fileOrgDataSrc; 397 var rdgeDirName, rdgeVersion, cvsDataDir = this.getCanvasDirectory(template.file.root), fileCvsDir, fileCvsDirAppend, cvsDirCounter = 1, fileOrgDataSrc;
371 // 398 //
372 if (cvsDataDir && !matchingtags.length && !webgllibtag) { 399 if (cvsDataDir && !matchingtags.length && !webgllibtag) {
373 400
374 if (template.libs.canvasId) { 401 if (template.libs.canvasId) {
375 libsobserver.canvasId = template.libs.canvasId; 402 libsobserver.canvasId = template.libs.canvasId;
376 } else { 403 } else {
diff --git a/js/document/views/design.js b/js/document/views/design.js
index 3d11e138..1a5b071e 100755
--- a/js/document/views/design.js
+++ b/js/document/views/design.js
@@ -204,7 +204,19 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
204 this.document.body.setAttribute(this.content.document.body.attributes[n].name, this.content.document.body.attributes[n].value); 204 this.document.body.setAttribute(this.content.document.body.attributes[n].name, this.content.document.body.attributes[n].value);
205 } 205 }
206 } 206 }
207 //TODO: Add attribute copying for <HEAD> and <HTML> 207 //Copying attributes to maintain same properties as the <head>
208 for (var m in this.content.document.head.attributes) {
209 if (this.content.document.head.attributes[m].value) {
210 this.document.head.setAttribute(this.content.document.head.attributes[m].name, this.content.document.head.attributes[m].value);
211 }
212 }
213 //Copying attributes to maintain same properties as the <html>
214 var htmlTagMem = this.content.document.getElementsByTagName('html')[0], htmlTagDoc = this.document.getElementsByTagName('html')[0];
215 for (var m in htmlTagMem.attributes) {
216 if (htmlTagMem.attributes[m].value) {
217 htmlTagDoc.setAttribute(htmlTagMem.attributes[m].name, htmlTagMem.attributes[m].value);
218 }
219 }
208 } 220 }
209 } 221 }
210 }, 222 },