rng.modules.rng = function(sandbox) {\r
\r
- function addTab(title, view) {\r
- sandbox.getModule('tabsModule').addTab(title, view);\r
+ function addTab(title, slug, view) {\r
+ sandbox.getModule('tabsManager').addTab(title, slug, view);\r
}\r
\r
/* Events handling */\r
\r
eventHandlers.sourceEditor = {\r
ready: function() {\r
- addTab('Source', sandbox.getModule('sourceEditor').getView());\r
+ addTab('Source', 'source', sandbox.getModule('sourceEditor').getView());\r
+ }\r
+ };\r
+ \r
+ eventHandlers.visualEditor = {\r
+ ready: function() {\r
+ addTab('Visual', 'visual', sandbox.getModule('visualEditor').getView());\r
}\r
};\r
\r
\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
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