From 215060e8e80f138986d66762049c0c792a2e7758 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 15 Nov 2013 00:57:19 +0000 Subject: [PATCH] Added selected_index support to accordion view. --- .../notebook/js/widgets/multicontainer.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/IPython/html/static/notebook/js/widgets/multicontainer.js b/IPython/html/static/notebook/js/widgets/multicontainer.js index 0502f708b..e678fbdbc 100644 --- a/IPython/html/static/notebook/js/widgets/multicontainer.js +++ b/IPython/html/static/notebook/js/widgets/multicontainer.js @@ -40,6 +40,19 @@ define(["notebook/js/widget"], function(){ } } + // Set selected page + var selected_index = this.model.get("selected_index"); + if (0 <= selected_index && selected_index < this.containers.length) { + for (var index in this.containers) { + if (index==selected_index) { + this.containers[index].find('.accordion-body').collapse('show'); + } else { + this.containers[index].find('.accordion-body').collapse('hide'); + } + + } + } + return IPython.WidgetView.prototype.update.call(this); }, @@ -53,11 +66,16 @@ define(["notebook/js/widget"], function(){ var accordion_heading = $('
') .addClass('accordion-heading') .appendTo(accordion_group); + var that = this; var accordion_toggle = $('') .addClass('accordion-toggle') .attr('data-toggle', 'collapse') .attr('data-parent', '#' + this.$el.attr('id')) .attr('href', '#' + uuid) + .click(function(evt){ + that.model.set("selected_index", index); + that.model.update_other_views(that); + }) .html('Page ' + index) .appendTo(accordion_heading); var accordion_body = $('
', {id: uuid}) @@ -67,9 +85,15 @@ define(["notebook/js/widget"], function(){ .addClass('accordion-inner') .appendTo(accordion_body); this.containers.push(accordion_group); - accordion_inner.append(view.$el); + this.update(); + + // Stupid workaround to close the bootstrap accordion tabs which + // open by default even though they don't have the `in` class + // attached to them. For some reason a delay is required. + // TODO: Better fix. + setTimeout(function(){that.update()}, 500); }, }); @@ -91,7 +115,7 @@ define(["notebook/js/widget"], function(){ this.containers = []; }, - + update: function() { // Set tab titles var titles = this.model.get('_titles'); @@ -151,5 +175,4 @@ define(["notebook/js/widget"], function(){ }); IPython.widget_manager.register_widget_view('TabView', TabView); - });