Another set of missing semicolons
[fnpeditor.git] / views / tabs / tabs.js
index dcd3e96..2a0bfb9 100644 (file)
@@ -26,22 +26,29 @@ define([
             this.nodes = {\r
                 tabBar: this.$('.rng-view-tabs-tabBar'),\r
                 content: this.$('.rng-view-tabs-content')\r
             this.nodes = {\r
                 tabBar: this.$('.rng-view-tabs-tabBar'),\r
                 content: this.$('.rng-view-tabs-content')\r
-            }\r
+            };\r
             \r
             if(this.options.stacked) {\r
             \r
             if(this.options.stacked) {\r
-                this.nodes.tabBar.addClass('nav-stacked nav-pills');\r
+                this.nodes.tabBar.addClass('nav-stacked nav-pills').removeClass('nav-tabs');\r
+            }\r
+            if(this.options.position === 'right') {\r
+                this.$el.addClass('tabs-right');\r
+                this.nodes.content.addClass('tab-content');\r
             }\r
             }\r
+            return this;\r
         },\r
         \r
         addTab: function(title, slug, content) {\r
         },\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.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
             if(!this.selectedTab)\r
                 this.selectTab(slug);\r
         },\r
@@ -50,17 +57,37 @@ 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
                 this.nodes.content.append(this.contents[slug]);\r
+                if(this.contents[slug].onShow) {\r
+                    this.contents[slug].onShow();\r
+                }\r
                 this.nodes.tabBar.find('.active').removeClass('active');\r
                 this.nodes.tabBar.find('a[href="#'+slug+'"]').parent().addClass('active');\r
                 \r
                 this.nodes.tabBar.find('.active').removeClass('active');\r
                 this.nodes.tabBar.find('a[href="#'+slug+'"]').parent().addClass('active');\r
                 \r
+                var prevSlug = this.selectedTab;\r
                 this.selectedTab = slug;\r
                 this.selectedTab = slug;\r
-                this.trigger('tabSelected', slug);\r
+                this.trigger('tabSelected', {slug: slug, prevSlug: prevSlug});\r
             }\r
         },\r
         \r
             }\r
         },\r
         \r
+        getAsView: function() {\r
+            return this.$el;\r
+        },\r
+        \r
+        getCurrentSlug: function() {\r
+            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
         /* Events */\r
         \r
         _onTabTitleClicked: function(e) {\r
@@ -76,7 +103,7 @@ define([
     \r
     return {\r
         View: View\r
     \r
     return {\r
         View: View\r
-    }\r
+    };\r
     \r
 \r
 });
\ No newline at end of file
     \r
 \r
 });
\ No newline at end of file