aboutsummaryrefslogtreecommitdiff
path: root/js/document
diff options
context:
space:
mode:
authorJonathan Duran2012-06-11 10:12:08 -0700
committerJonathan Duran2012-06-11 10:12:08 -0700
commit6a3b09433b8d5894a0f2a6c00748825727c2d991 (patch)
tree377cd68e0580172bc234059dbd4482c964d49bd4 /js/document
parent79cbc26904a7fbd7a846f48da6c026a91221ba93 (diff)
parentbad5a44824ba35cbc7f4f4d245e32b90208f00c1 (diff)
downloadninja-6a3b09433b8d5894a0f2a6c00748825727c2d991.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'js/document')
-rwxr-xr-xjs/document/document-html.js14
-rwxr-xr-xjs/document/helpers/webgl-helper.js14
-rwxr-xr-xjs/document/mediators/template.js100
-rwxr-xr-xjs/document/models/base.js78
-rwxr-xr-xjs/document/models/html.js50
-rwxr-xr-xjs/document/templates/banner/index.html24
-rwxr-xr-xjs/document/templates/html/index.html27
-rwxr-xr-xjs/document/views/design.js92
8 files changed, 276 insertions, 123 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js
index 33a41a8e..04565753 100755
--- a/js/document/document-html.js
+++ b/js/document/document-html.js
@@ -68,6 +68,8 @@ exports.HtmlDocument = Montage.create(Component, {
68 if (this.model.views.design.initialize(this.model.parentContainer)) { 68 if (this.model.views.design.initialize(this.model.parentContainer)) {
69 //Hiding iFrame, just initiliazing 69 //Hiding iFrame, just initiliazing
70 this.model.views.design.hide(); 70 this.model.views.design.hide();
71 //Setting the iFrame property for reference in helper class
72 this.model.webGlHelper.iframe = this.model.views.design.iframe;
71 } else { 73 } else {
72 //ERROR: Design View not initialized 74 //ERROR: Design View not initialized
73 } 75 }
@@ -82,13 +84,13 @@ exports.HtmlDocument = Montage.create(Component, {
82 this.model.views.design.iframe.style.opacity = 0; 84 this.model.views.design.iframe.style.opacity = 0;
83 this.model.views.design.content = this.model.file.content; 85 this.model.views.design.content = this.model.file.content;
84 //TODO: Improve reference (probably through binding values) 86 //TODO: Improve reference (probably through binding values)
85 this.model.views.design.model = this.model; 87 this.model.views.design._webGlHelper = this.model.webGlHelper;
86 //Rendering design view, using observers to know when template is ready 88 //Rendering design view, using observers to know when template is ready
87 this.model.views.design.render(function () { 89 this.model.views.design.render(function () {
88 //Adding observer to know when template is ready 90 //Adding observer to know when template is ready
89 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); 91 this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this));
90 this._observer.observe(this.model.views.design.document.head, {childList: true}); 92 this._observer.observe(this.model.views.design.document.head, {childList: true});
91 }.bind(this), template); 93 }.bind(this), template, {viewCallback: this.handleViewReady, context: this});
92 } else { 94 } else {
93 //TODO: Identify default view (probably code) 95 //TODO: Identify default view (probably code)
94 } 96 }
@@ -101,10 +103,14 @@ exports.HtmlDocument = Montage.create(Component, {
101 //Removing observer, only needed on initial load 103 //Removing observer, only needed on initial load
102 this._observer.disconnect(); 104 this._observer.disconnect();
103 this._observer = null; 105 this._observer = null;
104 //Making callback after view is loaded
105 this.loaded.callback.call(this.loaded.context, this);
106 } 106 }
107 }, 107 },
108 handleViewReady: {
109 value: function() {
110 //Making callback after view is loaded
111 this.loaded.callback.call(this.loaded.context, this);
112 }
113 },
108 //////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////
109 // 115 //
110 closeDocument: { 116 closeDocument: {
diff --git a/js/document/helpers/webgl-helper.js b/js/document/helpers/webgl-helper.js
index 84ddc547..6d9ced14 100755
--- a/js/document/helpers/webgl-helper.js
+++ b/js/document/helpers/webgl-helper.js
@@ -40,7 +40,7 @@ exports.webGlDocumentHelper = Montage.create(Component, {
40 if (elt) { 40 if (elt) {
41 var matLib = MaterialsModel.exportMaterials(); 41 var matLib = MaterialsModel.exportMaterials();
42 this._glData = [matLib]; 42 this._glData = [matLib];
43 this.collectGLData(elt, this._glData ); 43 this.collectGLData(this.iframe.contentWindow.document, this._glData );
44 } else { 44 } else {
45 this._glData = null 45 this._glData = null
46 } 46 }
@@ -97,10 +97,6 @@ exports.webGlDocumentHelper = Montage.create(Component, {
97 // 97 //
98 if (canvas) { 98 if (canvas) {
99 // 99 //
100 if (!canvas.elementModel) {
101 NJUtils.makeElementModel(canvas, "Canvas", "shape", true);
102 }
103 //
104 if (canvas.elementModel) { 100 if (canvas.elementModel) {
105 if (canvas.elementModel.shapeModel.GLWorld) { 101 if (canvas.elementModel.shapeModel.GLWorld) {
106 canvas.elementModel.shapeModel.GLWorld.clearTree(); 102 canvas.elementModel.shapeModel.GLWorld.clearTree();
@@ -194,6 +190,13 @@ exports.webGlDocumentHelper = Montage.create(Component, {
194 // 190 //
195 collectGLData: { 191 collectGLData: {
196 value: function( elt, dataArray ) { 192 value: function( elt, dataArray ) {
193 Array.prototype.slice.call(elt.querySelectorAll('[data-RDGE-id]'),0).forEach(function(glCanvas) {
194 dataArray.push(glCanvas.elementModel.shapeModel.GLWorld.exportJSON());
195 });
196
197 // Removing the old loop that went through all the elements.
198 // TODO: Remove the following code once QE has tested it.
199/*
197 // 200 //
198 var i, data, nKids, child; 201 var i, data, nKids, child;
199 // 202 //
@@ -209,6 +212,7 @@ exports.webGlDocumentHelper = Montage.create(Component, {
209 this.collectGLData( child, dataArray ); 212 this.collectGLData( child, dataArray );
210 } 213 }
211 } 214 }
215 */
212 } 216 }
213 } 217 }
214 //////////////////////////////////////////////////////////////////// 218 ////////////////////////////////////////////////////////////////////
diff --git a/js/document/mediators/template.js b/js/document/mediators/template.js
index 068a1f48..4c72314a 100755
--- a/js/document/mediators/template.js
+++ b/js/document/mediators/template.js
@@ -8,7 +8,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component, 10 Component = require("montage/ui/component").Component,
11 TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator; 11 TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator,
12 ClassUuid = require("js/components/core/class-uuid").ClassUuid;
12//////////////////////////////////////////////////////////////////////// 13////////////////////////////////////////////////////////////////////////
13// 14//
14exports.TemplateDocumentMediator = Montage.create(Component, { 15exports.TemplateDocumentMediator = Montage.create(Component, {
@@ -83,9 +84,24 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
83 parseHtmlToNinjaTemplate: { 84 parseHtmlToNinjaTemplate: {
84 value: function (html) { 85 value: function (html) {
85 //Creating temp object to mimic HTML 86 //Creating temp object to mimic HTML
86 var doc = window.document.implementation.createHTMLDocument(), template; 87 var doc = window.document.implementation.createHTMLDocument(), template, docHtmlTag,
88 hackHtml = document.createElement('html'), hackTag;
87 //Setting content to temp 89 //Setting content to temp
88 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 if (hackTag) {
97 for (var m in hackTag.attributes) {
98 if (hackTag.attributes[m].value) {
99 docHtmlTag.setAttribute(hackTag.attributes[m].name.replace(/ninjahtmlhack/gi, 'html'), hackTag.attributes[m].value.replace(/ninjahtmlhack/gi, 'html'));
100 }
101 }
102 }
103 //Garbage collection
104 hackHtml = hackTag = null;
89 //Creating return object 105 //Creating return object
90 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc}; 106 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc};
91 } 107 }
@@ -93,7 +109,7 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
93 //////////////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////////////
94 //TODO: Expand to allow more templates, clean up variables 110 //TODO: Expand to allow more templates, clean up variables
95 parseNinjaTemplateToHtml: { 111 parseNinjaTemplateToHtml: {
96 value: function (template, ninjaWrapper, libCopyCallback) { 112 value: function (saveExternalData, template, ninjaWrapper, libCopyCallback) {
97 //TODO: Improve reference for rootUrl 113 //TODO: Improve reference for rootUrl
98 var regexRootUrl, 114 var regexRootUrl,
99 rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])), 115 rootUrl = this.application.ninja.coreIoApi.rootUrl + escape((this.application.ninja.documentController.documentHackReference.root.split(this.application.ninja.coreIoApi.cloudData.root)[1])),
@@ -116,20 +132,36 @@ exports.TemplateDocumentMediator = Montage.create(Component, {
116 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, ''); 132 template.file.content.document.head.innerHTML = template.head.innerHTML.replace(regexRootUrl, '');
117 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, ''); 133 template.file.content.document.body.innerHTML = template.body.innerHTML.replace(regexRootUrl, '');
118 } 134 }
135 //Removes all attributes from node
136 function wipeAttributes (node) {
137 for (var f in node.attributes) {
138 node.removeAttribute(node.attributes[f].name);
139 }
140 }
119 //Copying attributes to maintain same properties as the <body> 141 //Copying attributes to maintain same properties as the <body>
142 wipeAttributes(template.file.content.document.body);
120 for (var n in template.body.attributes) { 143 for (var n in template.body.attributes) {
121 if (template.body.attributes[n].value) { 144 if (template.body.attributes[n].value) {
122 //
123 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);
124 } 146 }
125 } 147 }
126 148 wipeAttributes(template.file.content.document.head);
127 149 //Copying attributes to maintain same properties as the <head>
128 150 for (var m in template.document.head.attributes) {
129 //TODO: Add attribute copying for <HEAD> and <HTML> 151 if (template.document.head.attributes[m].value) {
130 152 template.file.content.document.head.setAttribute(template.document.head.attributes[m].name, template.document.head.attributes[m].value);
131 153 }
132 154 }