Sha256: 203ac32cadb7d6a6b2a4c270049b012a68832162969fd1fe93fc779343d2e372

Contents?: true

Size: 1.38 KB

Versions: 11

Compression:

Stored size: 1.38 KB

Contents

pageflow.TabsView = Backbone.Marionette.Layout.extend({
  template: 'templates/tabs_view',
  className: 'tabs_view',

  ui: {
    headers: '> ul',
  },

  regions: {
    container: '> div'
  },

  events: {
    'click > ul > li': function(event) {
      this.changeTab($(event.target).data('tab-name'));
    }
  },

  initialize: function() {
    this.tabFactoryFns = {};
    this.tabNames = [];
    this.currentTabName = null;
  },

  tab: function(name, factoryFn) {
    this.tabFactoryFns[name] = factoryFn;
    this.tabNames.push(name);
  },

  onRender: function() {
    _.each(this.tabNames, function(name) {
      this.ui.headers.append(
        $('<li />')
          .attr('data-tab-name', name)
          .text(I18n.t(this.options.i18n + '.' + name))
      );
    }, this);

    this.changeTab(this.options.defaultTab || _.first(this.tabNames));
  },

  changeTab: function(name) {
    this.container.show(this.tabFactoryFns[name]());
    this._updateActiveHeader(name);
    this.currentTabName = name;
  },

  refresh: function() {
    this.changeTab(this.currentTabName);
  },

  toggleSpinnerOnTab: function(name, visible) {
    this.$('[data-tab-name=' + name + ']').toggleClass('spinner', visible);
  },

  _updateActiveHeader: function(activeTabName) {
    this.ui.headers.children().each(function() {
      $(this).toggleClass('active', $(this).data('tab-name') === activeTabName);
    });
  }
});

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pageflow-0.5.0 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.4.0 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.3.0 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.2.1 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.2.0 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.1.0 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.0.5 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.0.4 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.0.3 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.0.2 app/assets/javascripts/pageflow/editor/views/tabs_view.js
pageflow-0.0.1 app/assets/javascripts/pageflow/editor/views/tabs_view.js