From df248fcadb1956e5027424ab9e59c41ddd96d3bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 4 Jun 2013 15:19:23 +0200 Subject: [PATCH 1/1] Visual editor: tabs view supports icons in tab titles --- views/tabs/tabs.js | 20 ++++++++++++++++---- views/tabs/templates/handle.html | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/views/tabs/tabs.js b/views/tabs/tabs.js index 048230f..dcd3e96 100644 --- a/views/tabs/tabs.js +++ b/views/tabs/tabs.js @@ -10,10 +10,11 @@ define([ className: 'rng-view-tabs', events: { - 'click ul a': '_onTabTitleClicked' + 'click ul a, i': '_onTabTitleClicked' }, - initialize: function() { + initialize: function(options) { + this.options = options || {}; this.template = _.template(mainTemplate), this.handleTemplate = _.template(handleTemplate); this.contents = {}; @@ -26,13 +27,21 @@ define([ tabBar: this.$('.rng-view-tabs-tabBar'), content: this.$('.rng-view-tabs-content') } + + if(this.options.stacked) { + this.nodes.tabBar.addClass('nav-stacked nav-pills'); + } }, addTab: function(title, slug, content) { if(this.contents[slug]) return false; this.contents[slug] = content; - this.nodes.tabBar.append(this.handleTemplate({title:title, slug: slug})); + + var text = (typeof title === 'string') ? title : (title.text || ''); + var icon = title.icon || null; + + this.nodes.tabBar.append(this.handleTemplate({text: text, icon: icon, slug: slug})); if(!this.selectedTab) this.selectTab(slug); }, @@ -56,7 +65,10 @@ define([ _onTabTitleClicked: function(e) { e.preventDefault(); - var slug = $(e.target).attr('href').substr(1); + var target = $(e.target); + if(target.is('i')) + target = target.parent(); + var slug = target.attr('href').substr(1); this.selectTab(slug); } }); diff --git a/views/tabs/templates/handle.html b/views/tabs/templates/handle.html index e5c4728..b828ce4 100644 --- a/views/tabs/templates/handle.html +++ b/views/tabs/templates/handle.html @@ -1 +1 @@ -
  • <%= title %>
  • \ No newline at end of file +
  • <% if(icon) { %><% } %><%= text %>
  • \ No newline at end of file -- 2.20.1