//----------------------------------------------------------------------------1// Copyright (C) 2008 The IPython Development Team2//3// Distributed under the terms of the BSD License. The full license is in4// the file COPYING, distributed as part of this software.5//----------------------------------------------------------------------------67//============================================================================8// ToolBar9//============================================================================10/**11* @module IPython12* @namespace IPython13* @submodule ToolBar14*/1516var IPython = (function (IPython) {17"use strict";1819/**20* A generic toolbar on which one can add button21* @class ToolBar22* @constructor23* @param {Dom object} selector24*/25var ToolBar = function (selector) {26this.selector = selector;27if (this.selector !== undefined) {28this.element = $(selector);29this.style();30}31};3233/**34* add a group of button into the current toolbar.35*36*37* @example38*39* IPython.toolbar.add_buttons_group([40* {41* label:'my button',42* icon:'icon-hdd',43* callback:function(){alert('hoho')},44* id : 'my_button_id', // this is optional45* },46* {47* label:'my second button',48* icon:'icon-play',49* callback:function(){alert('be carefull I cut')}50* }51* ],52* "my_button_group_id"53* )54*55* @method add_buttons_group56* @param list {List}57* List of button of the group, with the following paramter for each :58* @param list.label {string} text to show on button hover59* @param list.icon {string} icon to choose from [Font Awesome](http://fortawesome.github.io/Font-Awesome)60* @param list.callback {function} function to be called on button click61* @param [list.id] {String} id to give to the button62* @param [group_id] {String} optionnal id to give to the group63*64*/65ToolBar.prototype.add_buttons_group = function (list, group_id) {66var btn_group = $('<div/>').addClass("btn-group");67if( group_id !== undefined ) {68btn_group.attr('id',group_id);69}70var el;71for(var i=0; i < list.length; i++) {72el = list[i];73var button = $('<button/>')74.addClass('btn')75.attr("title", el.label)76.append(77$("<i/>").addClass(el.icon)78);79var id = el.id;80if( id !== undefined )81button.attr('id',id);82var fun = el.callback;83button.click(fun);84btn_group.append(button);85}86$(this.selector).append(btn_group);87};8889ToolBar.prototype.style = function () {90this.element.addClass('border-box-sizing')91.addClass('toolbar');92};9394/**95* Show and hide toolbar96* @method toggle97*/98ToolBar.prototype.toggle = function () {99this.element.toggle();100if (IPython.layout_manager !== undefined) {101IPython.layout_manager.do_resize();102}103};104105106IPython.ToolBar = ToolBar;107108return IPython;109110}(IPython));111112113