diff options
author | Valerio Virgillito | 2012-06-05 11:32:10 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-06-05 11:32:10 -0700 |
commit | 73a62c95b5635fee903457279f0f5b57f164e0b5 (patch) | |
tree | 2d93494abb9d9d6d446655d7006341336e4b64cc /js/document/templates/app | |
parent | 7933020ed6261052b01ac29bdb29794a3f2c8c8b (diff) | |
parent | 563935933c191093b8ccd88fd1377775c5641b0d (diff) | |
download | ninja-73a62c95b5635fee903457279f0f5b57f164e0b5.tar.gz |
Merge pull request #266 from mencio/element-model-fixes
components fix: adding a first draw event to components
Diffstat (limited to 'js/document/templates/app')
-rw-r--r-- | js/document/templates/app/main.js | 52 |
1 files changed, 43 insertions, 9 deletions
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, | |||
8 | Template = require("montage/ui/template").Template, | 8 | Template = require("montage/ui/template").Template, |
9 | TemplateCreator = require("tools/template/template-creator").TemplateCreator; | 9 | TemplateCreator = require("tools/template/template-creator").TemplateCreator; |
10 | 10 | ||
11 | |||
12 | //var njmodelGet = function njmodelGet() { | ||
13 | // return (this.hasOwnProperty("_model") ? this._model: document.modelGenerator.call(this)); | ||
14 | //}; | ||
15 | // | ||
16 | //Object.defineProperty(Object.prototype, "_model", { | ||
17 | // enumerable: false, | ||
18 | // value: null, | ||
19 | // writable: true | ||
20 | //}); | ||
21 | // | ||
22 | //Object.defineProperty(Object.prototype, "elementModel", { | ||
23 | // configurable: true, | ||
24 | // get: njmodelGet, | ||
25 | // set: function() { | ||
26 | // } | ||
27 | //}); | ||
28 | |||
11 | exports.Main = Montage.create(Component, { | 29 | exports.Main = Montage.create(Component, { |
12 | 30 | ||
13 | hasTemplate: { | 31 | hasTemplate: { |
14 | value: false | 32 | value: false |
15 | }, | 33 | }, |
16 | 34 | ||
35 | componentToInsert: { | ||
36 | value: null | ||
37 | }, | ||
38 | |||
39 | firstDrawCallback: { | ||
40 | value: null | ||
41 | }, | ||
42 | |||
17 | /** | 43 | /** |
18 | * Adding window hooks to callback into this object from Ninja. | 44 | * Adding window hooks to callback into this object from Ninja. |
19 | */ | 45 | */ |
@@ -24,6 +50,12 @@ exports.Main = Montage.create(Component, { | |||
24 | window.addComponent = function(element, data, callback) { | 50 | window.addComponent = function(element, data, callback) { |
25 | var component; | 51 | var component; |
26 | 52 | ||
53 | if(!self.firstDrawCallback) { | ||
54 | self.firstDrawCallback = {}; | ||
55 | self.firstDrawCallback.callback = data.firstDraw.cb; | ||
56 | self.firstDrawCallback.context = data.firstDraw.ctx; | ||
57 | } | ||
58 | |||
27 | component = require.async(data.path) | 59 | component = require.async(data.path) |
28 | .then(function(component) { | 60 | .then(function(component) { |
29 | var componentRequire = component[data.name]; | 61 | var componentRequire = component[data.name]; |
@@ -34,6 +66,9 @@ exports.Main = Montage.create(Component, { | |||
34 | componentInstance.needsDraw = true; | 66 | componentInstance.needsDraw = true; |
35 | componentInstance.ownerComponent = self; | 67 | componentInstance.ownerComponent = self; |
36 | 68 | ||
69 | self.componentToInsert = componentInstance; | ||
70 | componentInstance.addEventListener("firstDraw", self, false); | ||
71 | |||
37 | callback(componentInstance, element); | 72 | callback(componentInstance, element); |
38 | }) | 73 | }) |
39 | .end(); | 74 | .end(); |
@@ -46,16 +81,15 @@ exports.Main = Montage.create(Component, { | |||
46 | // | 81 | // |
47 | var templateEvent = document.createEvent("CustomEvent"); | 82 | var templateEvent = document.createEvent("CustomEvent"); |
48 | templateEvent.initCustomEvent("mjsTemplateReady", false, true); | 83 | templateEvent.initCustomEvent("mjsTemplateReady", false, true); |
49 | document.body.dispatchEvent(templateEvent); | 84 | } |
50 | 85 | }, | |
51 | 86 | ||
52 | // Dispatch event when this template has loaded. | 87 | handleFirstDraw: { |
53 | /* | 88 | value: function() { |
54 | var newEvent = document.createEvent( "CustomEvent" ); | 89 | this.firstDrawCallback.callback.call(this.firstDrawCallback.context, this.componentToInsert); |
55 | newEvent.initCustomEvent( "userTemplateDidLoad", false, true ); | ||
56 | document.body.dispatchEvent( newEvent ); | ||
57 | */ | ||
58 | 90 | ||
91 | this.componentToInsert.removeEventListener("firstDraw", this, false); | ||
92 | this.componentToInsert = null; | ||
59 | } | 93 | } |
60 | } | 94 | } |
61 | }); \ No newline at end of file | 95 | }); \ No newline at end of file |