// Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. define([ 'jquery', 'base/js/namespace', 'base/js/utils', 'base/js/i18n', 'base/js/dialog', ], function ($, IPython, utils, i18n, dialog) { "use strict"; var NewNotebookWidget = function (selector, options) { this.selector = selector; this.base_url = options.base_url; this.contents = options.contents; this.events = options.events; this.default_kernel = null; this.kernelspecs = {}; if (this.selector !== undefined) { this.element = $(selector); this.request_kernelspecs(); } this.bind_events(); }; NewNotebookWidget.prototype.bind_events = function () { var that = this; this.element.find('#new_notebook').click(function () { that.new_notebook(); }); }; NewNotebookWidget.prototype.request_kernelspecs = function () { /** request and then load kernel specs */ var url = utils.url_path_join(this.base_url, 'api/kernelspecs'); utils.promising_ajax(url).then($.proxy(this._load_kernelspecs, this)); }; NewNotebookWidget.prototype._load_kernelspecs = function (data) { /** load kernelspec list */ var that = this; this.kernelspecs = data.kernelspecs; var menu = this.element.find("#notebook-kernels"); var keys = Object.keys(data.kernelspecs).sort(function (a, b) { var da = data.kernelspecs[a].spec.display_name; var db = data.kernelspecs[b].spec.display_name; if (da === db) { return 0; } else if (da > db) { return 1; } else { return -1; } }); // Create the kernel list in reverse order because // the .after insertion causes each item to be added // to the top of the list. for (var i = keys.length - 1; i >= 0; i--) { var ks = this.kernelspecs[keys[i]]; var li = $("