From efcec76362a652033254fc6465dd127e8bebc04c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 22 Mar 2012 09:57:32 -0700 Subject: Adding firstDraw event to components added This will allow us to re-parse the document for styles added dynamically. --- js/controllers/document-controller.js | 8 +++++++- js/document/templates/montage-html/main.reel/main.js | 11 ----------- .../ComponentsPanelBase.reel/ComponentsPanelBase.js | 8 ++++++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 3db4c7d4..c6f867aa 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -64,10 +64,16 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("styleSheetDirty", this, false); + this.eventManager.addEventListener("addComponentFirstDraw", this, false); } }, - + handleAddComponentFirstDraw: { + value: function (e) { + //TODO: Add logic to reparse the document for dynamically added styles + console.log(e); + } + }, diff --git a/js/document/templates/montage-html/main.reel/main.js b/js/document/templates/montage-html/main.reel/main.js index 2970f37a..019c675e 100644 --- a/js/document/templates/montage-html/main.reel/main.js +++ b/js/document/templates/montage-html/main.reel/main.js @@ -31,8 +31,6 @@ exports.Main = Montage.create(Component, { componentInstance.needsDraw = true; componentInstance.ownerComponent = self; - componentInstance.addEventListener("firstDraw", self, false); - callback(componentInstance, element); }) .end(); @@ -46,14 +44,5 @@ exports.Main = Montage.create(Component, { document.body.dispatchEvent( newEvent ); } - }, - - handleFirstDraw: { - value: function() { - var newEvent = document.createEvent( "CustomEvent" ); - newEvent.initCustomEvent( "addComponentFirstDraw", false, true ); - - document.body.dispatchEvent( newEvent ); - } } }); \ No newline at end of file diff --git a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js index 599eeda3..3505393c 100755 --- a/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js +++ b/js/panels/Components/ComponentsPanelBase.reel/ComponentsPanelBase.js @@ -297,6 +297,8 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component styles[n] = defaultStyles[n]; } } + + instance.addEventListener('firstDraw', that, false); that.application.ninja.currentDocument.setComponentInstance(instance, element); @@ -305,6 +307,12 @@ var ComponentsPanelBase = exports.ComponentsPanelBase = Montage.create(Component } }, + + handleFirstDraw: { + value: function (e) { + NJevent("addComponentFirstDraw"); + } + }, makeComponent: { value: function(name) { -- cgit v1.2.3