From b7266f76b76a0a67000144d2780a8f64967fafb4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 18 Jun 2013 12:07:51 +0200 Subject: [PATCH 1/1] Layout informs its views on being shown --- fnpjs/layout.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fnpjs/layout.js b/fnpjs/layout.js index a7c27fe..99b2e58 100644 --- a/fnpjs/layout.js +++ b/fnpjs/layout.js @@ -2,12 +2,25 @@ define(['libs/jquery-1.9.1.min', 'libs/underscore-min'], function($ ,_) { 'use strict'; var Layout = function(template) { + var layout = this; this.dom = $(_.template(template)()); + this.views = {}; + + this.dom.onShow = function() { + _.values(layout.views).forEach(function(view) { + if(view.onShow) + view.onShow(); + }); + }; }; Layout.prototype.setView = function(place, view) { this.dom.find('[fnpjs-place=' + place + ']').append(view); + this.views[place] = view; + if(this.dom.is(':visible') && view.onShow) { + view.onShow(); + } }; Layout.prototype.getAsView = function() { -- 2.20.1