From e28eb9158a50d7e6d97dbc68066e591ac600c241 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 5 Jun 2012 21:40:44 -0700 Subject: removing all model creators. The elementModel is now a getter that will create a new model when needed. Signed-off-by: Valerio Virgillito --- js/document/views/design.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'js/document/views') diff --git a/js/document/views/design.js b/js/document/views/design.js index f7fbf3c5..0e42dcc2 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 //////////////////////////////////////////////////////////////////////// // var Montage = require("montage/core/core").Montage, - BaseDocumentView = require("js/document/views/base").BaseDocumentView; + BaseDocumentView = require("js/document/views/base").BaseDocumentView, + ElementModel = require("js/models/element-model"); //////////////////////////////////////////////////////////////////////// // exports.DesignDocumentView = Montage.create(BaseDocumentView, { @@ -21,6 +22,11 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { _callback: { value: null }, + //////////////////////////////////////////////////////////////////// + // + _viewCallback: { + value: null + }, //////////////////////////////////////////////////////////////////// // _template: { @@ -104,12 +110,13 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { //////////////////////////////////////////////////////////////////// // render: { - value: function (callback, template) { + value: function (callback, template, viewCallback) { //TODO: Remove, this is a temp patch for webRequest API gate this.application.ninja.documentController.redirectRequests = false; //Storing callback for dispatch ready this._callback = callback; this._template = template; + this._viewCallback = viewCallback; //Adding listener to know when template is loaded to then load user content this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false); //TODO: Add source parameter and root (optional) @@ -264,6 +271,10 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { } } } + + // Assign the modelGenerator reference from the template to our own modelGenerator + this.document.modelGenerator = ElementModel.modelGenerator; + //Checking for script tags then parsing check for montage and webgl if (scripttags.length > 0) { //Checking and initializing webGL @@ -272,6 +283,9 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { this.initMontage(scripttags); } else { //Else there is not data to parse + if(this._viewCallback) { + this._viewCallback.viewCallback.call(this._viewCallback.context); + } } //TODO: Verify appropiate location for this operation if (this._template && this._template.type === 'banner') { @@ -287,8 +301,9 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { for (var n in orgNodes) { if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true'); } - //Initiliazing document model - document.application.njUtils.makeElementModel(this.model.documentRoot, "Body", "body"); + + + //Makign callback if specified if (this._callback) this._callback(); } @@ -395,6 +410,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { // initMontage: { value: function (scripttags) { + var self = this; // this.iframe.contentWindow.document.body.addEventListener('mjsTemplateReady', function () { //Initializing template with user's seriliazation @@ -406,6 +422,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { //Forcing draw on components template._deserializer._objects[c].needsDraw = true; } + + // Now call the view callback + if(self._viewCallback) { + self._viewCallback.viewCallback.call(self._viewCallback.context); + } + }); }.bind(this), false); } -- cgit v1.2.3