Javascript lint in notebooklist.js

This commit is contained in:
Thomas Kluyver 2018-03-08 14:35:24 +00:00
parent c1c7d3df59
commit e2ee7c6297

View File

@ -29,19 +29,13 @@ define([
var normalized_list = list.map(function(_item) { var normalized_list = list.map(function(_item) {
return _item.toLowerCase(); return _item.toLowerCase();
}); });
return normalized_list.indexOf(item.toLowerCase()) != -1; return normalized_list.indexOf(item.toLowerCase()) !== -1;
}; };
var includes_extension = function(filepath, extensionslist) { var includes_extension = function(filepath, extensionslist) {
return item_in(extension(filepath), extensionslist); return item_in(extension(filepath), extensionslist);
}; };
var json_or_xml_container_mimetype = function(mimetype) {
// Match */*+json or */*+xml
return (mimetype.substring(mimetype.length - 5) == '+json'
|| mimetype.substring(mimetype.length - 4) == '+xml');
};
function name_sorter(ascending) { function name_sorter(ascending) {
return (function(a, b) { return (function(a, b) {
if (type_order[a['type']] < type_order[b['type']]) { if (type_order[a['type']] < type_order[b['type']]) {
@ -58,7 +52,7 @@ define([
} }
return 0; return 0;
}); });
}; }
function modified_sorter(ascending) { function modified_sorter(ascending) {
var order = ascending ? 1 : 0; var order = ascending ? 1 : 0;
@ -148,11 +142,10 @@ define([
$('#new-file').click(function(e) { $('#new-file').click(function(e) {
var w = window.open('', IPython._target); var w = window.open('', IPython._target);
that.contents.new_untitled(that.notebook_path || '', {type: 'file', ext: '.txt'}).then(function(data) { that.contents.new_untitled(that.notebook_path || '', {type: 'file', ext: '.txt'}).then(function(data) {
var url = utils.url_path_join( w.location = utils.url_path_join(
that.base_url, 'edit', that.base_url, 'edit',
utils.encode_uri_components(data.path) utils.encode_uri_components(data.path)
); );
w.location = url;
}).catch(function (e) { }).catch(function (e) {
w.close(); w.close();
dialog.modal({ dialog.modal({
@ -230,7 +223,7 @@ define([
var sort_on = e.target.id; var sort_on = e.target.id;
// Clear sort indications in UI // Clear sort indications in UI
$(".sort-action i").removeClass("fa-arrow-up").removeClass("fa-arrow-down") $(".sort-action i").removeClass("fa-arrow-up").removeClass("fa-arrow-down");
if ((that.sort_id === sort_on) && (that.sort_direction === 1)) { if ((that.sort_id === sort_on) && (that.sort_direction === 1)) {
that.sort_list(sort_on, 0); that.sort_list(sort_on, 0);
@ -457,7 +450,7 @@ define([
model = { model = {
type: 'directory', type: 'directory',
name: '..', name: '..',
path: utils.url_path_split(path)[0], path: utils.url_path_split(path)[0]
}; };
this.add_link(model, item); this.add_link(model, item);
offset += 1; offset += 1;
@ -567,13 +560,13 @@ define([
NotebookList.icons = { NotebookList.icons = {
directory: 'folder_icon', directory: 'folder_icon',
notebook: 'notebook_icon', notebook: 'notebook_icon',
file: 'file_icon', file: 'file_icon'
}; };
NotebookList.uri_prefixes = { NotebookList.uri_prefixes = {
directory: 'tree', directory: 'tree',
notebook: 'notebooks', notebook: 'notebooks',
file: 'edit', file: 'edit'
}; };
/** /**
@ -638,7 +631,6 @@ define([
var has_running_notebook = false; var has_running_notebook = false;
var has_directory = false; var has_directory = false;
var has_file = false; var has_file = false;
var that = this;
var checked = 0; var checked = 0;
$('.list_item :checked').each(function(index, item) { $('.list_item :checked').each(function(index, item) {
var parent = $(item).parent().parent(); var parent = $(item).parent().parent();
@ -889,7 +881,7 @@ define([
success : function () { success : function () {
that.load_sessions(); that.load_sessions();
}, },
error : utils.log_ajax_error, error : utils.log_ajax_error
}; };
var session = this.sessions[path]; var session = this.sessions[path];
@ -921,7 +913,7 @@ define([
case 'notebook': return i18n.msg._("Enter a new notebook name:"); case 'notebook': return i18n.msg._("Enter a new notebook name:");
default: return i18n.msg._("Enter a new name:"); default: return i18n.msg._("Enter a new name:");
} }
} };
var rename_title = function (type) { var rename_title = function (type) {
switch(type) { switch(type) {
case 'file': return i18n.msg._("Rename file"); case 'file': return i18n.msg._("Rename file");
@ -929,7 +921,7 @@ define([
case 'notebook': return i18n.msg._("Rename notebook"); case 'notebook': return i18n.msg._("Rename notebook");
default: return i18n.msg._("Rename"); default: return i18n.msg._("Rename");
} }
} };
var dialog_body = $('<div/>').append( var dialog_body = $('<div/>').append(
$("<p/>").addClass("rename-message") $("<p/>").addClass("rename-message")
.text(rename_msg(item_type)) .text(rename_msg(item_type))
@ -1275,7 +1267,6 @@ define([
var offset = 0; var offset = 0;
var chunk = 0; var chunk = 0;
var chunk_reader = null; var chunk_reader = null;
var upload_file = null;
var large_reader_onload = function (event) { var large_reader_onload = function (event) {
if (stop_signal === true) { if (stop_signal === true) {
@ -1294,7 +1285,6 @@ define([
upload_file(item, chunk); // Do the upload upload_file(item, chunk); // Do the upload
} else { } else {
console.log("Read error: " + event.target.error); console.log("Read error: " + event.target.error);
return;
} }
}; };
var on_error = function (event) { var on_error = function (event) {
@ -1351,7 +1341,7 @@ define([
model.chunk = chunk; model.chunk = chunk;
model.content = filedata; model.content = filedata;
var on_success = function (event) { var on_success = function () {
if (offset < f.size) { if (offset < f.size) {
// of to the next chunk // of to the next chunk
chunk_reader(offset, f); chunk_reader(offset, f);
@ -1403,7 +1393,7 @@ define([
item.find(".item_buttons").empty() item.find(".item_buttons").empty()
.append(upload_button) .append(upload_button)
.append(cancel_button); .append(cancel_button);
} };
NotebookList.prototype.add_upload_button = function (item) { NotebookList.prototype.add_upload_button = function (item) {
var that = this; var that = this;
@ -1465,7 +1455,6 @@ define([
model.content = filedata; model.content = filedata;
content_type = 'application/octet-stream'; content_type = 'application/octet-stream';
} }
filedata = item.data('filedata');
var on_success = function () { var on_success = function () {
item.removeClass('new-file'); item.removeClass('new-file');