tabs view: Allowing for overriding tab content
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 17 Jun 2013 19:04:49 +0000 (21:04 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 17 Jun 2013 19:04:49 +0000 (21:04 +0200)
views/tabs/tabs.js

index 43df1c1..7c94938 100644 (file)
@@ -39,14 +39,16 @@ define([
         },\r
         \r
         addTab: function(title, slug, content) {\r
-            if(this.contents[slug])\r
-                return false;\r
+            if(this.contents[slug]) {\r
+                this.contents[slug].detach();\r
+            }\r
             this.contents[slug] = content;\r
             \r
             var text = (typeof title === 'string') ? title : (title.text || '');\r
             var icon = title.icon || null;\r
             \r
-            this.nodes.tabBar.append(this.handleTemplate({text: text, icon: icon, slug: slug}));\r
+            if(!this.tabExists(slug))\r
+                this.nodes.tabBar.append(this.handleTemplate({text: text, icon: icon, slug: slug}));\r
             if(!this.selectedTab)\r
                 this.selectTab(slug);\r
         },\r
@@ -75,6 +77,10 @@ define([
             return this.selectedTab;\r
         },\r
         \r
+        tabExists: function(slug) {\r
+            return this.nodes.tabBar.find('a[href="#'+ slug + '"]').length > 0;\r
+        },\r
+        \r
         /* Events */\r
         \r
         _onTabTitleClicked: function(e) {\r