X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/5fbecb65c701a7680aae9258ff16df6a1e9f35f5..9f3a5ef91227a4ebd1b5c397bb11c067d03f7758:/modules/tabsManager.js?ds=sidebyside diff --git a/modules/tabsManager.js b/modules/tabsManager.js index cec88dc..4ede9a0 100644 --- a/modules/tabsManager.js +++ b/modules/tabsManager.js @@ -3,7 +3,7 @@ rng.modules.tabsManager = function(sandbox) { var $ = sandbox.$; var view = $(sandbox.getTemplate('main')()); - + var currentSlug; var tabContent = {}; function selectTab(slug) { @@ -14,17 +14,23 @@ rng.modules.tabsManager = function(sandbox) { 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=#' + slug + ']').parent().addClass('active'); if(prevSlug) tabContent[prevSlug].detach(); tabContent[slug].appendTo(view.find('#rng-tabsManager-content')); + currentSlug = slug; + sandbox.publish('showed', slug); } - - view.on('click', 'li a', function(e) { + view.on('click', '#rng-tabsManager-tabBar li a', function(e) { selectTab($(e.target).attr('href').substr(1)); }); @@ -42,6 +48,9 @@ rng.modules.tabsManager = function(sandbox) { view.find('#rng-tabsManager-tabBar').append(sandbox.getTemplate('tabHandle')({title: title, slug: slug})); if(_.values(tabContent).length === 1) selectTab(slug); + }, + getCurrentSlug: function() { + return currentSlug; } }