aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/template.js
diff options
context:
space:
mode:
authorValerio Virgillito2012-04-18 13:48:51 -0700
committerValerio Virgillito2012-04-18 13:48:51 -0700
commit2e04af953463643791f6362bd8ef4c6ba190abfa (patch)
treed07aaf646091ddf9dad5b030a7905055fd323490 /node_modules/montage/ui/template.js
parent616a8532099fec2a15855eac97cd85cb60c4451c (diff)
downloadninja-2e04af953463643791f6362bd8ef4c6ba190abfa.tar.gz
Squashed commit of the following:
commit 2054551bfb01a0f4ca2e138b9d724835462d45cd Merge: 765c2da 616a853 Author: Valerio Virgillito <valerio@motorola.com> Date: Wed Apr 18 13:48:21 2012 -0700 Merge branch 'refs/heads/master' into integration commit 765c2da8e1aa03550caf42b2bd5f367555ad2843 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Apr 17 15:29:41 2012 -0700 updating the picasa carousel Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 9484f1c82b81e27edf2dc0a1bcc1fa3b12077406 Merge: d27f2df cacb4a2 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Apr 17 15:03:50 2012 -0700 Merge branch 'refs/heads/master' into integration commit d27f2df4d846064444263d7832d213535962abe7 Author: Valerio Virgillito <valerio@motorola.com> Date: Wed Apr 11 10:39:36 2012 -0700 integrating new picasa carousel component Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 6f98384c9ecbc8abe55ccfe1fc25a0c7ce22c493 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Apr 10 14:33:00 2012 -0700 fixed the text area case issue Text area was renamed from TextArea to Textarea Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 1e83e26652266136802bc7af930379c1ecd631a6 Author: Valerio Virgillito <valerio@motorola.com> Date: Mon Apr 9 22:10:45 2012 -0700 integrating montage v0.8 into ninja. Signed-off-by: Valerio Virgillito <valerio@motorola.com> Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/template.js')
-rwxr-xr-xnode_modules/montage/ui/template.js313
1 files changed, 251 insertions, 62 deletions
diff --git a/node_modules/montage/ui/template.js b/node_modules/montage/ui/template.js
index 210d8cb7..ee2cc1be 100755
--- a/node_modules/montage/ui/template.js
+++ b/node_modules/montage/ui/template.js
@@ -37,7 +37,16 @@ var Template = exports.Template = Montage.create(Montage, /** @lends module:mont
37/** 37/**
38 @private 38 @private
39*/ 39*/
40 _document: {value: null}, 40 _document: {
41 enumerable: false,
42 value: null
43 },
44
45 document: {
46 get: function() {
47 return this._document;
48 }
49 },
41/** 50/**
42 @private 51 @private
43*/ 52*/
@@ -134,6 +143,17 @@ var Template = exports.Template = Montage.create(Montage, /** @lends module:mont
134 } 143 }
135 }, 144 },
136 145
146 initWithHtmlString: {
147 value: function(htmlString) {
148 var doc = this.createHtmlDocumentFromString(htmlString);
149
150 this._isLoaded = true;
151 this.initWithDocument(doc);
152
153 return this;
154 }
155 },
156
137 /** 157 /**
138 Initializes the Template object with a specific module id that represents an HTML page. 158 Initializes the Template object with a specific module id that represents an HTML page.
139 @function 159 @function
@@ -234,63 +254,62 @@ var Template = exports.Template = Montage.create(Montage, /** @lends module:mont
234 } 254 }
235 }, 255 },
236 256
237 /** 257 _deserialize: {
238 Instantiates the Template by specifying an object as the owner and a document where the elements referenced in the serialization should be found. 258 value: function(instances, targetDocument, callback) {
239 @function
240 @param {Object} rootObject The owner object of the template.
241 @param {HTMLDocument} document The HTML document to be used to find elements referenced from the serialization.
242 @param {Function} callback The callback function to invoke when the template is instantiated.
243 */
244 instantiateWithOwnerAndDocument: {
245 value: function(owner, document, callback) {
246 var self = this, 259 var self = this,
247 defaultApplication = applicationExports.application; 260 defaultApplication = applicationExports.application;
248 this.getDeserializer(function(deserializer) {
249 function invokeTemplateDidLoad(objects) {
250 owner = objects.owner;
251 self._invokeTemplateDidLoadWithOwner(deserializer, owner);
252 self.waitForStyles(function() {
253 callback(owner);
254 });
255 }
256 261
257 var externalObjects, 262 this.getDeserializer(function(deserializer) {
258 targetDocument, 263 var externalObjects;
259 instances;
260 264
261 if (deserializer) { 265 if (deserializer) {
262 externalObjects = self._externalObjects; 266 externalObjects = self._externalObjects;
263 if (externalObjects) { 267 if (externalObjects) {
264 instances = Object.create(externalObjects); 268 for (var label in externalObjects) {
265 instances.owner = owner; 269 if (!(label in instances)) {
266 instances.application = defaultApplication; 270 instances[label] = externalObjects[label];
267 } else { 271 }
268 instances = {owner: owner, application: defaultApplication}; 272 }
269 } 273 }
270 274
271 if (owner && owner._element) { 275 instances.application = defaultApplication;
272 targetDocument = owner._element.ownerDocument; 276 instances.template = self;
273 }
274 277
275 if (self._document === window.document) { 278 if (self._document === window.document) {
276 deserializer.deserializeWithInstancesAndDocument(instances, self._document, invokeTemplateDidLoad); 279 deserializer.deserializeWithInstancesAndDocument(instances, self._document, callback);
277 } else { 280 } else {
278 self.setupDocument(window.document); 281 deserializer.deserializeWithInstancesAndElementForDocument(instances, self._document.body, targetDocument, callback);
279 deserializer.deserializeWithInstancesAndElementForDocument(instances, self._document.body, targetDocument, invokeTemplateDidLoad);
280 } 282 }
281 } else { 283 } else {
282 if (self._document !== window.document) { 284 callback();
283 self.setupDocument(window.document);
284 }
285 self.waitForStyles(function() {
286 callback();
287 });
288 } 285 }
289 }); 286 });
290 } 287 }
291 }, 288 },
292 289
293 /** 290 /**
291 Instantiates the Template by specifying an object as the owner and a document where the elements referenced in the serialization should be found.
292 @function
293 @param {Object} rootObject The owner object of the template.
294 @param {HTMLDocument} document The HTML document to be used to find elements referenced from the serialization.
295 @param {Function} callback The callback function to invoke when the template is instantiated.
296 */
297 instantiateWithOwnerAndDocument: {
298 value: function(owner, targetDocument, callback) {
299 var self = this;
300
301 this._partiallyInstantiateWithInstancesForDocument({owner: owner}, targetDocument, function(objects) {
302 if (objects) {
303 self._invokeTemplateDidLoad(objects);
304 }
305 self.waitForStyles(function() {
306 callback(objects ? objects.owner : null);
307 });
308 });
309 }
310 },
311
312 /**
294 Instantiates the Template by using a component as the owner. 313 Instantiates the Template by using a component as the owner.
295 All elements refereced in the serialization will be found on the document the component is attached to. 314 All elements refereced in the serialization will be found on the document the component is attached to.
296 @function 315 @function
@@ -303,32 +322,86 @@ var Template = exports.Template = Montage.create(Montage, /** @lends module:mont
303 this.instantiateWithOwnerAndDocument(component, document, callback); 322 this.instantiateWithOwnerAndDocument(component, document, callback);
304 }}, 323 }},
305 324
325 instantiateWithDocument: {
326 value: function(document, callback) {
327 return this.instantiateWithOwnerAndDocument(null, document, callback);
328 }
329 },
330
331 _partiallyInstantiateWithInstancesForDocument: {
332 value: function(instances, targetDocument, callback) {
333 var self = this,
334 owner = instances.owner;
335
336 if (!targetDocument && owner && owner._element) {
337 targetDocument = owner._element.ownerDocument;
338 }
339
340 function importHeaders(objects) {
341 if (self._document !== targetDocument) {
342 self.exportHeaders(targetDocument);
343 }
344 callback(objects);
345 }
346
347 this._deserialize(instances, targetDocument, function(objects, element) {
348 if (self._extends && !self._isExpanded) {
349 var _extends = self._extends,
350 element = _extends.element,
351 instances = _extends.instances,
352 instancesMapping = _extends.instancesMapping,
353 elementId = _extends.elementId;
354
355 if (!element && elementId) {
356 element = element.querySelector("*[data-montage-id='" + elementId + "']");
357 }
358
359 if (!instances) {
360 if (instancesMapping) {
361 instances = {};
362 for (var label in instancesMapping) {
363 instances[label] = objects[instancesMapping[label]];
364 }
365 instances.owner = objects.owner;
366 } else {
367 instances = {owner: objects.owner};
368 }
369 }
370 self._extendsTemplateWithInstances(_extends.templateModuleId, element, instances, function(extendsObjects) {
371 var labels = Object.keys(extendsObjects);
372
373 for (var i =0, label; (label = labels[i]); i++) {
374 objects[label] = extendsObjects[label];
375 }
376 importHeaders(objects);
377 });
378 } else {
379 importHeaders(objects);
380 }
381 });
382 }
383 },
384
306 /** 385