tabs_list.js 1.27 KB
Newer Older
1 2 3 4 5 6 7 8
(function(define, undefined) {
    'use strict';
    define([
        'underscore', 'backbone', 'js/edxnotes/views/tab_item'
    ], function(_, Backbone, TabItemView) {
        var TabsListView = Backbone.View.extend({
            tagName: 'ul',
            className: 'tabs',
9

10 11 12
            initialize: function(options) {
                this.options = options;
                this.listenTo(this.collection, {
Eric Fischer committed
13 14
                    add: this.createTab,
                    destroy: function(model, collection) {
15 16 17
                        if (model.isActive() && collection.length) {
                            collection.at(0).activate();
                        }
18
                    }
19 20 21 22 23 24 25
                });
            },

            render: function() {
                this.collection.each(this.createTab, this);
                if (this.collection.length) {
                    this.collection.at(0).activate();
26
                }
27 28
                return this;
            },
29

30 31 32 33 34 35
            createTab: function(model) {
                var tab = new TabItemView({
                    model: model
                });
                tab.render().$el.appendTo(this.$el);
                return tab;
36
            }
37
        });
38

39
        return TabsListView;
40 41
    });
}).call(this, define || RequireJS.define);