Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50654 views
1
//----------------------------------------------------------------------------
2
// Copyright (C) 2008 The IPython Development Team
3
//
4
// Distributed under the terms of the BSD License. The full license is in
5
// the file COPYING, distributed as part of this software.
6
//----------------------------------------------------------------------------
7
8
//============================================================================
9
// ToolBar
10
//============================================================================
11
/**
12
* @module IPython
13
* @namespace IPython
14
* @submodule ToolBar
15
*/
16
17
var IPython = (function (IPython) {
18
"use strict";
19
20
/**
21
* A generic toolbar on which one can add button
22
* @class ToolBar
23
* @constructor
24
* @param {Dom object} selector
25
*/
26
var ToolBar = function (selector) {
27
this.selector = selector;
28
if (this.selector !== undefined) {
29
this.element = $(selector);
30
this.style();
31
}
32
};
33
34
/**
35
* add a group of button into the current toolbar.
36
*
37
*
38
* @example
39
*
40
* IPython.toolbar.add_buttons_group([
41
* {
42
* label:'my button',
43
* icon:'icon-hdd',
44
* callback:function(){alert('hoho')},
45
* id : 'my_button_id', // this is optional
46
* },
47
* {
48
* label:'my second button',
49
* icon:'icon-play',
50
* callback:function(){alert('be carefull I cut')}
51
* }
52
* ],
53
* "my_button_group_id"
54
* )
55
*
56
* @method add_buttons_group
57
* @param list {List}
58
* List of button of the group, with the following paramter for each :
59
* @param list.label {string} text to show on button hover
60
* @param list.icon {string} icon to choose from [Font Awesome](http://fortawesome.github.io/Font-Awesome)
61
* @param list.callback {function} function to be called on button click
62
* @param [list.id] {String} id to give to the button
63
* @param [group_id] {String} optionnal id to give to the group
64
*
65
*/
66
ToolBar.prototype.add_buttons_group = function (list, group_id) {
67
var btn_group = $('<div/>').addClass("btn-group");
68
if( group_id !== undefined ) {
69
btn_group.attr('id',group_id);
70
}
71
var el;
72
for(var i=0; i < list.length; i++) {
73
el = list[i];
74
var button = $('<button/>')
75
.addClass('btn')
76
.attr("title", el.label)
77
.append(
78
$("<i/>").addClass(el.icon)
79
);
80
var id = el.id;
81
if( id !== undefined )
82
button.attr('id',id);
83
var fun = el.callback;
84
button.click(fun);
85
btn_group.append(button);
86
}
87
$(this.selector).append(btn_group);
88
};
89
90
ToolBar.prototype.style = function () {
91
this.element.addClass('border-box-sizing')
92
.addClass('toolbar');
93
};
94
95
/**
96
* Show and hide toolbar
97
* @method toggle
98
*/
99
ToolBar.prototype.toggle = function () {
100
this.element.toggle();
101
if (IPython.layout_manager !== undefined) {
102
IPython.layout_manager.do_resize();
103
}
104
};
105
106
107
IPython.ToolBar = ToolBar;
108
109
return IPython;
110
111
}(IPython));
112
113