aboutsummaryrefslogtreecommitdiff
path: root/js/document/views
diff options
context:
space:
mode:
authorPushkar Joshi2012-06-11 14:07:13 -0700
committerPushkar Joshi2012-06-11 14:07:13 -0700
commit71bc93ad0d53a77d70c688b2b3aacf694dd1de91 (patch)
treea432a4652bf7c96aea72a22bf27946eeee8fc4a5 /js/document/views
parent76db3eb0aa4ffe9e75812db570c793e9f852f853 (diff)
parent756cbfad2b98b300af8db3793aa21718b88dd950 (diff)
downloadninja-71bc93ad0d53a77d70c688b2b3aacf694dd1de91.tar.gz
Merge branch 'master' into brushtool
Diffstat (limited to 'js/document/views')
-rwxr-xr-xjs/document/views/design.js42
1 files changed, 37 insertions, 5 deletions
diff --git a/js/document/views/design.js b/js/document/views/design.js
index 5af24546..1a5b071e 100755
--- a/js/document/views/design.js
+++ b/js/document/views/design.js
@@ -7,7 +7,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
7//////////////////////////////////////////////////////////////////////// 7////////////////////////////////////////////////////////////////////////
8// 8//
9var Montage = require("montage/core/core").Montage, 9var Montage = require("montage/core/core").Montage,
10 BaseDocumentView = require("js/document/views/base").BaseDocumentView; 10 BaseDocumentView = require("js/document/views/base").BaseDocumentView,
11 ElementModel = require("js/models/element-model");
11//////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////
12// 13//
13exports.DesignDocumentView = Montage.create(BaseDocumentView, { 14exports.DesignDocumentView = Montage.create(BaseDocumentView, {
@@ -23,6 +24,11 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
23 }, 24 },
24 //////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////
25 // 26 //
27 _viewCallback: {
28 value: null
29 },
30 ////////////////////////////////////////////////////////////////////
31 //
26 _template: { 32 _template: {
27 value: null 33 value: null
28 }, 34 },
@@ -126,12 +132,13 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
126 //////////////////////////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////
127 // 133 //
128 render: { 134 render: {
129 value: function (callback, template) { 135 value: function (callback, template, viewCallback) {
130 //TODO: Remove, this is a temp patch for webRequest API gate 136 //TODO: Remove, this is a temp patch for webRequest API gate
131 this.application.ninja.documentController.redirectRequests = false; 137 this.application.ninja.documentController.redirectRequests = false;
132 //Storing callback for dispatch ready 138 //Storing callback for dispatch ready
133 this._callback = callback; 139 this._callback = callback;
134 this._template = template; 140 this._template = template;
141 this._viewCallback = viewCallback;
135 //Adding listener to know when template is loaded to then load user content 142 //Adding listener to know when template is loaded to then load user content
136 this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false); 143 this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false);
137 //TODO: Add source parameter and root (optional) 144 //TODO: Add source parameter and root (optional)
@@ -197,7 +204,19 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
197 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);
198 } 205 }
199 } 206 }
200 //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 }
201 } 220 }
202 } 221 }
203 }, 222 },
@@ -286,6 +305,10 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
286 } 305 }
287 } 306 }
288 } 307 }
308
309 // Assign the modelGenerator reference from the template to our own modelGenerator
310 this.document.modelGenerator = ElementModel.modelGenerator;
311
289 //Checking for script tags then parsing check for montage and webgl 312 //Checking for script tags then parsing check for montage and webgl
290 if (scripttags.length > 0) { 313 if (scripttags.length > 0) {
291 //Checking and initializing webGL 314 //Checking and initializing webGL
@@ -294,6 +317,9 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
294 this.initMontage(scripttags); 317 this.initMontage(scripttags);
295 } else { 318 } else {
296 //Else there is not data to parse 319 //Else there is not data to parse
320 if(this._viewCallback) {
321 this._viewCallback.viewCallback.call(this._viewCallback.context);
322 }
297 } 323 }
298 //TODO: Verify appropiate location for this operation 324 //TODO: Verify appropiate location for this operation
299 if (this._template && this._template.type === 'banner') { 325 if (this._template && this._template.type === 'banner') {
@@ -309,8 +335,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
309 for (var n in orgNodes) { 335 for (var n in orgNodes) {
310 if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true'); 336 if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true');
311 } 337 }
312 //Initiliazing document model 338
313 document.application.njUtils.makeElementModel(this.documentRoot, "Body", "body");
314 //Makign callback if specified 339 //Makign callback if specified
315 if (this._callback) this._callback(); 340 if (this._callback) this._callback();
316 } 341 }
@@ -415,6 +440,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
415 // 440 //
416 initMontage: { 441 initMontage: {
417 value: function (scripttags) { 442 value: function (scripttags) {
443 var self = this;
418 // 444 //
419 this.iframe.contentWindow.document.body.addEventListener('mjsTemplateReady', function () { 445 this.iframe.contentWindow.document.body.addEventListener('mjsTemplateReady', function () {
420 //Initializing template with user's seriliazation 446 //Initializing template with user's seriliazation
@@ -426,6 +452,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, {
426 //Forcing draw on components 452 //Forcing draw on components
427 template._deserializer._objects[c].needsDraw = true; 453 template._deserializer._objects[c].needsDraw = true;
428 } 454 }
455
456 // Now call the view callback
457 if(self._viewCallback) {
458 self._viewCallback.viewCallback.call(self._viewCallback.context);
459 }
460
429 }); 461 });
430 }.bind(this), false); 462 }.bind(this), false);
431 } 463 }