##// END OF EJS Templates
Added selected_index property to TabView
Jonathan Frederic -
Show More
@@ -64,6 +64,7 b' require(["notebook/js/widget"], function(){'
64 64 render: function(){
65 65 this.$el = $('<div />');
66 66 var uuid = IPython.utils.uuid();
67 var that = this;
67 68 this.$tabs = $('<div />', {id: uuid})
68 69 .addClass('nav')
69 70 .addClass('nav-tabs')
@@ -85,6 +86,11 b' require(["notebook/js/widget"], function(){'
85 86 }
86 87 }
87 88
89 var selected_index = this.model.get('selected_index');
90 if (0 <= selected_index && selected_index < this.containers.length) {
91 this.select_page(selected_index);
92 }
93
88 94 return IPython.WidgetView.prototype.update.call(this);
89 95 },
90 96
@@ -103,8 +109,9 b' require(["notebook/js/widget"], function(){'
103 109 .html('Page ' + index)
104 110 .appendTo(tab)
105 111 .click(function (e) {
106 that.$tabs.find('li')
107 .removeClass('active');
112 that.model.set("selected_index", index);
113 that.model.update_other_views(that);
114 that.select_page(index);
108 115 });
109 116 this.containers.push(tab_text);
110 117
@@ -119,6 +126,12 b' require(["notebook/js/widget"], function(){'
119 126 }
120 127 this.update();
121 128 },
129
130 select_page: function(index) {
131 this.$tabs.find('li')
132 .removeClass('active');
133 this.containers[index].tab('show');
134 },
122 135 });
123 136
124 137 IPython.notebook.widget_manager.register_widget_view('TabView', TabView);
@@ -15,7 +15,7 b' pages.'
15 15 # Imports
16 16 #-----------------------------------------------------------------------------
17 17 from widget import Widget
18 from IPython.utils.traitlets import Unicode, Dict
18 from IPython.utils.traitlets import Unicode, Dict, Int
19 19
20 20 #-----------------------------------------------------------------------------
21 21 # Classes
@@ -25,8 +25,9 b' class MulticontainerWidget(Widget):'
25 25 default_view_name = Unicode('TabView')
26 26
27 27 # Keys
28 _keys = ['_titles']
28 _keys = ['_titles', 'selected_index']
29 29 _titles = Dict(help="Titles of the pages")
30 selected_index = Int(0)
30 31
31 32 # Public methods
32 33 def set_title(self, index, title):
General Comments 0
You need to be logged in to leave comments. Login now