From 9ae62c21b8f6bdca07d09385cb158d146b9cc89d Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 20 Oct 2014 21:19:24 +0200 Subject: [PATCH 1/3] Some cleanup unused code and missig use-strict --- IPython/html/static/base/js/namespace.js | 1 + IPython/html/static/notebook/js/notebook.js | 16 ++++++++++---- IPython/html/static/notebook/js/tooltip.js | 23 --------------------- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/IPython/html/static/base/js/namespace.js b/IPython/html/static/base/js/namespace.js index c89cbc75c..291e113c9 100644 --- a/IPython/html/static/base/js/namespace.js +++ b/IPython/html/static/base/js/namespace.js @@ -3,6 +3,7 @@ var IPython = IPython || {}; define([], function(){ + "use strict"; IPython.version = "3.0.0-dev"; return IPython; }); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 798172a7a..27bfeb200 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -40,6 +40,7 @@ define([ slideshow_celltoolbar, scrollmanager ) { + "use strict"; var Notebook = function (selector, options) { // Constructor @@ -149,14 +150,18 @@ define([ this.codemirror_mode = 'ipython'; this.create_elements(); this.bind_events(); - this.save_notebook = function() { // don't allow save until notebook_loaded - this.save_notebook_error(null, null, "Load failed, save is disabled"); - }; + this.kernel_selector = null; + this.dirty = null; + this.trusted = null; + this._fully_loaded = false; // Trigger cell toolbar registration. default_celltoolbar.register(this); rawcell_celltoolbar.register(this); slideshow_celltoolbar.register(this); + + // prevent assign to miss-typed properties. + Object.seal(this); }; Notebook.options_default = { @@ -1913,6 +1918,9 @@ define([ * @method save_notebook */ Notebook.prototype.save_notebook = function () { + if(!this._fully_loaded){ + return this.save_notebook_error(null, null, "Load failed, save is disabled"); + } // Create a JSON model to be sent to the server. var model = { type : "notebook", @@ -2240,7 +2248,7 @@ define([ } // now that we're fully loaded, it is safe to restore save functionality - delete(this.save_notebook); + this._fully_loaded = true; this.events.trigger('notebook_loaded.Notebook'); }; diff --git a/IPython/html/static/notebook/js/tooltip.js b/IPython/html/static/notebook/js/tooltip.js index e370efd30..9f0b99bf9 100644 --- a/IPython/html/static/notebook/js/tooltip.js +++ b/IPython/html/static/notebook/js/tooltip.js @@ -179,29 +179,6 @@ define([ // easy access for julia monkey patching. Tooltip.last_token_re = /[a-z_][0-9a-z._]*$/gi; - Tooltip.prototype.extract_oir_token = function(line){ - // use internally just to make the request to the kernel - // Feel free to shorten this logic if you are better - // than me in regEx - // basicaly you shoul be able to get xxx.xxx.xxx from - // something(range(10), kwarg=smth) ; xxx.xxx.xxx( firstarg, rand(234,23), kwarg1=2, - // remove everything between matchin bracket (need to iterate) - var matchBracket = /\([^\(\)]+\)/g; - var endBracket = /\([^\(]*$/g; - var oldline = line; - - line = line.replace(matchBracket, ""); - while (oldline != line) { - oldline = line; - line = line.replace(matchBracket, ""); - } - // remove everything after last open bracket - line = line.replace(endBracket, ""); - // reset the regex object - Tooltip.last_token_re.lastIndex = 0; - return Tooltip.last_token_re.exec(line); - }; - Tooltip.prototype._request_tooltip = function (cell, text, cursor_pos) { var callbacks = $.proxy(this._show, this); var msg_id = cell.kernel.inspect(text, cursor_pos, callbacks); From ac355d757f357fd0bb6b0ba20bdd1301a4bb05ab Mon Sep 17 00:00:00 2001 From: Bussonnier Matthias Date: Wed, 19 Nov 2014 21:44:03 +0100 Subject: [PATCH 2/3] update to use event --- IPython/html/static/notebook/js/notebook.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 27bfeb200..0187fd7ef 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1919,7 +1919,10 @@ define([ */ Notebook.prototype.save_notebook = function () { if(!this._fully_loaded){ - return this.save_notebook_error(null, null, "Load failed, save is disabled"); + this.events.trigger('notebook_save_failed.Notebook', + new Error("Load failed, save is disabled") + ); + return } // Create a JSON model to be sent to the server. var model = { From 907d70339e9d5f23c83af4fbd2c93991b454b832 Mon Sep 17 00:00:00 2001 From: Bussonnier Matthias Date: Wed, 19 Nov 2014 21:47:22 +0100 Subject: [PATCH 3/3] some extra comma/semicolon cleanup --- IPython/html/static/notebook/js/notebook.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 0187fd7ef..910a70d4e 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -100,7 +100,7 @@ define([ } utils.requireCodeMirrorMode(lang, function () { var el = document.createElement("div"); - mode = CodeMirror.getMode({}, lang); + var mode = CodeMirror.getMode({}, lang); if (!mode) { console.log("No CodeMirror mode: " + lang); callback(null, code); @@ -168,7 +168,7 @@ define([ // can be any cell type, or the special values of // 'above', 'below', or 'selected' to get the value from another cell. Notebook: { - default_cell_type: 'code', + default_cell_type: 'code' } }; @@ -885,7 +885,7 @@ define([ config: this.config, keyboard_manager: this.keyboard_manager, notebook: this, - tooltip: this.tooltip, + tooltip: this.tooltip }; switch(type) { case 'code': @@ -1121,7 +1121,7 @@ define([ '## This is a level 2 heading' )), buttons : { - "OK" : {}, + "OK" : {} } }); }; @@ -1922,7 +1922,7 @@ define([ this.events.trigger('notebook_save_failed.Notebook', new Error("Load failed, save is disabled") ); - return + return; } // Create a JSON model to be sent to the server. var model = {