From a226bd2d6e9ca1eb3ec1135917ddb0033c89d16b Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Thu, 3 Jul 2014 10:52:28 -0700 Subject: [PATCH] Fixed cell toolbars --- .../html/static/notebook/js/celltoolbar.js | 19 ++-- .../notebook/js/celltoolbarpresets/default.js | 44 ++++----- .../notebook/js/celltoolbarpresets/example.js | 94 +++++++++---------- .../notebook/js/celltoolbarpresets/rawcell.js | 41 ++++---- .../js/celltoolbarpresets/slideshow.js | 42 ++++----- IPython/html/static/notebook/js/codecell.js | 2 +- .../notebook/js/codemirror-ipythongfm.js | 1 - .../html/static/notebook/js/maintoolbar.js | 3 +- IPython/html/static/notebook/js/notebook.js | 15 ++- 9 files changed, 127 insertions(+), 134 deletions(-) diff --git a/IPython/html/static/notebook/js/celltoolbar.js b/IPython/html/static/notebook/js/celltoolbar.js index b17bea80d..3394218af 100644 --- a/IPython/html/static/notebook/js/celltoolbar.js +++ b/IPython/html/static/notebook/js/celltoolbar.js @@ -4,8 +4,7 @@ define([ 'base/js/namespace', 'jquery', - 'notebook/js/textcell', -], function(IPython, $, textcell) { +], function(IPython, $) { "use strict"; var CellToolbar = function (options) { @@ -176,13 +175,13 @@ define([ * CellToolbar.register_preset('foo.foo_preset1', ['foo.c1', 'foo.c2', 'foo.c5']) * CellToolbar.register_preset('foo.foo_preset2', ['foo.c4', 'foo.c5']) */ - CellToolbar.register_preset = function(name, preset_list) { + CellToolbar.register_preset = function(name, preset_list, notebook, events) { CellToolbar._presets[name] = preset_list; - this.events.trigger('preset_added.CellToolbar', {name: name}); + events.trigger('preset_added.CellToolbar', {name: name}); // When "register_callback" is called by a custom extension, it may be executed after notebook is loaded. // In that case, activate the preset if needed. - if (this.notebook && this.notebook.metadata && this.notebook.metadata.celltoolbar === name) - this.activate_preset(name); + if (notebook && notebook.metadata && notebook.metadata.celltoolbar === name) + CellToolbar.activate_preset(name, events); }; @@ -215,7 +214,7 @@ define([ * * CellToolbar.activate_preset('foo.foo_preset1'); */ - CellToolbar.activate_preset = function(preset_name){ + CellToolbar.activate_preset = function(preset_name, events){ var preset = CellToolbar._presets[preset_name]; if(preset !== undefined){ @@ -223,8 +222,8 @@ define([ CellToolbar.rebuild_all(); } - if (this.events) { - this.events.trigger('preset_activated.CellToolbar', {name: preset_name}); + if (events) { + events.trigger('preset_activated.CellToolbar', {name: preset_name}); } }; @@ -279,7 +278,7 @@ define([ } // If there are no controls or the cell is a rendered TextCell hide the toolbar. - if (!this.ui_controls_list.length || (this.cell instanceof textcell.TextCell && this.cell.rendered)) { + if (!this.ui_controls_list.length || (this.cell_type != 'code' && this.cell.rendered)) { this.hide(); } else { this.show(); diff --git a/IPython/html/static/notebook/js/celltoolbarpresets/default.js b/IPython/html/static/notebook/js/celltoolbarpresets/default.js index cb3b12e35..29c715472 100644 --- a/IPython/html/static/notebook/js/celltoolbarpresets/default.js +++ b/IPython/html/static/notebook/js/celltoolbarpresets/default.js @@ -1,31 +1,23 @@ -//---------------------------------------------------------------------------- -// Copyright (C) 2012 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. -//---------------------------------------------------------------------------- +// Copyright (c) IPython Development Team. +// Distributed under the terms of the Modified BSD License. -//============================================================================ -// CellToolbar Default -//============================================================================ - -/** - * Example Use for the CellToolbar library - */ - // IIFE without asignement, we don't modifiy the IPython namespace -(function (IPython) { +define([ + 'jquery', + 'notebook/js/celltoolbar', + 'base/js/dialog', +], function($, celltoolbar, dialog) { "use strict"; - var CellToolbar = IPython.CellToolbar; + var CellToolbar = celltoolbar.CellToolbar; var raw_edit = function(cell){ - IPython.dialog.edit_metadata(cell.metadata, function (md) { + dialog.edit_metadata(cell.metadata, function (md) { cell.metadata = md; }); }; var add_raw_edit_button = function(div, cell) { - var button_container = div; + var button_container = $(div); var button = $('