From 5fbecb65c701a7680aae9258ff16df6a1e9f35f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 8 Apr 2013 13:57:34 +0200 Subject: [PATCH] Two tabs working --- modules/rng.js | 12 +++++++++--- modules/sourceEditor.js | 4 ++++ modules/tabsManager.js | 30 +++++++++++++++++++++--------- modules/visualEditor.js | 4 ++++ 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/modules/rng.js b/modules/rng.js index 0d40c2e..98b4619 100644 --- a/modules/rng.js +++ b/modules/rng.js @@ -1,7 +1,7 @@ rng.modules.rng = function(sandbox) { - function addTab(title, view) { - sandbox.getModule('tabsModule').addTab(title, view); + function addTab(title, slug, view) { + sandbox.getModule('tabsManager').addTab(title, slug, view); } /* Events handling */ @@ -25,7 +25,13 @@ rng.modules.rng = function(sandbox) { eventHandlers.sourceEditor = { ready: function() { - addTab('Source', sandbox.getModule('sourceEditor').getView()); + addTab('Source', 'source', sandbox.getModule('sourceEditor').getView()); + } + }; + + eventHandlers.visualEditor = { + ready: function() { + addTab('Visual', 'visual', sandbox.getModule('visualEditor').getView()); } }; diff --git a/modules/sourceEditor.js b/modules/sourceEditor.js index 59b663e..ea84ee3 100644 --- a/modules/sourceEditor.js +++ b/modules/sourceEditor.js @@ -2,6 +2,10 @@ rng.modules.sourceEditor = function(sandbox) { return { start: function() { + sandbox.publish('ready'); + }, + getView: function() { + return $('

source editor

'); } } diff --git a/modules/tabsManager.js b/modules/tabsManager.js index a57a47e..cec88dc 100644 --- a/modules/tabsManager.js +++ b/modules/tabsManager.js @@ -6,16 +6,25 @@ rng.modules.tabsManager = function(sandbox) { 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); + 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')); } + + - $('#rng-main-tabs li a').click(function(e) { + view.on('click', 'li a', function(e) { selectTab($(e.target).attr('href').substr(1)); }); @@ -28,8 +37,11 @@ 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); } } diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 29506a5..e53bfbf 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -2,6 +2,10 @@ rng.modules.visualEditor = function(sandbox) { return { start: function() { + sandbox.publish('ready'); + }, + getView: function() { + return $('

visual editor

'); } } -- 2.20.1