\r
var tabContent = {};\r
\r
- function selectTab(tabCode) {\r
- var tabBar = $(view, '#rng-main-tabs');\r
- var prevTabCode = tabBar.find('li.active a').attr('href').substr(1);\r
+ function selectTab(slug) {\r
+ var tabBar = view.find('#rng-tabsManager-tabBar');\r
+ \r
+ var prevActive = tabBar.find('li.active');\r
+ var prevSlug;\r
+ if(prevActive.length)\r
+ prevSlug = prevActive.find('a').attr('href').substr(1);\r
+ \r
+ if(prevSlug == slug)\r
+ return;\r
+ \r
tabBar.find('li').removeClass('active');\r
- tabBar.find('a[href=#' + tabCode + ']').parent().addClass('active');\r
- $(view, '.rng-tab-content').hide();\r
- $(view, '#rng-tab-content-' + tabCode).show();\r
+ tabBar.find('a[href=#' + slug + ']').parent().addClass('active');\r
+ \r
+ if(prevSlug)\r
+ tabContent[prevSlug].detach();\r
+ tabContent[slug].appendTo(view.find('#rng-tabsManager-content'));\r
}\r
+ \r
+ \r
\r
- $('#rng-main-tabs li a').click(function(e) {\r
+ view.on('click', 'li a', function(e) {\r
selectTab($(e.target).attr('href').substr(1));\r
});\r
\r
return view;\r
},\r
\r
- addTab: function(title, view) {\r
- tabContent[title] = view;\r
+ addTab: function(title, slug, contentView) {\r
+ tabContent[slug] = contentView;\r
+ view.find('#rng-tabsManager-tabBar').append(sandbox.getTemplate('tabHandle')({title: title, slug: slug}));\r
+ if(_.values(tabContent).length === 1)\r
+ selectTab(slug);\r
}\r
}\r
\r