// Copyright (c) IPython Development Team. // Distributed under the terms of the Modified BSD License. define([ 'base/js/namespace', 'jquery', 'base/js/utils', ], function(IPython, $, utils) { "use strict"; var KernelSelector = function(selector, notebook) { this.selector = selector; this.notebook = notebook; this.notebook.set_kernelselector(this); this.events = notebook.events; this.current_selection = null; this.kernelspecs = {}; if (this.selector !== undefined) { this.element = $(selector); this.request_kernelspecs(); } this.bind_events(); // Make the object globally available for user convenience & inspection IPython.kernelselector = this; Object.seal(this); }; KernelSelector.prototype.request_kernelspecs = function() { var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs'); utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this)); }; KernelSelector.prototype._got_kernelspecs = function(data) { this.kernelspecs = data.kernelspecs; var change_kernel_submenu = $("#menu-change-kernel-submenu"); var new_notebook_submenu = $("#menu-new-notebook-submenu"); var keys = Object.keys(data.kernelspecs).sort(function (a, b) { // sort by display_name 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 > Change kernel submenu for (var i = 0; i < keys.length; i++) { var ks = this.kernelspecs[keys[i]]; var ks_submenu_entry = $("