##// END OF EJS Templates
optionally 1n, 2l
Matthias BUSSONNIER -
Show More
@@ -1,94 +1,94
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008 The IPython Development Team
2 // Copyright (C) 2008 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // ToolBar
9 // ToolBar
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13
13
14 var ToolBar = function (selector) {
14 var ToolBar = function (selector) {
15 this.selector = selector;
15 this.selector = selector;
16 if (this.selector !== undefined) {
16 if (this.selector !== undefined) {
17 this.element = $(selector);
17 this.element = $(selector);
18 this.style();
18 this.style();
19 }
19 }
20 };
20 };
21
21
22 // add a group of button into the current toolbar.
22 // add a group of button into the current toolbar.
23 //
23 //
24 // First argument : Mandatory
24 // First argument : Mandatory
25 // list of dict as argument, each dict should contain
25 // list of dict as argument, each dict should contain
26 // 3 mandatory keys and values :
26 // 3 mandatory keys and values :
27 // label : string -- the text to show on hover
27 // label : string -- the text to show on hover
28 // icon : string -- the jQuery-ui icon to add on this button
28 // icon : string -- the jQuery-ui icon to add on this button
29 // callback : function -- the callback to execute on a click
29 // callback : function -- the callback to execute on a click
30 //
30 //
31 // and optionnaly an 'id' key that is assigned to the button element
31 // and optionally an 'id' key that is assigned to the button element
32 //
32 //
33 // Second Argument, optionnal,
33 // Second Argument, optional,
34 // string reprensenting the id to give to the button group.
34 // string reprensenting the id to give to the button group.
35 //
35 //
36 // Example
36 // Example
37 //
37 //
38 // IPython.toolbar.add_button_group([
38 // IPython.toolbar.add_button_group([
39 // {label:'my button',
39 // {label:'my button',
40 // icon:'ui-icon-disk',
40 // icon:'ui-icon-disk',
41 // callback:function(){alert('hoho'),
41 // callback:function(){alert('hoho'),
42 // id : 'my_button_id', // this is optionnal
42 // id : 'my_button_id', // this is optional
43 // }
43 // }
44 // },
44 // },
45 // {label:'my second button',
45 // {label:'my second button',
46 // icon:'ui-icon-scissors',
46 // icon:'ui-icon-scissors',
47 // callback:function(){alert('be carefull I cut')}
47 // callback:function(){alert('be carefull I cut')}
48 // }
48 // }
49 // ],
49 // ],
50 // "my_button_group_id"
50 // "my_button_group_id"
51 // )
51 // )
52 //
52 //
53 ToolBar.prototype.add_button_group = function(list, group_id){
53 ToolBar.prototype.add_button_group = function(list, group_id){
54 var span_group = $('<span/>');
54 var span_group = $('<span/>');
55 if( group_id != undefined )
55 if( group_id != undefined )
56 span_group.attr('id',group_id)
56 span_group.attr('id',group_id)
57 for(var el in list)
57 for(var el in list)
58 {
58 {
59 var button = $('<button/>').button({
59 var button = $('<button/>').button({
60 icons : {primary: list[el].icon},
60 icons : {primary: list[el].icon},
61 text : false,
61 text : false,
62 label: list[el].label,
62 label: list[el].label,
63 });
63 });
64 var id = list[el].id;
64 var id = list[el].id;
65 if( id != undefined )
65 if( id != undefined )
66 button.attr('id',id);
66 button.attr('id',id);
67 var fun = list[el].callback;
67 var fun = list[el].callback;
68 button.click(fun);
68 button.click(fun);
69 span_group.append(button);
69 span_group.append(button);
70 }
70 }
71 span_group.buttonset();
71 span_group.buttonset();
72 $(this.selector).append(span_group)
72 $(this.selector).append(span_group)
73 }
73 }
74
74
75 ToolBar.prototype.style = function () {
75 ToolBar.prototype.style = function () {
76 this.element.addClass('border-box-sizing').
76 this.element.addClass('border-box-sizing').
77 addClass('ui-widget ui-widget-content toolbar').
77 addClass('ui-widget ui-widget-content toolbar').
78 css('border-top-style','none').
78 css('border-top-style','none').
79 css('border-left-style','none').
79 css('border-left-style','none').
80 css('border-right-style','none');
80 css('border-right-style','none');
81 };
81 };
82
82
83
83
84 ToolBar.prototype.toggle = function () {
84 ToolBar.prototype.toggle = function () {
85 this.element.toggle();
85 this.element.toggle();
86 IPython.layout_manager.do_resize();
86 IPython.layout_manager.do_resize();
87 };
87 };
88
88
89
89
90 IPython.ToolBar = ToolBar;
90 IPython.ToolBar = ToolBar;
91
91
92 return IPython;
92 return IPython;
93
93
94 }(IPython));
94 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now