##// END OF EJS Templates
Added style for widget modal
Added style for widget modal

File last commit:

r14398:4af2a2b8
r14407:e377c57c
Show More
multicontainer.js
179 lines | 6.4 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Added standard IPY JS header to widget JS files.
r14366 //----------------------------------------------------------------------------
// Copyright (C) 2013 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------
//============================================================================
// MultiContainerWidget
//============================================================================
/**
* @module IPython
* @namespace IPython
**/
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 define(["notebook/js/widget"], function(widget_manager){
Jonathan Frederic
Added multicontainer widget
r14284 var MulticontainerModel = IPython.WidgetModel.extend({});
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_model('MulticontainerWidgetModel', MulticontainerModel);
Jonathan Frederic
Added multicontainer widget
r14284
var AccordionView = IPython.WidgetView.extend({
render: function(){
Jonathan Frederic
Make sure DOM element ids start with alphabetic characters, not numeric.
r14398 var guid = 'accordion' + IPython.utils.uuid();
this.$el = $('<div />', {id: guid})
Jonathan Frederic
Added multicontainer widget
r14284 .addClass('accordion');
Jonathan Frederic
Make sure backbone events fire....
r14395 this._ensureElement();
Jonathan Frederic
Added multicontainer widget
r14284 this.containers = [];
},
update: function() {
Jonathan Frederic
Added ability to set container page titles for widget multicontainer
r14288 // Set tab titles
var titles = this.model.get('_titles');
for (var page_index in titles) {
Jonathan Frederic
Added ability to title multicontainer pages before multicontainer display()
r14289
var accordian = this.containers[page_index]
if (accordian != undefined) {
accordian
.find('.accordion-heading')
.find('.accordion-toggle')
.html(titles[page_index]);
}
Jonathan Frederic
Added ability to set container page titles for widget multicontainer
r14288 }
Jonathan Frederic
Added multicontainer widget
r14284
Jonathan Frederic
Added selected_index support to accordion view.
r14370 // 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');
}
}
}
Jonathan Frederic
Added multicontainer widget
r14284 return IPython.WidgetView.prototype.update.call(this);
},
display_child: function(view) {
var index = this.containers.length;
var uuid = IPython.utils.uuid();
var accordion_group = $('<div />')
.addClass('accordion-group')
.appendTo(this.$el);
var accordion_heading = $('<div />')
.addClass('accordion-heading')
.appendTo(accordion_group);
Jonathan Frederic
Added selected_index support to accordion view.
r14370 var that = this;
Jonathan Frederic
Added multicontainer widget
r14284 var accordion_toggle = $('<a />')
.addClass('accordion-toggle')
.attr('data-toggle', 'collapse')
.attr('data-parent', '#' + this.$el.attr('id'))
.attr('href', '#' + uuid)
Jonathan Frederic
Added selected_index support to accordion view.
r14370 .click(function(evt){
that.model.set("selected_index", index);
that.model.update_other_views(that);
})
Jonathan Frederic
Added multicontainer widget
r14284 .html('Page ' + index)
.appendTo(accordion_heading);
var accordion_body = $('<div />', {id: uuid})
Jonathan Frederic
Added ability to set container page titles for widget multicontainer
r14288 .addClass('accordion-body collapse')
Jonathan Frederic
Added multicontainer widget
r14284 .appendTo(accordion_group);
var accordion_inner = $('<div />')
.addClass('accordion-inner')
.appendTo(accordion_body);
this.containers.push(accordion_group);
accordion_inner.append(view.$el);
Jonathan Frederic
Added selected_index support to accordion view.
r14370
Jonathan Frederic
Added ability to title multicontainer pages before multicontainer display()
r14289 this.update();
Jonathan Frederic
Added selected_index support to accordion view.
r14370
// 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);
Jonathan Frederic
Added multicontainer widget
r14284 },
});
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_view('AccordionView', AccordionView);
Jonathan Frederic
Added TabView to multicontainer
r14290
var TabView = IPython.WidgetView.extend({
render: function(){
Jonathan Frederic
Make sure DOM element ids start with alphabetic characters, not numeric.
r14398 var uuid = 'tabs'+IPython.utils.uuid();
Jonathan Frederic
Added selected_index property to TabView
r14307 var that = this;
Jonathan Frederic
Added TabView to multicontainer
r14290 this.$tabs = $('<div />', {id: uuid})
.addClass('nav')
.addClass('nav-tabs')
.appendTo(this.$el);
this.$tab_contents = $('<div />', {id: uuid + 'Content'})
.addClass('tab-content')
.appendTo(this.$el);
this.containers = [];
},
Jonathan Frederic
Added selected_index support to accordion view.
r14370
Jonathan Frederic
Added TabView to multicontainer
r14290 update: function() {
// Set tab titles
var titles = this.model.get('_titles');
for (var page_index in titles) {
var tab_text = this.containers[page_index]
if (tab_text != undefined) {
tab_text.html(titles[page_index]);
}
}
Jonathan Frederic
Added selected_index property to TabView
r14307 var selected_index = this.model.get('selected_index');
if (0 <= selected_index && selected_index < this.containers.length) {
this.select_page(selected_index);
}
Jonathan Frederic
Added TabView to multicontainer
r14290 return IPython.WidgetView.prototype.update.call(this);
},
display_child: function(view) {
var index = this.containers.length;
var uuid = IPython.utils.uuid();
var that = this;
var tab = $('<li />')
.css('list-style-type', 'none')
.appendTo(this.$tabs);
var tab_text = $('<a />')
.attr('href', '#' + uuid)
.attr('data-toggle', 'tab')
.html('Page ' + index)
.appendTo(tab)
.click(function (e) {
Jonathan Frederic
Added selected_index property to TabView
r14307 that.model.set("selected_index", index);
that.model.update_other_views(that);
that.select_page(index);
Jonathan Frederic
Added TabView to multicontainer
r14290 });
this.containers.push(tab_text);
var contents_div = $('<div />', {id: uuid})
.addClass('tab-pane')
.addClass('fade')
.append(view.$el)
.appendTo(this.$tab_contents);
if (index==0) {
tab_text.tab('show');
}
this.update();
},
Jonathan Frederic
Added selected_index property to TabView
r14307
select_page: function(index) {
this.$tabs.find('li')
.removeClass('active');
this.containers[index].tab('show');
},
Jonathan Frederic
Added TabView to multicontainer
r14290 });
Jonathan Frederic
Changed require.js load calls to allow require.js to pass...
r14374 widget_manager.register_widget_view('TabView', TabView);
Jonathan Frederic
Added TabView to multicontainer
r14290 });