X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/a5871ab5512d87a33e7e95451d26ee7d3e789742..9201c5810622e27a19de7e331046108d7110c46b:/modules/tabsManager.js?ds=inline diff --git a/modules/tabsManager.js b/modules/tabsManager.js index a57a47e..4ede9a0 100644 --- a/modules/tabsManager.js +++ b/modules/tabsManager.js @@ -3,19 +3,34 @@ rng.modules.tabsManager = function(sandbox) { var $ = sandbox.$; var view = $(sandbox.getTemplate('main')()); - + var currentSlug; var tabContent = {}; - function selectTab(tabCode) { - var tabBar = $(view, '#rng-main-tabs'); - var prevTabCode = tabBar.find('li.active a').attr('href').substr(1); + function selectTab(slug) { + var tabBar = view.find('#rng-tabsManager-tabBar'); + + var prevActive = tabBar.find('li.active'); + var prevSlug; + if(prevActive.length) + prevSlug = prevActive.find('a').attr('href').substr(1); + + if(prevSlug == slug) + return; + if(prevSlug) + sandbox.publish('leaving', prevSlug); + tabBar.find('li').removeClass('active'); - tabBar.find('a[href=#' + tabCode + ']').parent().addClass('active'); - $(view, '.rng-tab-content').hide(); - $(view, '#rng-tab-content-' + tabCode).show(); + tabBar.find('a[href=#' + slug + ']').parent().addClass('active'); + + if(prevSlug) + tabContent[prevSlug].detach(); + tabContent[slug].appendTo(view.find('#rng-tabsManager-content')); + currentSlug = slug; + sandbox.publish('showed', slug); } + - $('#rng-main-tabs li a').click(function(e) { + view.on('click', '#rng-tabsManager-tabBar li a', function(e) { selectTab($(e.target).attr('href').substr(1)); }); @@ -28,8 +43,14 @@ rng.modules.tabsManager = function(sandbox) { return view; }, - addTab: function(title, view) { - tabContent[title] = view; + addTab: function(title, slug, contentView) { + tabContent[slug] = contentView; + view.find('#rng-tabsManager-tabBar').append(sandbox.getTemplate('tabHandle')({title: title, slug: slug})); + if(_.values(tabContent).length === 1) + selectTab(slug); + }, + getCurrentSlug: function() { + return currentSlug; } }