aboutsummaryrefslogtreecommitdiff
path: root/js/document/mediators
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-06-07 14:44:10 -0700
committerJose Antonio Marquez2012-06-07 14:44:10 -0700
commit1698e3b0c99ff972da61d915074f1f7f1646f641 (patch)
treeba290cfdf6e8cd675eb23ed7daab86439172c4f1 /js/document/mediators
parent8da49b093e01a62c5b2009da075c2ccd2b1b6f5a (diff)
downloadninja-1698e3b0c99ff972da61d915074f1f7f1646f641.tar.gz
Adding support for html and head tags attributes
Both on open and close, Chrome randomly changes order of attributes, so this is browser induced bug.
Diffstat (limited to 'js/document/mediators')
-rwxr-xr-xjs/document/mediators/template.js47
1 files changed, 37 insertions, 10 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 {