toolbar.js
109 lines
| 3.3 KiB
| application/javascript
|
JavascriptLexer
Brian Granger
|
r5993 | //---------------------------------------------------------------------------- | ||
Matthias BUSSONNIER
|
r7832 | // Copyright (C) 2008 The IPython Development Team | ||
Brian Granger
|
r5993 | // | ||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
//============================================================================ | ||||
// ToolBar | ||||
//============================================================================ | ||||
Matthias BUSSONNIER
|
r8769 | /** | ||
* @module IPython | ||||
* @namespace IPython | ||||
* @submodule ToolBar | ||||
*/ | ||||
Brian Granger
|
r5993 | |||
var IPython = (function (IPython) { | ||||
Matthias BUSSONNIER
|
r12103 | "use strict"; | ||
Brian Granger
|
r5993 | |||
Matthias BUSSONNIER
|
r8769 | /** | ||
* A generic toolbar on which one can add button | ||||
* @class ToolBar | ||||
* @constructor | ||||
* @param {Dom object} selector | ||||
*/ | ||||
Brian Granger
|
r5993 | var ToolBar = function (selector) { | ||
this.selector = selector; | ||||
if (this.selector !== undefined) { | ||||
this.element = $(selector); | ||||
this.style(); | ||||
} | ||||
}; | ||||
Matthias BUSSONNIER
|
r8769 | /** | ||
* add a group of button into the current toolbar. | ||||
* | ||||
* | ||||
* @example | ||||
* | ||||
Matthias BUSSONNIER
|
r9055 | * IPython.toolbar.add_buttons_group([ | ||
Matthias BUSSONNIER
|
r8769 | * { | ||
* label:'my button', | ||||
MinRK
|
r10889 | * icon:'icon-hdd', | ||
Matthias BUSSONNIER
|
r9542 | * callback:function(){alert('hoho')}, | ||
Matthias BUSSONNIER
|
r8769 | * id : 'my_button_id', // this is optional | ||
* }, | ||||
* { | ||||
* label:'my second button', | ||||
MinRK
|
r10889 | * icon:'icon-play', | ||
Matthias BUSSONNIER
|
r8769 | * callback:function(){alert('be carefull I cut')} | ||
* } | ||||
* ], | ||||
* "my_button_group_id" | ||||
* ) | ||||
* | ||||
* @method add_buttons_group | ||||
* @param list {List} | ||||
* List of button of the group, with the following paramter for each : | ||||
* @param list.label {string} text to show on button hover | ||||
MinRK
|
r10889 | * @param list.icon {string} icon to choose from [Font Awesome](http://fortawesome.github.io/Font-Awesome) | ||
Matthias BUSSONNIER
|
r8769 | * @param list.callback {function} function to be called on button click | ||
* @param [list.id] {String} id to give to the button | ||||
* @param [group_id] {String} optionnal id to give to the group | ||||
* | ||||
*/ | ||||
Matthias BUSSONNIER
|
r8212 | ToolBar.prototype.add_buttons_group = function (list, group_id) { | ||
MinRK
|
r10889 | var btn_group = $('<div/>').addClass("btn-group"); | ||
Matthias BUSSONNIER
|
r8209 | if( group_id != undefined ) { | ||
MinRK
|
r10889 | btn_group.attr('id',group_id); | ||
Matthias BUSSONNIER
|
r8209 | } | ||
for(var el in list) { | ||||
MinRK
|
r10889 | var button = $('<button/>') | ||
.addClass('btn') | ||||
.attr("title", list[el].label) | ||||
.append( | ||||
$("<i/>").addClass(list[el].icon) | ||||
); | ||||
Matthias BUSSONNIER
|
r7837 | var id = list[el].id; | ||
Matthias BUSSONNIER
|
r7832 | if( id != undefined ) | ||
button.attr('id',id); | ||||
Matthias BUSSONNIER
|
r7837 | var fun = list[el].callback; | ||
Matthias BUSSONNIER
|
r7832 | button.click(fun); | ||
MinRK
|
r10889 | btn_group.append(button); | ||
Matthias BUSSONNIER
|
r7832 | } | ||
MinRK
|
r10889 | $(this.selector).append(btn_group); | ||
Matthias BUSSONNIER
|
r8209 | }; | ||
Brian Granger
|
r5993 | |||
ToolBar.prototype.style = function () { | ||||
MinRK
|
r10889 | this.element.addClass('border-box-sizing') | ||
.addClass('toolbar'); | ||||
Brian Granger
|
r5993 | }; | ||
Matthias BUSSONNIER
|
r8769 | /** | ||
* Show and hide toolbar | ||||
* @method toggle | ||||
*/ | ||||
Brian Granger
|
r5994 | ToolBar.prototype.toggle = function () { | ||
this.element.toggle(); | ||||
Matthias BUSSONNIER
|
r8212 | if (IPython.layout_manager != undefined) { | ||
IPython.layout_manager.do_resize(); | ||||
} | ||||
Brian Granger
|
r5993 | }; | ||
IPython.ToolBar = ToolBar; | ||||
return IPython; | ||||
}(IPython)); | ||||