From 7c74a0d38bee1d5dd21e1cf3ed1b49e9becb9a28 2014-12-27 20:39:07 From: Matthias Bussonnier Date: 2014-12-27 20:39:07 Subject: [PATCH] Some code cleanup in javascript and python change patern that are prone to error, like function redifinition and other. --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index e63785b..daa295b 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -243,8 +243,6 @@ class InteractiveShell(SingletonConfigurable): """ ) - banner = Unicode('') - banner1 = Unicode(default_banner, config=True, help="""The part of the banner to be printed before the profile""" ) diff --git a/IPython/html/static/notebook/js/actions.js b/IPython/html/static/notebook/js/actions.js index 05d2d37..13ff5b5 100644 --- a/IPython/html/static/notebook/js/actions.js +++ b/IPython/html/static/notebook/js/actions.js @@ -1,8 +1,7 @@ // Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. -define(['require' -], function(require) { +define(function(require){ "use strict"; var ActionHandler = function (env) { @@ -36,7 +35,7 @@ define(['require' * but is considered undefined behavior. * **/ - var _action = { + var _actions = { 'run-select-next': { icon: 'fa-play', help : 'run cell, select below', @@ -387,31 +386,36 @@ define(['require' // Will actually generate/register all the IPython actions var fun = function(){ var final_actions = {}; - for(var k in _action){ - // Js closure are function level not block level need to wrap in a IIFE - // and append ipython to event name these things do intercept event so are wrapped - // in a function that return false. - var handler = _prepare_handler(final_actions, k, _action); - (function(key, handler){ - final_actions['ipython.'+key].handler = function(env, event){ - handler(env); - if(event){ - event.preventDefault(); - } - return false; - }; - })(k, handler); + var k; + for(k in _actions){ + if(_actions.hasOwnProperty(k)){ + // Js closure are function level not block level need to wrap in a IIFE + // and append ipython to event name these things do intercept event so are wrapped + // in a function that return false. + var handler = _prepare_handler(final_actions, k, _actions); + (function(key, handler){ + final_actions['ipython.'+key].handler = function(env, event){ + handler(env); + if(event){ + event.preventDefault(); + } + return false; + }; + })(k, handler); + } } - for(var k in custom_ignore){ + for(k in custom_ignore){ // Js closure are function level not block level need to wrap in a IIFE // same as above, but decide for themselves wether or not they intercept events. - var handler = _prepare_handler(final_actions, k, custom_ignore); - (function(key, handler){ - final_actions['ipython.'+key].handler = function(env, event){ - return handler(env, event); - }; - })(k, handler); + if(custom_ignore.hasOwnProperty(k)){ + var handler = _prepare_handler(final_actions, k, custom_ignore); + (function(key, handler){ + final_actions['ipython.'+key].handler = function(env, event){ + return handler(env, event); + }; + })(k, handler); + } } return final_actions; diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 3e3bac3..58302b7 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -40,7 +40,7 @@ define([ var Cell = cell.Cell; /* local util for codemirror */ - var posEq = function(a, b) {return a.line == b.line && a.ch == b.ch;}; + var posEq = function(a, b) {return a.line === b.line && a.ch === b.ch;}; /** * @@ -332,7 +332,7 @@ define([ // whatever key is pressed, first, cancel the tooltip request before // they are sent, and remove tooltip if any, except for tab again var tooltip_closed = null; - if (event.type === 'keydown' && event.which != keycodes.tab ) { + if (event.type === 'keydown' && event.which !== keycodes.tab ) { tooltip_closed = this.tooltip.remove_and_cancel_tooltip(); } @@ -366,7 +366,7 @@ define([ if (editor.somethingSelected() || editor.getSelections().length !== 1){ var anchor = editor.getCursor("anchor"); var head = editor.getCursor("head"); - if( anchor.line != head.line){ + if( anchor.line !== head.line){ return false; } } @@ -374,7 +374,7 @@ define([ event.codemirrorIgnore = true; event.preventDefault(); return true; - } else if (event.keyCode === keycodes.tab && event.type == 'keydown') { + } else if (event.keyCode === keycodes.tab && event.type === 'keydown') { // Tab completion. this.tooltip.remove_and_cancel_tooltip(); diff --git a/IPython/html/static/notebook/js/menubar.js b/IPython/html/static/notebook/js/menubar.js index af04c8f..85eb9f7 100644 --- a/IPython/html/static/notebook/js/menubar.js +++ b/IPython/html/static/notebook/js/menubar.js @@ -371,7 +371,6 @@ define([ * Set the 'Download as foo' menu option for the relevant language. */ var el = this.element.find('#download_script'); - var that = this; // Set menu entry text to e.g. "Python (.py)" var langname = (langinfo.name || 'Script') diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 94be416..9bc5db5 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -347,7 +347,7 @@ define([ if (value === undefined) { value = true; } - if (this.dirty == value) { + if (this.dirty === value) { return; } this.events.trigger('set_dirty.Notebook', {value: value}); @@ -1792,7 +1792,7 @@ define([ cell_data = new_cells[i]; new_cell = this.insert_cell_at_index(cell_data.cell_type, i); new_cell.fromJSON(cell_data); - if (new_cell.cell_type == 'code' && !new_cell.output_area.trusted) { + if (new_cell.cell_type === 'code' && !new_cell.output_area.trusted) { trusted = false; } } @@ -1818,7 +1818,7 @@ define([ var trusted = true; for (var i=0; i', {id: uuid}) .addClass('nav') .addClass('nav-tabs') diff --git a/IPython/html/tests/notebook/markdown.js b/IPython/html/tests/notebook/markdown.js index cafe19d..d11ac23 100644 --- a/IPython/html/tests/notebook/markdown.js +++ b/IPython/html/tests/notebook/markdown.js @@ -2,6 +2,7 @@ // Test that a Markdown cell is rendered to HTML. // casper.notebook_test(function () { + "use strict"; // Test JavaScript models. var output = this.evaluate(function () { IPython.notebook.to_markdown(); @@ -56,7 +57,7 @@ casper.notebook_test(function () { for (var idx=0; idx < levels.length; idx++) { var level = levels[idx]; level_text = set_level(level); - hashes = new Array(level + 1).join('#'); + var hashes = new Array(level + 1).join('#'); this.test.assertEquals(level_text, hashes + ' ' + text, 'markdown set_heading_level ' + level); } }); diff --git a/IPython/html/tests/notebook/roundtrip.js b/IPython/html/tests/notebook/roundtrip.js index 1523cf9..262a6b7 100644 --- a/IPython/html/tests/notebook/roundtrip.js +++ b/IPython/html/tests/notebook/roundtrip.js @@ -23,7 +23,7 @@ var svg = "\"