From b671b7c42fee18d6e0ce33662f3305d71a6382de Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Thu, 16 Apr 2015 21:13:31 -0400 Subject: [PATCH 1/2] MAINT: Replace use of != and == with !== and ===. I can't imagine we actually want the fun type-coercion behavior of the original operators... --- .../static/tree/js/notebooklist.js | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/jupyter_notebook/static/tree/js/notebooklist.js b/jupyter_notebook/static/tree/js/notebooklist.js index 76f239692..30743d30a 100644 --- a/jupyter_notebook/static/tree/js/notebooklist.js +++ b/jupyter_notebook/static/tree/js/notebooklist.js @@ -151,9 +151,9 @@ define([ NotebookList.prototype.handleFilesUpload = function(event, dropOrForm) { var that = this; var files; - if(dropOrForm =='drop'){ + if(dropOrForm === 'drop'){ files = event.originalEvent.dataTransfer.files; - } else + } else { files = event.originalEvent.target.files; } @@ -171,7 +171,7 @@ define([ } var item = that.new_item(0, true); item.addClass('new-file'); - that.add_name_input(f.name, item, file_ext == '.ipynb' ? 'notebook' : 'file'); + that.add_name_input(f.name, item, file_ext === '.ipynb' ? 'notebook' : 'file'); // Store the list item in the reader so we can use it later // to know which item it belongs to. $(reader).data('item', item); @@ -302,7 +302,7 @@ define([ var list_items = $('.list_item'); for (var i=0; i').text("Cancel") From 2a415d19f14247d4d51004014e8f42e452ee1eec Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Thu, 16 Apr 2015 21:15:35 -0400 Subject: [PATCH 2/2] MAINT: Move function creation out of loop. See https://jslinterrors.com/dont-make-functions-within-a-loop for why this is a really bad thing to do. --- .../static/tree/js/notebooklist.js | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/jupyter_notebook/static/tree/js/notebooklist.js b/jupyter_notebook/static/tree/js/notebooklist.js index 30743d30a..6a974345d 100644 --- a/jupyter_notebook/static/tree/js/notebooklist.js +++ b/jupyter_notebook/static/tree/js/notebooklist.js @@ -157,6 +157,23 @@ define([ { files = event.originalEvent.target.files; } + + var reader_onload = function (event) { + var item = $(event.target).data('item'); + that.add_file_data(event.target.result, item); + that.add_upload_button(item); + }; + var reader_onerror = function (event) { + var item = $(event.target).data('item'); + var name = item.data('name'); + item.remove(); + dialog.modal({ + title : 'Failed to read file', + body : "Failed to read file '" + name + "'", + buttons : {'OK' : { 'class' : 'btn-primary' }} + }); + }; + for (var i = 0; i < files.length; i++) { var f = files[i]; var name_and_ext = utils.splitext(f.name); @@ -175,21 +192,8 @@ define([ // Store the list item in the reader so we can use it later // to know which item it belongs to. $(reader).data('item', item); - reader.onload = function (event) { - var item = $(event.target).data('item'); - that.add_file_data(event.target.result, item); - that.add_upload_button(item); - }; - reader.onerror = function (event) { - var item = $(event.target).data('item'); - var name = item.data('name'); - item.remove(); - dialog.modal({ - title : 'Failed to read file', - body : "Failed to read file '" + name + "'", - buttons : {'OK' : { 'class' : 'btn-primary' }} - }); - }; + reader.onload = reader_onload; + reader.onerror = reader_onerror; } // Replace the file input form wth a clone of itself. This is required to // reset the form. Otherwise, if you upload a file, delete it and try to