##// 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 render: function(){
64 render: function(){
65 this.$el = $('<div />');
65 this.$el = $('<div />');
66 var uuid = IPython.utils.uuid();
66 var uuid = IPython.utils.uuid();
67 var that = this;
67 this.$tabs = $('<div />', {id: uuid})
68 this.$tabs = $('<div />', {id: uuid})
68 .addClass('nav')
69 .addClass('nav')
69 .addClass('nav-tabs')
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 return IPython.WidgetView.prototype.update.call(this);
94 return IPython.WidgetView.prototype.update.call(this);
89 },
95 },
90
96
@@ -103,8 +109,9 b' require(["notebook/js/widget"], function(){'
103 .html('Page ' + index)
109 .html('Page ' + index)
104 .appendTo(tab)
110 .appendTo(tab)
105 .click(function (e) {
111 .click(function (e) {
106 that.$tabs.find('li')
112 that.model.set("selected_index", index);
107 .removeClass('active');
113 that.model.update_other_views(that);
114 that.select_page(index);
108 });
115 });
109 this.containers.push(tab_text);
116 this.containers.push(tab_text);
110
117
@@ -119,6 +126,12 b' require(["notebook/js/widget"], function(){'
119 }
126 }
120 this.update();
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 IPython.notebook.widget_manager.register_widget_view('TabView', TabView);
137 IPython.notebook.widget_manager.register_widget_view('TabView', TabView);
@@ -15,7 +15,7 b' pages.'
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 from widget import Widget
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 # Classes
21 # Classes
@@ -25,8 +25,9 b' class MulticontainerWidget(Widget):'
25 default_view_name = Unicode('TabView')
25 default_view_name = Unicode('TabView')
26
26
27 # Keys
27 # Keys
28 _keys = ['_titles']
28 _keys = ['_titles', 'selected_index']
29 _titles = Dict(help="Titles of the pages")
29 _titles = Dict(help="Titles of the pages")
30 selected_index = Int(0)
30
31
31 # Public methods
32 # Public methods
32 def set_title(self, index, title):
33 def set_title(self, index, title):
General Comments 0
You need to be logged in to leave comments. Login now