Layout informs its views on being shown
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 18 Jun 2013 10:07:51 +0000 (12:07 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 18 Jun 2013 10:07:51 +0000 (12:07 +0200)
fnpjs/layout.js

index a7c27fe..99b2e58 100644 (file)
@@ -2,12 +2,25 @@ define(['libs/jquery-1.9.1.min', 'libs/underscore-min'], function($ ,_) {
     'use strict';\r
       \r
     var Layout = function(template) {\r
     'use strict';\r
       \r
     var Layout = function(template) {\r
+        var layout = this;\r
         this.dom = $(_.template(template)());\r
         this.dom = $(_.template(template)());\r
+        this.views = {};\r
+        \r
+        this.dom.onShow = function() {\r
+            _.values(layout.views).forEach(function(view) {\r
+                if(view.onShow)\r
+                    view.onShow();\r
+            });\r
+        };\r
         \r
     };\r
     \r
     Layout.prototype.setView = function(place, view) {\r
         this.dom.find('[fnpjs-place=' + place + ']').append(view);\r
         \r
     };\r
     \r
     Layout.prototype.setView = function(place, view) {\r
         this.dom.find('[fnpjs-place=' + place + ']').append(view);\r
+        this.views[place] = view;\r
+        if(this.dom.is(':visible') && view.onShow) {\r
+            view.onShow();\r
+        }\r
     };\r
     \r
     Layout.prototype.getAsView = function() {\r
     };\r
     \r
     Layout.prototype.getAsView = function() {\r