diff options
author | Valerio Virgillito | 2012-06-05 21:40:44 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-06-05 21:40:44 -0700 |
commit | e28eb9158a50d7e6d97dbc68066e591ac600c241 (patch) | |
tree | 1615affe62374ae67eaecb8b1966a2f464559dfa /js/document | |
parent | d7555c35b357e28a1e1ccc1c4edc4fe04d2b139a (diff) | |
download | ninja-e28eb9158a50d7e6d97dbc68066e591ac600c241.tar.gz |
removing all model creators.
The elementModel is now a getter that will create a new model when needed.
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/document')
-rwxr-xr-x | js/document/document-html.js | 10 | ||||
-rwxr-xr-x | js/document/models/html.js | 23 | ||||
-rwxr-xr-x | js/document/templates/banner/index.html | 24 | ||||
-rwxr-xr-x | js/document/templates/html/index.html | 27 | ||||
-rwxr-xr-x | js/document/views/design.js | 30 |
5 files changed, 77 insertions, 37 deletions
diff --git a/js/document/document-html.js b/js/document/document-html.js index 33a41a8e..4a8d5d41 100755 --- a/js/document/document-html.js +++ b/js/document/document-html.js | |||
@@ -88,7 +88,7 @@ exports.HtmlDocument = Montage.create(Component, { | |||
88 | //Adding observer to know when template is ready | 88 | //Adding observer to know when template is ready |
89 | this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); | 89 | this._observer = new WebKitMutationObserver(this.handleTemplateReady.bind(this)); |
90 | this._observer.observe(this.model.views.design.document.head, {childList: true}); | 90 | this._observer.observe(this.model.views.design.document.head, {childList: true}); |
91 | }.bind(this), template); | 91 | }.bind(this), template, {viewCallback: this.handleViewReady, context: this}); |
92 | } else { | 92 | } else { |
93 | //TODO: Identify default view (probably code) | 93 | //TODO: Identify default view (probably code) |
94 | } | 94 | } |
@@ -101,10 +101,14 @@ exports.HtmlDocument = Montage.create(Component, { | |||
101 | //Removing observer, only needed on initial load | 101 | //Removing observer, only needed on initial load |
102 | this._observer.disconnect(); | 102 | this._observer.disconnect(); |
103 | this._observer = null; | 103 | this._observer = null; |
104 | //Making callback after view is loaded | ||
105 | this.loaded.callback.call(this.loaded.context, this); | ||
106 | } | 104 | } |
107 | }, | 105 | }, |
106 | handleViewReady: { | ||
107 | value: function() { | ||
108 | //Making callback after view is loaded | ||
109 | this.loaded.callback.call(this.loaded.context, this); | ||
110 | } | ||
111 | }, | ||
108 | //////////////////////////////////////////////////////////////////// | 112 | //////////////////////////////////////////////////////////////////// |
109 | // | 113 | // |
110 | closeDocument: { | 114 | closeDocument: { |
diff --git a/js/document/models/html.js b/js/document/models/html.js index 9aa0d27e..a367f95f 100755 --- a/js/document/models/html.js +++ b/js/document/models/html.js | |||
@@ -64,31 +64,8 @@ exports.HtmlDocumentModel = Montage.create(BaseDocumentModel, { | |||
64 | }, | 64 | }, |
65 | //////////////////////////////////////////////////////////////////// | 65 | //////////////////////////////////////////////////////////////////// |
66 | // | 66 | // |
67 | userComponents: { | ||
68 | value: {} | ||
69 | }, | ||
70 | //////////////////////////////////////////////////////////////////// | ||
71 | // | ||
72 | documentRoot: { | 67 | documentRoot: { |
73 | value: null | 68 | value: null |
74 | }, | ||
75 | //////////////////////////////////////////////////////////////////// | ||
76 | //Add a reference to a component instance to the userComponents hash using the element UUID | ||
77 | setComponentInstance: { | ||
78 | value: function(instance, el) { | ||
79 | this.userComponents[el.uuid] = instance; | ||
80 | } | ||
81 | }, | ||
82 | //////////////////////////////////////////////////////////////////// | ||
83 | //Returns the component instance obj from the element | ||
84 | getComponentFromElement: { | ||
85 | value: function(el) { | ||
86 | if(el) { | ||
87 | if(el.uuid) return this.userComponents[el.uuid]; | ||
88 | } else { | ||
89 | return null; | ||
90 | } | ||
91 | } | ||
92 | } | 69 | } |
93 | //////////////////////////////////////////////////////////////////// | 70 | //////////////////////////////////////////////////////////////////// |
94 | //////////////////////////////////////////////////////////////////// | 71 | //////////////////////////////////////////////////////////////////// |
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> |
diff --git a/js/document/views/design.js b/js/document/views/design.js index f7fbf3c5..0e42dcc2 100755 --- a/js/document/views/design.js +++ b/js/document/views/design.js | |||
@@ -7,7 +7,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
7 | //////////////////////////////////////////////////////////////////////// | 7 | //////////////////////////////////////////////////////////////////////// |
8 | // | 8 | // |
9 | var Montage = require("montage/core/core").Montage, | 9 | var Montage = require("montage/core/core").Montage, |
10 | BaseDocumentView = require("js/document/views/base").BaseDocumentView; | 10 | BaseDocumentView = require("js/document/views/base").BaseDocumentView, |
11 | ElementModel = require("js/models/element-model"); | ||
11 | //////////////////////////////////////////////////////////////////////// | 12 | //////////////////////////////////////////////////////////////////////// |
12 | // | 13 | // |
13 | exports.DesignDocumentView = Montage.create(BaseDocumentView, { | 14 | exports.DesignDocumentView = Montage.create(BaseDocumentView, { |
@@ -22,6 +23,11 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { | |||
22 | value: null | 23 | value: null |
23 | }, | 24 | }, |
24 | //////////////////////////////////////////////////////////////////// | 25 | //////////////////////////////////////////////////////////////////// |
26 | // | ||
27 | _viewCallback: { | ||
28 | value: null | ||
29 | }, | ||
30 | //////////////////////////////////////////////////////////////////// | ||
25 | // | 31 | // |
26 | _template: { | 32 | _template: { |
27 | value: null | 33 | value: null |
@@ -104,12 +110,13 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { | |||
104 | //////////////////////////////////////////////////////////////////// | 110 | //////////////////////////////////////////////////////////////////// |
105 | // | 111 | // |
106 | render: { | 112 | render: { |
107 | value: function (callback, template) { | 113 | value: function (callback, template, viewCallback) { |
108 | //TODO: Remove, this is a temp patch for webRequest API gate | 114 | //TODO: Remove, this is a temp patch for webRequest API gate |
109 | this.application.ninja.documentController.redirectRequests = false; | 115 | this.application.ninja.documentController.redirectRequests = false; |
110 | //Storing callback for dispatch ready | 116 | //Storing callback for dispatch ready |
111 | this._callback = callback; | 117 | this._callback = callback; |
112 | this._template = template; | 118 | this._template = template; |
119 | this._viewCallback = viewCallback; | ||
113 | //Adding listener to know when template is loaded to then load user content | 120 | //Adding listener to know when template is loaded to then load user content |
114 | this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false); | 121 | this.iframe.addEventListener("load", this.onTemplateLoad.bind(this), false); |
115 | //TODO: Add source parameter and root (optional) | 122 | //TODO: Add source parameter and root (optional) |
@@ -264,6 +271,10 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { | |||
264 | } | 271 | } |
265 | } | 272 | } |
266 | } | 273 | } |
274 | |||
275 | // Assign the modelGenerator reference from the template to our own modelGenerator | ||
276 | this.document.modelGenerator = ElementModel.modelGenerator; | ||
277 | |||
267 | //Checking for script tags then parsing check for montage and webgl | 278 | //Checking for script tags then parsing check for montage and webgl |
268 | if (scripttags.length > 0) { | 279 | if (scripttags.length > 0) { |
269 | //Checking and initializing webGL | 280 | //Checking and initializing webGL |
@@ -272,6 +283,9 @@ exports.DesignDocumentView = Montage.create(BaseDocumentView, { | |||
272 | this.initMontage(scripttags); | 283 | this.initMontage(scripttags); |
273 | } else { | 284 | } else { |
274 | //Else there is not data to parse | 285 | //Else there is not data to parse |
286 | if(this._viewCallback) { | ||
287 | this._viewCallback.viewCallback.call(this._viewCallback.context); | ||
288 | } | ||
275 | } | 289 | } |
276 | //TODO: Verify appropiate location for this operation | 290 | //TODO: Verify appropiate location for this operation |