From 86837d69186bc4d1d6f54fc893c523de0972a0b9 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 1 Jun 2012 11:53:57 -0700 Subject: Creating template mediator class This is to simplify code, more to be changed and added. --- js/document/views/design.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/document/views/design.js') diff --git a/js/document/views/design.js b/js/document/views/design.js index dedfe8b6..02e78e6e 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -159,7 +159,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { this._observer.body = new WebKitMutationObserver(this.insertBannerContent.bind(this)); this._observer.body.observe(this._bodyFragment, {childList: true}); //Inserting HTML and parsing URLs via mediator method - this._bodyFragment.innerHTML = ''+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator)); + this._bodyFragment.innerHTML = ''+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt)); } } else { //Creating temp code fragement to load head @@ -168,12 +168,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { this._observer.head = new WebKitMutationObserver(this.insertHeadContent.bind(this)); this._observer.head.observe(this._headFragment, {childList: true}); //Inserting HTML and parsing URLs via mediator method - this._headFragment.innerHTML = (this.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator)); + this._headFragment.innerHTML = (this.content.head.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt)); //Adding event listener to know when the body is ready and make callback (using HTML5 new DOM Mutation Events) this._observer.body = new WebKitMutationObserver(this.bodyContentLoaded.bind(this)); this._observer.body.observe(this.document.body, {childList: true}); //Inserting HTML and parsing URLs via mediator method - this.document.body.innerHTML += ''+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator)); + this.document.body.innerHTML += ''+(this.content.body.replace(/\b(href|src)\s*=\s*"([^"]*)"/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt))).replace(/url\(([^"]*)(.+?)\1\)/g, this.application.ninja.ioMediator.tmplt.getNinjaPropUrlRedirect.bind(this.application.ninja.ioMediator.tmplt)); //Copying attributes to maintain same properties as the for (var n in this.content.document.body.attributes) { if (this.content.document.body.attributes[n].value) { -- cgit v1.2.3 From 54c53c326ebde0631fe5720dc912c39341966f1f Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 1 Jun 2012 16:55:31 -0700 Subject: Adding open draw to reel components --- js/document/views/design.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'js/document/views/design.js') diff --git a/js/document/views/design.js b/js/document/views/design.js index 02e78e6e..05431d85 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -405,7 +405,13 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { //Initializing template with user's seriliazation var template = this.iframe.contentWindow.mjsTemplate.create(); template.initWithDocument(this.iframe.contentWindow.document); - template.instantiateWithOwnerAndDocument(null, this.iframe.contentWindow.document, function (e){/*Nothing just a required extra parameter*/}); + template.instantiateWithOwnerAndDocument(null, this.iframe.contentWindow.document, function (){ + //TODO: Verify this is properly done, seems like a hack + for (var c in template._deserializer._objects) { + //Forcing draw on components + template._deserializer._objects[c].needsDraw = true; + } + }); }.bind(this), false); } }, -- cgit v1.2.3 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/design.js') 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 From 6a0f150f49be656e0725bc77b452a3141dddd47c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 6 Jun 2012 13:46:02 -0700 Subject: Cleaning up Removed reference of model in design view, clean up slightly, need to implement binding later. --- js/document/views/design.js | 46 ++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'js/document/views/design.js') diff --git a/js/document/views/design.js b/js/document/views/design.js index f7fbf3c5..53590944 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -51,11 +51,6 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { content: { value: null }, - //////////////////////////////////////////////////////////////////// - //TODO: Remove usage - model: { - value: null - }, //////////////////////////////////////////////////////////////////// // document: { @@ -69,6 +64,33 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { }, //////////////////////////////////////////////////////////////////// // + _baseHref: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + baseHref: { + get: function() {return this._baseHref;}, + set: function(value) {this._baseHref = value;} + }, + //////////////////////////////////////////////////////////////////// + // + _documentRoot: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + documentRoot: { + get: function() {return this._documentRoot;}, + set: function(value) {this._documentRoot = value;} + }, + //////////////////////////////////////////////////////////////////// + // + _webGlHelper: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // getLiveNodeList: { value: function(useFilter) { if(useFilter) { @@ -142,7 +164,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { if (basetag.length) { if (basetag[basetag.length-1].getAttribute && basetag[basetag.length-1].getAttribute('href')) { //Setting base HREF in model - this.model.baseHref = basetag[basetag.length-1].getAttribute('href'); + this.baseHref = basetag[basetag.length-1].getAttribute('href'); } } //Checking to content to be template @@ -275,12 +297,12 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { } //TODO: Verify appropiate location for this operation if (this._template && this._template.type === 'banner') { - this.model.documentRoot = this.document.body.getElementsByTagName('ninja-content')[0]; + this.documentRoot = this.document.body.getElementsByTagName('ninja-content')[0]; } else { - this.model.documentRoot = this.document.body; + this.documentRoot = this.document.body; } //Storing node list for reference (might need to store in the model) - this._liveNodeList = this.model.documentRoot.getElementsByTagName('*'); + this._liveNodeList = this.documentRoot.getElementsByTagName('*'); //Getting list of original nodes orgNodes = this.document.getElementsByTagName('*'); //TODO: Figure out if this is ideal for identifying nodes created by Ninja @@ -288,7 +310,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { if (orgNodes[n].getAttribute) orgNodes[n].setAttribute('data-ninja-node', 'true'); } //Initiliazing document model - document.application.njUtils.makeElementModel(this.model.documentRoot, "Body", "body"); + document.application.njUtils.makeElementModel(this.documentRoot, "Body", "body"); //Makign callback if specified if (this._callback) this._callback(); } @@ -358,8 +380,6 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { value: function (scripttags) { // var n, webgldata, fileRead; - //Setting the iFrame property for reference in helper class - this.model.webGlHelper.iframe = this.model.views.design.iframe; //Checking for webGL Data for (var w in scripttags) { // @@ -385,7 +405,7 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { webgldata.data[n] = unescape(webgldata.data[n]); } //TODO: Improve setter of webGL and reference - this.model.webGlHelper.glData = webgldata.data; + this._webGlHelper.glData = webgldata.data; } } } -- cgit v1.2.3 From 98d8cf7fdc1b14a6ac4eaa54f9086a558f3a60cb Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 6 Jun 2012 13:50:05 -0700 Subject: Cleaning more. --- js/document/views/design.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'js/document/views/design.js') diff --git a/js/document/views/design.js b/js/document/views/design.js index 53590944..5af24546 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js @@ -26,11 +26,6 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { _template: { value: null }, - //////////////////////////////////////////////////////////////////// - // - _document: { - value: null - }, //////////////////////////////////////////////////////////////////// // _bodyFragment: { @@ -52,14 +47,13 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { value: null }, //////////////////////////////////////////////////////////////////// - // - document: { - get: function() {return this._document;}, - set: function(value) {this._document = value;} + // + _liveNodeList: { + value: null }, //////////////////////////////////////////////////////////////////// // - _liveNodeList: { + _webGlHelper: { value: null }, //////////////////////////////////////////////////////////////////// @@ -73,6 +67,17 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { get: function() {return this._baseHref;}, set: function(value) {this._baseHref = value;} }, + //////////////////////////////////////////////////////////////////// + // + _document: { + value: null + }, + //////////////////////////////////////////////////////////////////// + // + document: { + get: function() {return this._document;}, + set: function(value) {this._document = value;} + }, //////////////////////////////////////////////////////////////////// // _documentRoot: { @@ -86,11 +91,6 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { }, //////////////////////////////////////////////////////////////////// // - _webGlHelper: { - value: null - }, - //////////////////////////////////////////////////////////////////// - // getLiveNodeList: { value: function(useFilter) { if(useFilter) { -- cgit v1.2.3