Layout and tabs view informs its views about being hidden
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 18 Jun 2013 10:25:00 +0000 (12:25 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 18 Jun 2013 10:25:00 +0000 (12:25 +0200)
fnpjs/layout.js
views/tabs/tabs.js

index 99b2e58..5fe61cc 100644 (file)
@@ -12,6 +12,12 @@ define(['libs/jquery-1.9.1.min', 'libs/underscore-min'], function($ ,_) {
                     view.onShow();\r
             });\r
         };\r
                     view.onShow();\r
             });\r
         };\r
+        this.dom.onHide = function() {\r
+            _.values(layout.views).forEach(function(view) {\r
+                if(view.onHide)\r
+                    view.onHide();\r
+            });\r
+        };\r
         \r
     };\r
     \r
         \r
     };\r
     \r
index 7298d4e..bc14083 100644 (file)
@@ -57,8 +57,12 @@ define([
             if(slug !== this.selectedTab && this.contents[slug]) {\r
                 this.trigger('leaving', this.selectedTab);\r
                 \r
             if(slug !== this.selectedTab && this.contents[slug]) {\r
                 this.trigger('leaving', this.selectedTab);\r
                 \r
-                if(this.selectedTab)\r
-                    this.contents[this.selectedTab].detach();\r
+                if(this.selectedTab) {\r
+                    var toDetach = this.contents[this.selectedTab];\r
+                    if(toDetach.onHide)\r
+                        toDetach.onHide();\r
+                    toDetach.detach();\r
+                }\r
                 this.nodes.content.append(this.contents[slug]);\r
                 if(this.contents[slug].onShow) {\r
                     this.contents[slug].onShow();\r
                 this.nodes.content.append(this.contents[slug]);\r
                 if(this.contents[slug].onShow) {\r
                     this.contents[slug].onShow();\r