aboutsummaryrefslogtreecommitdiff
path: root/js/document/templates/app
diff options
context:
space:
mode:
authorArmen Kesablyan2012-06-11 11:17:41 -0700
committerArmen Kesablyan2012-06-11 11:17:41 -0700
commit278769df00ced8620fd73371e38fe2e43f07ca3b (patch)
treedeb505c8a66b660eee1f17a2c6c4c575c7939f6f /js/document/templates/app
parent555fd6efa605b937800b3979a4c68fa7eb8666ae (diff)
parent0f040acabfb7a4bf3138debec5aff869487ceb11 (diff)
downloadninja-278769df00ced8620fd73371e38fe2e43f07ca3b.tar.gz
Merge branch 'refs/heads/master' into binding
Conflicts: js/document/models/html.js js/document/views/design.js js/ninja.reel/ninja.js Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'js/document/templates/app')
-rw-r--r--js/document/templates/app/main.js51
1 files changed, 43 insertions, 8 deletions
diff --git a/js/document/templates/app/main.js b/js/document/templates/app/main.js
index e2bdc1a0..bb4cd829 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
11exports.Main = Montage.create(Component, { 29exports.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];
@@ -35,6 +67,9 @@ exports.Main = Montage.create(Component, {
35 componentInstance.needsDraw = true; 67 componentInstance.needsDraw = true;
36 componentInstance.ownerComponent = self; 68 componentInstance.ownerComponent = self;
37 69
70 self.componentToInsert = componentInstance;
71 componentInstance.addEventListener("firstDraw", self, false);
72
38 callback(componentInstance, element); 73 callback(componentInstance, element);
39 }) 74 })
40 .end(); 75 .end();
@@ -48,15 +83,15 @@ exports.Main = Montage.create(Component, {
48 var templateEvent = document.createEvent("CustomEvent"); 83 var templateEvent = document.createEvent("CustomEvent");
49 templateEvent.initCustomEvent("mjsTemplateReady", false, true); 84 templateEvent.initCustomEvent("mjsTemplateReady", false, true);
50 document.body.dispatchEvent(templateEvent); 85 document.body.dispatchEvent(templateEvent);
51 86 }
52 87 },
53 // Dispatch event when this template has loaded. 88
54 /* 89 handleFirstDraw: {
55 var newEvent = document.createEvent( "CustomEvent" ); 90 value: function() {
56 newEvent.initCustomEvent( "userTemplateDidLoad", false, true ); 91 this.firstDrawCallback.callback.call(this.firstDrawCallback.context, this.componentToInsert);
57 document.body.dispatchEvent( newEvent );
58 */
59 92
93 this.componentToInsert.removeEventListener("firstDraw", this, false);
94 this.componentToInsert = null;
60 } 95 }
61 } 96 }
62}); \ No newline at end of file 97}); \ No newline at end of file