aboutsummaryrefslogtreecommitdiff
path: root/js/document/templates
diff options
context:
space:
mode:
Diffstat (limited to 'js/document/templates')
-rw-r--r--js/document/templates/app/main.js51
-rwxr-xr-xjs/document/templates/banner/index.html24
-rwxr-xr-xjs/document/templates/html/index.html27
3 files changed, 87 insertions, 15 deletions
diff --git a/js/document/templates/app/main.js b/js/document/templates/app/main.js
index a406abdb..0cdf718c 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];
@@ -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();
@@ -47,15 +82,15 @@ exports.Main = Montage.create(Component, {
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 document.body.dispatchEvent(templateEvent);
50 85 }
51 86 },
52 // Dispatch event when this template has loaded. 87
53 /* 88 handleFirstDraw: {
54 var newEvent = document.createEvent( "CustomEvent" ); 89 value: function() {
55 newEvent.initCustomEvent( "userTemplateDidLoad", false, true ); 90 this.firstDrawCallback.callback.call(this.firstDrawCallback.context, this.componentToInsert);
56 document.body.dispatchEvent( newEvent );
57 */
58 91
92 this.componentToInsert.removeEventListener("firstDraw", this, false);
93 this.componentToInsert = null;
59 } 94 }
60 } 95 }
61}); \ No newline at end of file 96}); \ No newline at end of file
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 @@
74 </style> 74 </style>
75 75
76 <script type="text/javascript" data-ninja-template="true"> 76 <script type="text/javascript" data-ninja-template="true">
77 function getElement(x,y) { 77
78 return document.elementFromPoint(x,y); 78 function getElement(x,y) {
79 } 79 return document.elementFromPoint(x,y);
80 }
81
82 var njmodelGet = function njmodelGet() {
83 return (this.hasOwnProperty("_model") ? this._model: document.modelGenerator.call(this));
84 };
85
86 Object.defineProperty(Object.prototype, "_model", {
87 enumerable: false,
88 value: null,
89 writable: true
90 });
91
92 Object.defineProperty(Object.prototype, "elementModel", {
93 configurable: true,
94 get: njmodelGet,
95 set: function() {
96 }
97 });
80 </script> 98 </script>
81 99
82 <!-- TODO: Determine if loading Montage is always needed or if it could be done author-time or on file open --> 100 <!-- TODO: Determine if loading Montage is always needed or if it could be done author-time or on file open -->
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 @@
57 57
58 .nj-element-highlight { 58 .nj-element-highlight {
59 outline: 4px solid #ff0000; 59 outline: 4px solid #ff0000;
60 } 60 }
61 </style> 61 </style>
62 62
63 <script type="text/javascript" data-ninja-template="true"> 63 <script type="text/javascript" data-ninja-template="true">
64 function getElement(x,y) { 64
65 return document.elementFromPoint(x,y); 65 function getElement(x,y) {
66 } 66 return document.elementFromPoint(x,y);
67 }
68
69 var njmodelGet = function njmodelGet() {
70 return (this.hasOwnProperty("_model") ? this._model: document.modelGenerator.call(this));
71 };
72
73 Object.defineProperty(Object.prototype, "_model", {
74 enumerable: false,
75 value: null,
76 writable: true
77 });
78
79 Object.defineProperty(Object.prototype, "elementModel", {
80 configurable: true,
81 get: njmodelGet,
82 set: function() {
83 }
84 });
85
67 </script> 86 </script>
68 87
69 <script type="text/javascript" data-package="../app" src="../../../../node_modules/montage/montage.js" data-ninja-template="true"></script> 88 <script type="text/javascript" data-package="../app" src="../../../../node_modules/montage/montage.js" data-ninja-template="true"></script>