From 563935933c191093b8ccd88fd1377775c5641b0d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Mon, 4 Jun 2012 23:33:32 -0700 Subject: components fix: adding a first draw event to components Adding a first draw allows the component to have the right element so that ninja can use it's controller to get the component instance Signed-off-by: Valerio Virgillito --- js/document/templates/app/main.js | 52 ++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 9 deletions(-) (limited to 'js/document/templates') diff --git a/js/document/templates/app/main.js b/js/document/templates/app/main.js index a406abdb..fbd2e138 100644 --- a/js/document/templates/app/main.js +++ b/js/document/templates/app/main.js @@ -8,12 +8,38 @@ var Montage = require("montage/core/core").Montage, Template = require("montage/ui/template").Template, TemplateCreator = require("tools/template/template-creator").TemplateCreator; + +//var njmodelGet = function njmodelGet() { +// return (this.hasOwnProperty("_model") ? this._model: document.modelGenerator.call(this)); +//}; +// +//Object.defineProperty(Object.prototype, "_model", { +// enumerable: false, +// value: null, +// writable: true +//}); +// +//Object.defineProperty(Object.prototype, "elementModel", { +// configurable: true, +// get: njmodelGet, +// set: function() { +// } +//}); + exports.Main = Montage.create(Component, { hasTemplate: { value: false }, + componentToInsert: { + value: null + }, + + firstDrawCallback: { + value: null + }, + /** * Adding window hooks to callback into this object from Ninja. */ @@ -24,6 +50,12 @@ exports.Main = Montage.create(Component, { window.addComponent = function(element, data, callback) { var component; + if(!self.firstDrawCallback) { + self.firstDrawCallback = {}; + self.firstDrawCallback.callback = data.firstDraw.cb; + self.firstDrawCallback.context = data.firstDraw.ctx; + } + component = require.async(data.path) .then(function(component) { var componentRequire = component[data.name]; @@ -34,6 +66,9 @@ exports.Main = Montage.create(Component, { componentInstance.needsDraw = true; componentInstance.ownerComponent = self; + self.componentToInsert = componentInstance; + componentInstance.addEventListener("firstDraw", self, false); + callback(componentInstance, element); }) .end(); @@ -46,16 +81,15 @@ exports.Main = Montage.create(Component, { // var templateEvent = document.createEvent("CustomEvent"); templateEvent.initCustomEvent("mjsTemplateReady", false, true); - document.body.dispatchEvent(templateEvent); - - - // Dispatch event when this template has loaded. - /* - var newEvent = document.createEvent( "CustomEvent" ); - newEvent.initCustomEvent( "userTemplateDidLoad", false, true ); - document.body.dispatchEvent( newEvent ); - */ + } + }, + + handleFirstDraw: { + value: function() { + this.firstDrawCallback.callback.call(this.firstDrawCallback.context, this.componentToInsert); + this.componentToInsert.removeEventListener("firstDraw", this, false); + this.componentToInsert = null; } } }); \ No newline at end of file -- cgit v1.2.3 From 0d7ff08d74ab28247de8a84b84796c183aa47f0d Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 5 Jun 2012 14:20:31 -0700 Subject: fixing a small typo Signed-off-by: Valerio Virgillito --- js/document/templates/app/main.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/document/templates') diff --git a/js/document/templates/app/main.js b/js/document/templates/app/main.js index fbd2e138..0cdf718c 100644 --- a/js/document/templates/app/main.js +++ b/js/document/templates/app/main.js @@ -81,6 +81,7 @@ exports.Main = Montage.create(Component, { // var templateEvent = document.createEvent("CustomEvent"); templateEvent.initCustomEvent("mjsTemplateReady", false, true); + document.body.dispatchEvent(templateEvent); } }, -- 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/templates/banner/index.html | 24 +++++++++++++++++++++--- js/document/templates/html/index.html | 27 +++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 7 deletions(-) (limited to 'js/document/templates') diff --git a/js/document/templates/banner/index.html b/js/document/templates/banner/index.html index f1ee3d98..08a998e5 100755 --- a/js/document/templates/banner/index.html +++ b/js/document/templates/banner/index.html @@ -74,9 +74,27 @@ diff --git a/js/document/templates/html/index.html b/js/document/templates/html/index.html index 70187900..c74a7251 100755 --- a/js/document/templates/html/index.html +++ b/js/document/templates/html/index.html @@ -57,13 +57,32 @@ .nj-element-highlight { outline: 4px solid #ff0000; - } + } -- cgit v1.2.3