Uploaded Test files
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
BIN
venv/Lib/site-packages/notebook/static/base/images/favicon.ico
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
venv/Lib/site-packages/notebook/static/base/images/logo.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
433
venv/Lib/site-packages/notebook/static/base/js/dialog.js
Normal file
|
@ -0,0 +1,433 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
define(['jquery',
|
||||
'codemirror/lib/codemirror',
|
||||
'bootstrap',
|
||||
'base/js/i18n'],
|
||||
function($, CodeMirror, bs, i18n) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* A wrapper around bootstrap modal for easier use
|
||||
* Pass it an option dictionary with the following properties:
|
||||
*
|
||||
* - body : <string> or <DOM node>, main content of the dialog
|
||||
* if pass a <string> it will be wrapped in a p tag and
|
||||
* html element escaped, unless you specify sanitize=false
|
||||
* option.
|
||||
* - title : Dialog title, default to empty string.
|
||||
* - buttons : dict of btn_options who keys are button label.
|
||||
* see btn_options below for description
|
||||
* - open : callback to trigger on dialog open.
|
||||
* - destroy:
|
||||
* - notebook : notebook instance
|
||||
* - keyboard_manager: keyboard manager instance.
|
||||
*
|
||||
* Unlike bootstrap modals, the backdrop options is set by default
|
||||
* to 'static'.
|
||||
*
|
||||
* The rest of the options are passed as is to bootstrap modals.
|
||||
*
|
||||
* btn_options: dict with the following property:
|
||||
*
|
||||
* - click : callback to trigger on click
|
||||
* - class : css classes to add to button.
|
||||
*
|
||||
*
|
||||
*
|
||||
**/
|
||||
var modal = function (options) {
|
||||
|
||||
var modal = $("<div/>")
|
||||
.addClass("modal")
|
||||
.addClass("fade")
|
||||
.attr("role", "dialog");
|
||||
var dialog = $("<div/>")
|
||||
.addClass("modal-dialog")
|
||||
.appendTo(modal);
|
||||
var dialog_content = $("<div/>")
|
||||
.addClass("modal-content")
|
||||
.appendTo(dialog);
|
||||
if(typeof(options.body) === 'string' && options.sanitize !== false){
|
||||
options.body = $("<p/>").text(options.body);
|
||||
}
|
||||
dialog_content.append(
|
||||
$("<div/>")
|
||||
.addClass("modal-header")
|
||||
.mousedown(function() {
|
||||
$(".modal").draggable({handle: '.modal-header'});
|
||||
})
|
||||
.append($("<button>")
|
||||
.attr("type", "button")
|
||||
.attr("aria-label", i18n.msg._("close"))
|
||||
.addClass("close")
|
||||
.attr("data-dismiss", "modal")
|
||||
.attr("aria-hidden", "true")
|
||||
.html("×")
|
||||
).append(
|
||||
$("<h4/>")
|
||||
.addClass('modal-title')
|
||||
.text(options.title || "")
|
||||
)
|
||||
).append(
|
||||
$("<div/>")
|
||||
.addClass("modal-body")
|
||||
.append(
|
||||
options.body || $("<p/>")
|
||||
)
|
||||
);
|
||||
|
||||
var footer = $("<div/>").addClass("modal-footer");
|
||||
|
||||
var default_button;
|
||||
|
||||
for (var label in options.buttons) {
|
||||
var btn_opts = options.buttons[label];
|
||||
var button = $("<button/>")
|
||||
.addClass("btn btn-default btn-sm")
|
||||
.attr("data-dismiss", "modal")
|
||||
.text(i18n.msg.translate(label).fetch());
|
||||
if (btn_opts.id) {
|
||||
button.attr('id', btn_opts.id);
|
||||
}
|
||||
if (btn_opts.click) {
|
||||
button.click($.proxy(btn_opts.click, dialog_content));
|
||||
}
|
||||
if (btn_opts.class) {
|
||||
button.addClass(btn_opts.class);
|
||||
}
|
||||
footer.append(button);
|
||||
if (options.default_button && label === options.default_button) {
|
||||
default_button = button;
|
||||
}
|
||||
}
|
||||
if (!options.default_button) {
|
||||
default_button = footer.find("button").last();
|
||||
}
|
||||
dialog_content.append(footer);
|
||||
// hook up on-open event
|
||||
modal.on("shown.bs.modal", function () {
|
||||
setTimeout(function () {
|
||||
default_button.focus();
|
||||
if (options.open) {
|
||||
$.proxy(options.open, modal)();
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
|
||||
// destroy modal on hide, unless explicitly asked not to
|
||||
if (options.destroy === undefined || options.destroy) {
|
||||
modal.on("hidden.bs.modal", function () {
|
||||
modal.remove();
|
||||
});
|
||||
}
|
||||
modal.on("hidden.bs.modal", function () {
|
||||
if (options.notebook) {
|
||||
var cell = options.notebook.get_selected_cell();
|
||||
if (cell) cell.select();
|
||||
}
|
||||
if (options.keyboard_manager) {
|
||||
options.keyboard_manager.enable();
|
||||
options.keyboard_manager.command_mode();
|
||||
}
|
||||
if (options.focus_button) {
|
||||
$(options.focus_button).focus();
|
||||
}
|
||||
});
|
||||
|
||||
if (options.keyboard_manager) {
|
||||
options.keyboard_manager.disable();
|
||||
}
|
||||
|
||||
if(options.backdrop === undefined){
|
||||
options.backdrop = 'static';
|
||||
}
|
||||
|
||||
return modal.modal(options);
|
||||
};
|
||||
|
||||
var kernel_modal = function (options) {
|
||||
/**
|
||||
* only one kernel dialog should be open at a time -- but
|
||||
* other modal dialogs can still be open
|
||||
*/
|
||||
$('.kernel-modal').modal('hide');
|
||||
var dialog = modal(options);
|
||||
dialog.addClass('kernel-modal');
|
||||
return dialog;
|
||||
};
|
||||
|
||||
var edit_metadata = function (options) {
|
||||
options.name = options.name || "Cell";
|
||||
var error_div = $('<div/>').css('color', 'red');
|
||||
var message_cell =
|
||||
i18n.msg._("Manually edit the JSON below to manipulate the metadata for this cell.");
|
||||
var message_notebook =
|
||||
i18n.msg._("Manually edit the JSON below to manipulate the metadata for this notebook.");
|
||||
var message_end =
|
||||
i18n.msg._(" We recommend putting custom metadata attributes in an appropriately named substructure," +
|
||||
" so they don't conflict with those of others.");
|
||||
|
||||
var message;
|
||||
if (options.name === 'Notebook') {
|
||||
message = message_notebook + message_end;
|
||||
} else {
|
||||
message = message_cell + message_end;
|
||||
}
|
||||
var textarea = $('<textarea/>')
|
||||
.attr('rows', '13')
|
||||
.attr('cols', '80')
|
||||
.attr('name', 'metadata')
|
||||
.text(JSON.stringify(options.md || {}, null, 2));
|
||||
|
||||
var dialogform = $('<div/>').attr('title', i18n.msg._('Edit the metadata'))
|
||||
.append(
|
||||
$('<form/>').append(
|
||||
$('<fieldset/>').append(
|
||||
$('<label/>')
|
||||
.attr('for','metadata')
|
||||
.text(message)
|
||||
)
|
||||
.append(error_div)
|
||||
.append($('<br/>'))
|
||||
.append(textarea)
|
||||
)
|
||||
);
|
||||
var editor = CodeMirror.fromTextArea(textarea[0], {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
indentUnit: 2,
|
||||
autoIndent: true,
|
||||
mode: 'application/json',
|
||||
});
|
||||
var title_msg;
|
||||
if (options.name === "Notebook") {
|
||||
title_msg = i18n.msg._("Edit Notebook Metadata");
|
||||
} else {
|
||||
title_msg = i18n.msg._("Edit Cell Metadata");
|
||||
}
|
||||
// This statement is used simply so that message extraction
|
||||
// will pick up the strings.
|
||||
var button_labels = [ i18n.msg._("Cancel"), i18n.msg._("Edit"), i18n.msg._("OK"), i18n.msg._("Apply")];
|
||||
var modal_obj = modal({
|
||||
title: title_msg,
|
||||
body: dialogform,
|
||||
default_button: "Cancel",
|
||||
buttons: {
|
||||
Cancel: {},
|
||||
Edit: { class : "btn-primary",
|
||||
click: function() {
|
||||
/**
|
||||
* validate json and set it
|
||||
*/
|
||||
var new_md;
|
||||
try {
|
||||
new_md = JSON.parse(editor.getValue());
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
error_div.text(i18n.msg._('WARNING: Could not save invalid JSON.'));
|
||||
return false;
|
||||
}
|
||||
options.callback(new_md);
|
||||
options.notebook.apply_directionality();
|
||||
}
|
||||
}
|
||||
},
|
||||
notebook: options.notebook,
|
||||
keyboard_manager: options.keyboard_manager,
|
||||
});
|
||||
|
||||
modal_obj.on('shown.bs.modal', function(){ editor.refresh(); });
|
||||
modal_obj.on('hide.bs.modal', function(){
|
||||
options.edit_metadata_button ? options.edit_metadata_button.focus() : "";});
|
||||
};
|
||||
|
||||
var edit_attachments = function (options) {
|
||||
// This shows the Edit Attachments dialog. This dialog allows the
|
||||
// user to delete attachments. We show a list of attachments to
|
||||
// the user and he can mark some of them for deletion. The deletion
|
||||
// is applied when the 'Apply' button of this dialog is pressed.
|
||||
var message;
|
||||
var attachments_list;
|
||||
if (Object.keys(options.attachments).length == 0) {
|
||||
message = i18n.msg._("There are no attachments for this cell.");
|
||||
attachments_list = $('<div>');
|
||||
} else {
|
||||
message = i18n.msg._("Current cell attachments");
|
||||
|
||||
attachments_list = $('<div>')
|
||||
.addClass('list_container')
|
||||
.append(
|
||||
$('<div>')
|
||||
.addClass('row list_header')
|
||||
.append(
|
||||
$('<div>')
|
||||
.text(i18n.msg._('Attachments'))
|
||||
)
|
||||
);
|
||||
|
||||
// This is a set containing keys of attachments to be deleted when
|
||||
// the Apply button is clicked
|
||||
var to_delete = {};
|
||||
|
||||
var refresh_attachments_list = function() {
|
||||
$(attachments_list).find('.row').remove();
|
||||
for (var key in options.attachments) {
|
||||
var mime = Object.keys(options.attachments[key])[0];
|
||||
var deleted = key in to_delete;
|
||||
|
||||
// This ensures the current value of key is captured since
|
||||
// javascript only has function scope
|
||||
var btn;
|
||||
// Trash/restore button
|
||||
(function(){
|
||||
var _key = key;
|
||||
btn = $('<button>')
|
||||
.addClass('btn btn-default btn-xs')
|
||||
.css('display', 'inline-block');
|
||||
if (deleted) {
|
||||
btn.attr('title', i18n.msg._('Restore'))
|
||||
.append(
|
||||
$('<i>')
|
||||
.addClass('fa fa-plus')
|
||||
);
|
||||
btn.click(function() {
|
||||
delete to_delete[_key];
|
||||
refresh_attachments_list();
|
||||
});
|
||||
} else {
|
||||
btn.attr('title', i18n.msg._('Delete'))
|
||||
.addClass('btn-danger')
|
||||
.append(
|
||||
$('<i>')
|
||||
.addClass('fa fa-trash')
|
||||
);
|
||||
btn.click(function() {
|
||||
to_delete[_key] = true;
|
||||
refresh_attachments_list();
|
||||
});
|
||||
}
|
||||
return btn;
|
||||
})();
|
||||
var row = $('<div>')
|
||||
.addClass('col-md-12 att_row')
|
||||
.append(
|
||||
$('<div>')
|
||||
.addClass('row')
|
||||
.append(
|
||||
$('<div>')
|
||||
.addClass('att-name col-xs-4')
|
||||
.text(key)
|
||||
)
|
||||
.append(
|
||||
$('<div>')
|
||||
.addClass('col-xs-4 text-muted')
|
||||
.text(mime)
|
||||
)
|
||||
.append(
|
||||
$('<div>')
|
||||
.addClass('item-buttons pull-right')
|
||||
.append(btn)
|
||||
)
|
||||
);
|
||||
if (deleted) {
|
||||
row.find('.att-name')
|
||||
.css('text-decoration', 'line-through');
|
||||
}
|
||||
|
||||
attachments_list.append($('<div>')
|
||||
.addClass('list_item row')
|
||||
.append(row)
|
||||
);
|
||||
}
|
||||
};
|
||||
refresh_attachments_list();
|
||||
}
|
||||
|
||||
var dialogform = $('<div/>')
|
||||
.attr('title', i18n.msg._('Edit attachments'))
|
||||
.append(message)
|
||||
.append('<br />')
|
||||
.append(attachments_list);
|
||||
var title_msg;
|
||||
if ( options.name === "Notebook" ) {
|
||||
title_msg = i18n.msg._("Edit Notebook Attachments");
|
||||
} else {
|
||||
title_msg = i18n.msg._("Edit Cell Attachments");
|
||||
}
|
||||
var modal_obj = modal({
|
||||
title: title_msg,
|
||||
body: dialogform,
|
||||
buttons: {
|
||||
Apply: { class : "btn-primary",
|
||||
click: function() {
|
||||
for (var key in to_delete) {
|
||||
delete options.attachments[key];
|
||||
}
|
||||
options.callback(options.attachments);
|
||||
}
|
||||
},
|
||||
Cancel: {}
|
||||
},
|
||||
notebook: options.notebook,
|
||||
keyboard_manager: options.keyboard_manager,
|
||||
});
|
||||
};
|
||||
|
||||
var insert_image = function (options) {
|
||||
var message =
|
||||
i18n.msg._("Select a file to insert.");
|
||||
var file_input = $('<input/>')
|
||||
.attr('type', 'file')
|
||||
.attr('accept', 'image/*')
|
||||
.attr('name', 'file')
|
||||
.on('change', function(file) {
|
||||
var $btn = $(modal_obj).find('#btn_ok');
|
||||
if (this.files.length > 0) {
|
||||
$btn.removeClass('disabled');
|
||||
} else {
|
||||
$btn.addClass('disabled');
|
||||
}
|
||||
});
|
||||
var dialogform = $('<div/>').attr('title', i18n.msg._('Edit attachments'))
|
||||
.append(
|
||||
$('<form id="insert-image-form" />').append(
|
||||
$('<fieldset/>').append(
|
||||
$('<label/>')
|
||||
.attr('for','file')
|
||||
.text(message)
|
||||
)
|
||||
.append($('<br/>'))
|
||||
.append(file_input)
|
||||
)
|
||||
);
|
||||
var modal_obj = modal({
|
||||
title: i18n.msg._("Select a file"),
|
||||
body: dialogform,
|
||||
buttons: {
|
||||
OK: {
|
||||
id : 'btn_ok',
|
||||
class : "btn-primary disabled",
|
||||
click: function() {
|
||||
options.callback(file_input[0].files[0]);
|
||||
}
|
||||
},
|
||||
Cancel: {}
|
||||
},
|
||||
notebook: options.notebook,
|
||||
keyboard_manager: options.keyboard_manager,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var dialog = {
|
||||
modal : modal,
|
||||
kernel_modal : kernel_modal,
|
||||
edit_metadata : edit_metadata,
|
||||
edit_attachments : edit_attachments,
|
||||
insert_image : insert_image
|
||||
};
|
||||
|
||||
return dialog;
|
||||
});
|
37
venv/Lib/site-packages/notebook/static/base/js/events.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
// Give us an object to bind all events to. This object should be created
|
||||
// before all other objects so it exists when others register event handlers.
|
||||
// To register an event handler:
|
||||
//
|
||||
// requirejs(['base/js/events'], function (events) {
|
||||
// events.on("event.Namespace", function () { do_stuff(); });
|
||||
// });
|
||||
|
||||
define(['jquery', 'base/js/namespace'], function($, Jupyter) {
|
||||
"use strict";
|
||||
|
||||
// Events singleton
|
||||
if (!window._Events) {
|
||||
window._Events = function () {};
|
||||
window._events = new window._Events();
|
||||
}
|
||||
|
||||
// Backwards compatibility.
|
||||
Jupyter.Events = window._Events;
|
||||
Jupyter.events = window._events;
|
||||
|
||||
var events = $([window._events]);
|
||||
|
||||
// catch and log errors in triggered events
|
||||
events._original_trigger = events.trigger;
|
||||
events.trigger = function (name, data) {
|
||||
try {
|
||||
this._original_trigger.apply(this, arguments);
|
||||
} catch (e) {
|
||||
console.error("Exception in event handler for " + name, e, arguments);
|
||||
}
|
||||
}
|
||||
return events;
|
||||
});
|
16
venv/Lib/site-packages/notebook/static/base/js/i18n.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
// Module to handle i18n ( Internationalization ) and translated UI
|
||||
|
||||
define([
|
||||
'jed'
|
||||
], function(Jed) {
|
||||
"use strict";
|
||||
|
||||
var i18n = new Jed(document.nbjs_translations);
|
||||
i18n._ = i18n.gettext;
|
||||
i18n.msg = i18n; // Just a place holder until the init promise resolves.
|
||||
|
||||
return i18n;
|
||||
});
|
576
venv/Lib/site-packages/notebook/static/base/js/keyboard.js
Normal file
|
@ -0,0 +1,576 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @module keyboard
|
||||
* @namespace keyboard
|
||||
* @class ShortcutManager
|
||||
*/
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'base/js/utils',
|
||||
'underscore',
|
||||
], function($, utils, _) {
|
||||
"use strict";
|
||||
|
||||
|
||||
/**
|
||||
* Setup global keycodes and inverse keycodes.
|
||||
*
|
||||
* See http://unixpapa.com/js/key.html for a complete description. The short of
|
||||
* it is that there are different keycode sets. Firefox uses the "Mozilla keycodes"
|
||||
* and Webkit/IE use the "IE keycodes". These keycode sets are mostly the same
|
||||
* but have minor differences.
|
||||
**/
|
||||
|
||||
// These apply to Firefox, (Webkit and IE)
|
||||
// This does work **only** on US keyboard.
|
||||
var _keycodes = {
|
||||
'a': 65, 'b': 66, 'c': 67, 'd': 68, 'e': 69, 'f': 70, 'g': 71, 'h': 72, 'i': 73,
|
||||
'j': 74, 'k': 75, 'l': 76, 'm': 77, 'n': 78, 'o': 79, 'p': 80, 'q': 81, 'r': 82,
|
||||
's': 83, 't': 84, 'u': 85, 'v': 86, 'w': 87, 'x': 88, 'y': 89, 'z': 90,
|
||||
'1 !': 49, '2 @': 50, '3 #': 51, '4 $': 52, '5 %': 53, '6 ^': 54,
|
||||
'7 &': 55, '8 *': 56, '9 (': 57, '0 )': 48,
|
||||
'[ {': 219, '] }': 221, '` ~': 192, ', <': 188, '. >': 190, '/ ?': 191,
|
||||
'\\ |': 220, '\' "': 222,
|
||||
'numpad0': 96, 'numpad1': 97, 'numpad2': 98, 'numpad3': 99, 'numpad4': 100,
|
||||
'numpad5': 101, 'numpad6': 102, 'numpad7': 103, 'numpad8': 104, 'numpad9': 105,
|
||||
'multiply': 106, 'add': 107, 'subtract': 109, 'decimal': 110, 'divide': 111,
|
||||
'f1': 112, 'f2': 113, 'f3': 114, 'f4': 115, 'f5': 116, 'f6': 117, 'f7': 118,
|
||||
'f8': 119, 'f9': 120, 'f10': 121, 'f11': 122, 'f12': 123, 'f13': 124, 'f14': 125, 'f15': 126,
|
||||
'backspace': 8, 'tab': 9, 'enter': 13, 'shift': 16, 'ctrl': 17, 'alt': 18,
|
||||
'meta': 91, 'capslock': 20, 'esc': 27, 'space': 32, 'pageup': 33, 'pagedown': 34,
|
||||
'end': 35, 'home': 36, 'left': 37, 'up': 38, 'right': 39, 'down': 40,
|
||||
'insert': 45, 'delete': 46, 'numlock': 144,
|
||||
};
|
||||
|
||||
// These apply to Firefox and Opera
|
||||
var _mozilla_keycodes = {
|
||||
'; :': 59, '= +': 61, '- _': 173, 'meta': 224, 'minus':173
|
||||
};
|
||||
|
||||
// This apply to Webkit and IE
|
||||
var _ie_keycodes = {
|
||||
'; :': 186, '= +': 187, '- _': 189, 'minus':189
|
||||
};
|
||||
|
||||
var browser = utils.browser[0];
|
||||
var platform = utils.platform;
|
||||
|
||||
if (browser === 'Firefox' || browser === 'Opera' || browser === 'Netscape') {
|
||||
$.extend(_keycodes, _mozilla_keycodes);
|
||||
} else if (browser === 'Safari' || browser === 'Chrome' || browser === 'MSIE') {
|
||||
$.extend(_keycodes, _ie_keycodes);
|
||||
}
|
||||
|
||||
var keycodes = {};
|
||||
var inv_keycodes = {};
|
||||
for (var name in _keycodes) {
|
||||
var names = name.split(' ');
|
||||
if (names.length === 1) {
|
||||
var n = names[0];
|
||||
keycodes[n] = _keycodes[n];
|
||||
inv_keycodes[_keycodes[n]] = n;
|
||||
} else {
|
||||
var primary = names[0];
|
||||
var secondary = names[1];
|
||||
keycodes[primary] = _keycodes[name];
|
||||
keycodes[secondary] = _keycodes[name];
|
||||
inv_keycodes[_keycodes[name]] = primary;
|
||||
}
|
||||
}
|
||||
|
||||
var normalize_key = function (key) {
|
||||
return inv_keycodes[keycodes[key]];
|
||||
};
|
||||
|
||||
var normalize_shortcut = function (shortcut) {
|
||||
/**
|
||||
* @function _normalize_shortcut
|
||||
* @private
|
||||
* return a dict containing the normalized shortcut and the number of time it should be pressed:
|
||||
*
|
||||
* Put a shortcut into normalized form:
|
||||
* 1. Make lowercase
|
||||
* 2. Replace cmd by meta
|
||||
* 3. Sort '-' separated modifiers into the order alt-ctrl-meta-shift
|
||||
* 4. Normalize keys
|
||||
**/
|
||||
if (platform === 'MacOS') {
|
||||
shortcut = shortcut.toLowerCase().replace('cmdtrl-', 'cmd-');
|
||||
} else {
|
||||
shortcut = shortcut.toLowerCase().replace('cmdtrl-', 'ctrl-');
|
||||
}
|
||||
|
||||
shortcut = shortcut.toLowerCase().replace('cmd', 'meta');
|
||||
shortcut = shortcut.replace(/-$/, 'minus'); // catch shortcuts using '-' key
|
||||
shortcut = shortcut.replace(/,$/, 'comma'); // catch shortcuts using '-' key
|
||||
if(shortcut.indexOf(',') !== -1){
|
||||
var sht = shortcut.split(',');
|
||||
sht = _.map(sht, normalize_shortcut);
|
||||
return shortcut;
|
||||
}
|
||||
shortcut = shortcut.replace(/comma/g, ','); // catch shortcuts using '-' key
|
||||
var values = shortcut.split("-");
|
||||
if (values.length === 1) {
|
||||
return normalize_key(values[0]);
|
||||
} else {
|
||||
var modifiers = values.slice(0,-1);
|
||||
var key = normalize_key(values[values.length-1]);
|
||||
modifiers.sort();
|
||||
return modifiers.join('-') + '-' + key;
|
||||
}
|
||||
};
|
||||
|
||||
var shortcut_to_event = function (shortcut, type) {
|
||||
/**
|
||||
* Convert a shortcut (shift-r) to a jQuery Event object
|
||||
**/
|
||||
type = type || 'keydown';
|
||||
shortcut = normalize_shortcut(shortcut);
|
||||
shortcut = shortcut.replace(/-$/, 'minus'); // catch shortcuts using '-' key
|
||||
var values = shortcut.split("-");
|
||||
var modifiers = values.slice(0,-1);
|
||||
var key = values[values.length-1];
|
||||
var opts = {which: keycodes[key]};
|
||||
if (modifiers.indexOf('alt') !== -1) {opts.altKey = true;}
|
||||
if (modifiers.indexOf('ctrl') !== -1) {opts.ctrlKey = true;}
|
||||
if (modifiers.indexOf('meta') !== -1) {opts.metaKey = true;}
|
||||
if (modifiers.indexOf('shift') !== -1) {opts.shiftKey = true;}
|
||||
return $.Event(type, opts);
|
||||
};
|
||||
|
||||
var only_modifier_event = function(event){
|
||||
/**
|
||||
* Return `true` if the event only contains modifiers keys.
|
||||
* false otherwise
|
||||
**/
|
||||
var key = inv_keycodes[event.which];
|
||||
return ((event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) &&
|
||||
(key === 'alt'|| key === 'ctrl'|| key === 'meta'|| key === 'shift'));
|
||||
|
||||
};
|
||||
|
||||
var event_to_shortcut = function (event) {
|
||||
/**
|
||||
* Convert a jQuery Event object to a normalized shortcut string (shift-r)
|
||||
**/
|
||||
var shortcut = '';
|
||||
var key = inv_keycodes[event.which];
|
||||
if (event.altKey && key !== 'alt') {shortcut += 'alt-';}
|
||||
if (event.ctrlKey && key !== 'ctrl') {shortcut += 'ctrl-';}
|
||||
if (event.metaKey && key !== 'meta') {shortcut += 'meta-';}
|
||||
if (event.shiftKey && key !== 'shift') {shortcut += 'shift-';}
|
||||
shortcut += key;
|
||||
return shortcut;
|
||||
};
|
||||
|
||||
// Shortcut manager class
|
||||
|
||||
var ShortcutManager = function (delay, events, actions, env, config, mode) {
|
||||
/**
|
||||
* A class to deal with keyboard event and shortcut
|
||||
*
|
||||
* @class ShortcutManager
|
||||
* @constructor
|
||||
*
|
||||
* :config: configobjet on which to call `update(....)` to persist the config.
|
||||
* :mode: mode of this shortcut manager where to persist config.
|
||||
*/
|
||||
mode = mode || 'command';
|
||||
this._shortcuts = {};
|
||||
this._defaults_bindings = [];
|
||||
this.delay = delay || 800; // delay in milliseconds
|
||||
this.events = events;
|
||||
this.actions = actions;
|
||||
this.actions.extend_env(env);
|
||||
this._queue = [];
|
||||
this._cleartimeout = null;
|
||||
this._config = config;
|
||||
this._mode = mode;
|
||||
Object.seal(this);
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.clearsoon = function(){
|
||||
/**
|
||||
* Clear the pending shortcut soon, and cancel previous clearing
|
||||
* that might be registered.
|
||||
**/
|
||||
var that = this;
|
||||
clearTimeout(this._cleartimeout);
|
||||
this._cleartimeout = setTimeout(function(){that.clearqueue();}, this.delay);
|
||||
};
|
||||
|
||||
|
||||
ShortcutManager.prototype.clearqueue = function(){
|
||||
/**
|
||||
* clear the pending shortcut sequence now.
|
||||
**/
|
||||
this._queue = [];
|
||||
clearTimeout(this._cleartimeout);
|
||||
};
|
||||
|
||||
|
||||
var flatten_shorttree = function(tree){
|
||||
/**
|
||||
* Flatten a tree of shortcut sequences.
|
||||
* use full to iterate over all the key/values of available shortcuts.
|
||||
**/
|
||||
var dct = {};
|
||||
_.forEach(tree, function(value, key) {
|
||||
if(typeof(value) === 'string'){
|
||||
dct[key] = value;
|
||||
} else {
|
||||
var ftree=flatten_shorttree(value);
|
||||
_.forEach(ftree, function(v2, subkey) {
|
||||
dct[key+','+subkey] = ftree[subkey];
|
||||
});
|
||||
}
|
||||
});
|
||||
return dct;
|
||||
};
|
||||
|
||||
|
||||
ShortcutManager.prototype.get_action_shortcuts = function(name){
|
||||
var ftree = flatten_shorttree(this._shortcuts);
|
||||
var res = [];
|
||||
_.forEach(ftree, function(value, key) {
|
||||
if(value === name){
|
||||
res.push(key);
|
||||
}
|
||||
});
|
||||
return res;
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.get_action_shortcut = function(name){
|
||||
var matches = this.get_action_shortcuts(name);
|
||||
if (matches.length > 0) {
|
||||
return matches[0];
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.help = function () {
|
||||
var that = this;
|
||||
var help = [];
|
||||
var ftree = flatten_shorttree(this._shortcuts);
|
||||
_.forEach(ftree, function(value, key) {
|
||||
var action = that.actions.get(value);
|
||||
var help_string = action.help||'== no help ==';
|
||||
var help_index = action.help_index;
|
||||
if (help_string) {
|
||||
var shortstring = (action.shortstring||key);
|
||||
help.push({
|
||||
shortcut: shortstring,
|
||||
help: help_string,
|
||||
help_index: help_index}
|
||||
);
|
||||
}
|
||||
});
|
||||
help.sort(function (a, b) {
|
||||
if (a.help_index === b.help_index) {
|
||||
if (a.shortcut === b.shortcut) {
|
||||
return 0;
|
||||
}
|
||||
if (a.shortcut > b.shortcut) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (a.help_index === undefined || a.help_index > b.help_index){
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
return help;
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.clear_shortcuts = function () {
|
||||
this._shortcuts = {};
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.get_shortcut = function (shortcut){
|
||||
/**
|
||||
* return a node of the shortcut tree which an action name (string) if leaf,
|
||||
* and an object with `object.subtree===true`
|
||||
**/
|
||||
if(typeof(shortcut) === 'string'){
|
||||
shortcut = shortcut.split(',');
|
||||
}
|
||||
|
||||
return this._get_leaf(shortcut, this._shortcuts);
|
||||
};
|
||||
|
||||
|
||||
ShortcutManager.prototype._get_leaf = function(shortcut_array, tree){
|
||||
/**
|
||||
* @private
|
||||
* find a leaf/node in a subtree of the keyboard shortcut
|
||||
*
|
||||
**/
|
||||
if(shortcut_array.length === 1){
|
||||
return tree[shortcut_array[0]];
|
||||
} else if( typeof(tree[shortcut_array[0]]) !== 'string'){
|
||||
return this._get_leaf(shortcut_array.slice(1), tree[shortcut_array[0]]);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.set_shortcut = function( shortcut, action_name){
|
||||
if( typeof(action_name) !== 'string'){throw new Error('action is not a string', action_name);}
|
||||
if( typeof(shortcut) === 'string'){
|
||||
shortcut = shortcut.split(',');
|
||||
}
|
||||
return this._set_leaf(shortcut, action_name, this._shortcuts);
|
||||
};
|
||||
|
||||
ShortcutManager.prototype._is_leaf = function(shortcut_array, tree){
|
||||
if(shortcut_array.length === 1){
|
||||
return(typeof(tree[shortcut_array[0]]) === 'string');
|
||||
} else {
|
||||
var subtree = tree[shortcut_array[0]];
|
||||
return this._is_leaf(shortcut_array.slice(1), subtree );
|
||||
}
|
||||
};
|
||||
|
||||
ShortcutManager.prototype._remove_leaf = function(shortcut_array, tree, allow_node){
|
||||
if(shortcut_array.length === 1){
|
||||
var current_node = tree[shortcut_array[0]];
|
||||
if(typeof(current_node) === 'string'){
|
||||
delete tree[shortcut_array[0]];
|
||||
} else {
|
||||
throw new Error('try to delete non-leaf');
|
||||
}
|
||||
} else {
|
||||
this._remove_leaf(shortcut_array.slice(1), tree[shortcut_array[0]], allow_node);
|
||||
if(_.keys(tree[shortcut_array[0]]).length === 0){
|
||||
delete tree[shortcut_array[0]];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.is_available_shortcut = function(shortcut){
|
||||
var shortcut_array = shortcut.split(',');
|
||||
return this._is_available_shortcut(shortcut_array, this._shortcuts);
|
||||
};
|
||||
|
||||
ShortcutManager.prototype._is_available_shortcut = function(shortcut_array, tree){
|
||||
var current_node = tree[shortcut_array[0]];
|
||||
if(!shortcut_array[0]){
|
||||
return false;
|
||||
}
|
||||
if(current_node === undefined){
|
||||
return true;
|
||||
} else {
|
||||
if (typeof(current_node) === 'string'){
|
||||
return false;
|
||||
} else { // assume is a sub-shortcut tree
|
||||
return this._is_available_shortcut(shortcut_array.slice(1), current_node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ShortcutManager.prototype._set_leaf = function(shortcut_array, action_name, tree){
|
||||
var current_node = tree[shortcut_array[0]];
|
||||
|
||||
if(shortcut_array.length === 1){
|
||||
if(current_node !== undefined && typeof(current_node) !== 'string'){
|
||||
console.warn('[warning], you are overriting a long shortcut with a shorter one');
|
||||
}
|
||||
tree[shortcut_array[0]] = action_name;
|
||||
return true;
|
||||
} else {
|
||||
if(typeof(current_node) === 'string'){
|
||||
console.warn('you are trying to set a shortcut that will be shadowed'+
|
||||
'by a more specific one. Aborting for :', action_name, 'the following '+
|
||||
'will take precedence', current_node);
|
||||
return false;
|
||||
} else {
|
||||
tree[shortcut_array[0]] = tree[shortcut_array[0]]||{};
|
||||
}
|
||||
this._set_leaf(shortcut_array.slice(1), action_name, tree[shortcut_array[0]]);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
ShortcutManager.prototype._persist_shortcut = function(shortcut, data) {
|
||||
/**
|
||||
* add a shortcut to this manager and persist it to the config file.
|
||||
**/
|
||||
shortcut = shortcut.toLowerCase();
|
||||
this.add_shortcut(shortcut, data);
|
||||
var patch = {keys:{}};
|
||||
patch.keys[this._mode] = {bind:{}};
|
||||
patch.keys[this._mode].bind[shortcut] = data;
|
||||
this._config.update(patch);
|
||||
};
|
||||
|
||||
ShortcutManager.prototype._persist_remove_shortcut = function(shortcut){
|
||||
/**
|
||||
* Remove a shortcut from this manager and persist its removal.
|
||||
*/
|
||||
|
||||
shortcut = shortcut.toLowerCase();
|
||||
this.remove_shortcut(shortcut);
|
||||
var patch = {keys: {}};
|
||||
patch.keys[this._mode] = {bind:{}};
|
||||
patch.keys[this._mode].bind[shortcut] = null;
|
||||
this._config.update(patch);
|
||||
|
||||
// if the shortcut we unbind is a default one, we add it to the list of
|
||||
// things to unbind at startup
|
||||
if( this._defaults_bindings.indexOf(shortcut) !== -1 ){
|
||||
var cnf = (this._config.data.keys || {})[this._mode];
|
||||
var unbind_array = cnf.unbind || [];
|
||||
|
||||
|
||||
// unless it's already there (like if we have remapped a default
|
||||
// shortcut to another command): unbind it)
|
||||
if(unbind_array.indexOf(shortcut) === -1){
|
||||
var _parray = unbind_array.concat(shortcut);
|
||||
var unbind_patch = {keys:{}};
|
||||
unbind_patch.keys[this._mode] = {unbind:_parray};
|
||||
console.warn('up:', unbind_patch);
|
||||
this._config.update(unbind_patch);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ShortcutManager.prototype.add_shortcut = function (shortcut, data, suppress_help_update) {
|
||||
/**
|
||||
* Add an action to be handled by shortcut manager.
|
||||
*
|
||||
* - `shortcut` should be a `Shortcut Sequence` of the for `Ctrl-Alt-C,Meta-X`...
|
||||
* - `data` could be an `action name`, an `action` or a `function`.
|
||||
* if a `function` is passed it will be converted to an anonymous `action`.
|
||||
*
|
||||
**/
|
||||
var action_name = this.actions.get_name(data);
|
||||
if (! action_name){
|
||||
if (typeof data === 'string') {
|
||||
// If we have an action name, allow it to be bound anyway.
|
||||
console.log("Unknown action '" + data + "' for shortcut " + shortcut
|
||||
+ "; it may be defined by an extension which is not yet loaded.");
|
||||
action_name = data;
|
||||
} else {
|
||||
throw new Error('does not know how to deal with : ' + data);
|
||||
}
|
||||
}
|
||||
var _shortcut = normalize_shortcut(shortcut);
|
||||
this.set_shortcut(_shortcut, action_name);
|
||||
|
||||
if (!suppress_help_update) {
|
||||
// update the keyboard shortcuts notebook help
|
||||
this.events.trigger('rebuild.QuickHelp');
|
||||
}
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.add_shortcuts = function (data) {
|
||||
/**
|
||||
* Convenient methods to call `add_shortcut(key, value)` on several items
|
||||
*
|
||||
* data : Dict of the form {key:value, ...}
|
||||
**/
|
||||
var that = this;
|
||||
_.forEach(data, function(value, key) {
|
||||
that.add_shortcut(key, value, true);
|
||||
});
|
||||
// update the keyboard shortcuts notebook help
|
||||
this.events.trigger('rebuild.QuickHelp');
|
||||
};
|
||||
|
||||
ShortcutManager.prototype._add_default_shortcuts = function (data) {
|
||||
/**
|
||||
* same as add_shortcuts, but register them as "default" that if persistently unbound, with
|
||||
* persist_remove_shortcut, need to be on the "unbind" list.
|
||||
**/
|
||||
this._defaults_bindings = this._defaults_bindings.concat(Object.keys(data));
|
||||
this.add_shortcuts(data);
|
||||
|
||||
};
|
||||
|
||||
ShortcutManager.prototype.remove_shortcut = function (shortcut, suppress_help_update) {
|
||||
/**
|
||||
* Remove the binding of shortcut `shortcut` with its action.
|
||||
* throw an error if trying to remove a non-exiting shortcut
|
||||
**/
|
||||
if(!shortcut){
|
||||
console.warn('trying to remove empty shortcut');
|
||||
return;
|
||||
}
|
||||
shortcut = normalize_shortcut(shortcut);
|
||||
if( typeof(shortcut) === 'string'){
|
||||
shortcut = shortcut.split(',');
|
||||
}
|
||||
/*
|
||||
* The shortcut error should be explicit here, because it will be
|
||||
* seen by users.
|
||||
*/
|
||||
try {
|
||||
this._remove_leaf(shortcut, this._shortcuts);
|
||||
if (!suppress_help_update) {
|
||||
// update the keyboard shortcuts notebook help
|
||||
this.events.trigger('rebuild.QuickHelp');
|
||||
}
|
||||
} catch (ex) {
|
||||
throw new Error('trying to remove a non-existent shortcut', shortcut, typeof shortcut);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
ShortcutManager.prototype.call_handler = function (event) {
|
||||
/**
|
||||
* Call the corresponding shortcut handler for a keyboard event
|
||||
* @method call_handler
|
||||
* @return {Boolean} `true|false`, `false` if no handler was found, otherwise the value return by the handler.
|
||||
* @param event {event}
|
||||
*
|
||||
* given an event, call the corresponding shortcut.
|
||||
* return false is event wan handled, true otherwise
|
||||
* in any case returning false stop event propagation
|
||||
**/
|
||||
|
||||
|
||||
this.clearsoon();
|
||||
if(only_modifier_event(event)){
|
||||
return true;
|
||||
}
|
||||
var shortcut = event_to_shortcut(event);
|
||||
this._queue.push(shortcut);
|
||||
var action_name = this.get_shortcut(this._queue);
|
||||
|
||||
if (typeof(action_name) === 'undefined'|| action_name === null){
|
||||
this.clearqueue();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.actions.exists(action_name)) {
|
||||
event.preventDefault();
|
||||
this.clearqueue();
|
||||
return this.actions.call(action_name, event);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
ShortcutManager.prototype.handles = function (event) {
|
||||
var shortcut = event_to_shortcut(event);
|
||||
var action_name = this.get_shortcut(this._queue.concat(shortcut));
|
||||
return (typeof(action_name) !== 'undefined');
|
||||
};
|
||||
|
||||
return {
|
||||
keycodes : keycodes,
|
||||
inv_keycodes : inv_keycodes,
|
||||
ShortcutManager : ShortcutManager,
|
||||
normalize_key : normalize_key,
|
||||
normalize_shortcut : normalize_shortcut,
|
||||
shortcut_to_event : shortcut_to_event,
|
||||
event_to_shortcut : event_to_shortcut,
|
||||
};
|
||||
});
|
83
venv/Lib/site-packages/notebook/static/base/js/namespace.js
Normal file
|
@ -0,0 +1,83 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
|
||||
var Jupyter = Jupyter || {};
|
||||
|
||||
var jprop = function(name, module_path){
|
||||
Object.defineProperty(Jupyter, name, {
|
||||
get: function() {
|
||||
console.warn('accessing `'+name+'` is deprecated. Use `requirejs("'+module_path+'")`');
|
||||
return requirejs(module_path);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
|
||||
var jglobal = function(name, module_path){
|
||||
Object.defineProperty(Jupyter, name, {
|
||||
get: function() {
|
||||
console.warn('accessing `'+name+'` is deprecated. Use `requirejs("'+module_path+'").'+name+'`');
|
||||
return requirejs(module_path)[name];
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
|
||||
define(function(){
|
||||
"use strict";
|
||||
|
||||
// expose modules
|
||||
|
||||
jprop('utils','base/js/utils')
|
||||
|
||||
//Jupyter.load_extensions = Jupyter.utils.load_extensions;
|
||||
//
|
||||
jprop('security','base/js/security');
|
||||
jprop('keyboard','base/js/keyboard');
|
||||
jprop('dialog','base/js/dialog');
|
||||
jprop('mathjaxutils','notebook/js/mathjaxutils');
|
||||
|
||||
|
||||
//// exposed constructors
|
||||
jglobal('CommManager','services/kernels/comm')
|
||||
jglobal('Comm','services/kernels/comm')
|
||||
|
||||
jglobal('NotificationWidget','base/js/notificationwidget');
|
||||
jglobal('Kernel','services/kernels/kernel');
|
||||
jglobal('Session','services/sessions/session');
|
||||
jglobal('LoginWidget','auth/js/loginwidget');
|
||||
jglobal('Page','base/js/page');
|
||||
|
||||
// notebook
|
||||
jglobal('TextCell','notebook/js/textcell');
|
||||
jglobal('OutputArea','notebook/js/outputarea');
|
||||
jglobal('KeyboardManager','notebook/js/keyboardmanager');
|
||||
jglobal('Completer','notebook/js/completer');
|
||||
jglobal('Notebook','notebook/js/notebook');
|
||||
jglobal('Tooltip','notebook/js/tooltip');
|
||||
jglobal('Toolbar','notebook/js/toolbar');
|
||||
jglobal('SaveWidget','notebook/js/savewidget');
|
||||
jglobal('Pager','notebook/js/pager');
|
||||
jglobal('QuickHelp','notebook/js/quickhelp');
|
||||
jglobal('MarkdownCell','notebook/js/textcell');
|
||||
jglobal('RawCell','notebook/js/textcell');
|
||||
jglobal('Cell','notebook/js/cell');
|
||||
jglobal('MainToolBar','notebook/js/maintoolbar');
|
||||
jglobal('NotebookNotificationArea','notebook/js/notificationarea');
|
||||
jglobal('NotebookTour', 'notebook/js/tour');
|
||||
jglobal('MenuBar', 'notebook/js/menubar');
|
||||
|
||||
// tree
|
||||
jglobal('SessionList','tree/js/sessionlist');
|
||||
|
||||
Jupyter.version = "6.1.5";
|
||||
Jupyter._target = '_blank';
|
||||
|
||||
return Jupyter;
|
||||
});
|
||||
|
||||
// deprecated since 4.0, remove in 5+
|
||||
var IPython = Jupyter;
|
|
@ -0,0 +1,83 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'base/js/notificationwidget',
|
||||
], function($, notificationwidget) {
|
||||
"use strict";
|
||||
|
||||
// store reference to the NotificationWidget class
|
||||
var NotificationWidget = notificationwidget.NotificationWidget;
|
||||
|
||||
/**
|
||||
* Construct the NotificationArea object. Options are:
|
||||
* events: $(Events) instance
|
||||
* save_widget: SaveWidget instance
|
||||
* notebook: Notebook instance
|
||||
* keyboard_manager: KeyboardManager instance
|
||||
*
|
||||
* @constructor
|
||||
* @param {string} selector - a jQuery selector string for the
|
||||
* notification area element
|
||||
* @param {Object} [options] - a dictionary of keyword arguments.
|
||||
*/
|
||||
var NotificationArea = function (selector, options) {
|
||||
this.selector = selector;
|
||||
this.events = options.events;
|
||||
if (this.selector !== undefined) {
|
||||
this.element = $(selector);
|
||||
}
|
||||
this.widget_dict = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a widget by name, creating it if it doesn't exist.
|
||||
*
|
||||
* @method widget
|
||||
* @param {string} name - the widget name
|
||||
*/
|
||||
NotificationArea.prototype.widget = function (name) {
|
||||
if (this.widget_dict[name] === undefined) {
|
||||
return this.new_notification_widget(name);
|
||||
}
|
||||
return this.get_widget(name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a widget by name, throwing an error if it doesn't exist.
|
||||
*
|
||||
* @method get_widget
|
||||
* @param {string} name - the widget name
|
||||
*/
|
||||
NotificationArea.prototype.get_widget = function (name) {
|
||||
if(this.widget_dict[name] === undefined) {
|
||||
throw new Error('no widgets with this name');
|
||||
}
|
||||
return this.widget_dict[name];
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new notification widget with the given name. The
|
||||
* widget must not already exist.
|
||||
*
|
||||
* @method new_notification_widget
|
||||
* @param {string} name - the widget name
|
||||
*/
|
||||
NotificationArea.prototype.new_notification_widget = function (name) {
|
||||
if (this.widget_dict[name] !== undefined) {
|
||||
throw new Error('widget with that name already exists!');
|
||||
}
|
||||
|
||||
// create the element for the notification widget and add it
|
||||
// to the notification aread element
|
||||
var div = $('<div/>').attr('id', 'notification_' + name);
|
||||
$(this.selector).append(div);
|
||||
|
||||
// create the widget object and return it
|
||||
this.widget_dict[name] = new NotificationWidget('#notification_' + name);
|
||||
return this.widget_dict[name];
|
||||
};
|
||||
|
||||
return {'NotificationArea': NotificationArea};
|
||||
});
|
|
@ -0,0 +1,168 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
define(['jquery'], function($) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Construct a NotificationWidget object.
|
||||
*
|
||||
* @constructor
|
||||
* @param {string} selector - a jQuery selector string for the
|
||||
* notification widget element
|
||||
*/
|
||||
var NotificationWidget = function (selector) {
|
||||
this.selector = selector;
|
||||
this.timeout = null;
|
||||
this.busy = false;
|
||||
if (this.selector !== undefined) {
|
||||
this.element = $(selector);
|
||||
this.style();
|
||||
}
|
||||
this.element.hide();
|
||||
this.inner = $('<span/>');
|
||||
this.element.append(this.inner);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add the 'notification_widget' CSS class to the widget element.
|
||||
*
|
||||
* @method style
|
||||
*/
|
||||
NotificationWidget.prototype.style = function () {
|
||||
// use explicit bootstrap classes here,
|
||||
// because multiple inheritance in LESS doesn't work
|
||||
// for this particular combination
|
||||
this.element.addClass('notification_widget btn btn-xs navbar-btn');
|
||||
};
|
||||
|
||||
/**
|
||||
* hide the widget and empty the text
|
||||
**/
|
||||
NotificationWidget.prototype.hide = function () {
|
||||
var that = this;
|
||||
this.element.fadeOut(100, function(){that.inner.text('');});
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the notification widget message to display for a certain
|
||||
* amount of time (timeout). The widget will be shown forever if
|
||||
* timeout is <= 0 or undefined. If the widget is clicked while it
|
||||
* is still displayed, execute an optional callback
|
||||
* (click_callback). If the callback returns false, it will
|
||||
* prevent the notification from being dismissed.
|
||||
*
|
||||
* Options:
|
||||
* class - CSS class name for styling
|
||||
* icon - CSS class name for the widget icon
|
||||
* title - HTML title attribute for the widget
|
||||
*
|
||||
* @method set_message
|
||||
* @param {string} msg - The notification to display
|
||||
* @param {integer} [timeout] - The amount of time in milliseconds to display the widget
|
||||
* @param {function} [click_callback] - The function to run when the widget is clicked
|
||||
* @param {Object} [options] - Additional options
|
||||
*/
|
||||
NotificationWidget.prototype.set_message = function (msg, timeout, click_callback, options) {
|
||||
options = options || {};
|
||||
|
||||
// unbind potential previous callback
|
||||
this.element.unbind('click');
|
||||
this.inner.attr('class', options.icon);
|
||||
this.inner.attr('title', options.title);
|
||||
this.inner.text(msg);
|
||||
this.element.fadeIn(100);
|
||||
|
||||
// reset previous set style
|
||||
this.element.removeClass();
|
||||
this.style();
|
||||
if (options.class) {
|
||||
this.element.addClass(options.class);
|
||||
}
|
||||
|
||||
// clear previous timer
|
||||
if (this.timeout !== null) {
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = null;
|
||||
}
|
||||
|
||||
// set the timer if a timeout is given
|
||||
var that = this;
|
||||
if (timeout !== undefined && timeout >= 0) {
|
||||
this.timeout = setTimeout(function () {
|
||||
that.element.fadeOut(100, function () {that.inner.text('');});
|
||||
that.element.unbind('click');
|
||||
that.timeout = null;
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
// if no click callback assume we will just dismiss the notification
|
||||
if (click_callback === undefined) {
|
||||
click_callback = function(){return true};
|
||||
}
|
||||
// on click, remove widget if click callback say so
|
||||
// and unbind click event.
|
||||
this.element.click(function () {
|
||||
if (click_callback() !== false) {
|
||||
that.element.fadeOut(100, function () {that.inner.text('');});
|
||||
that.element.unbind('click');
|
||||
}
|
||||
if (that.timeout !== null) {
|
||||
clearTimeout(that.timeout);
|
||||
that.timeout = null;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Display an information message (styled with the 'info'
|
||||
* class). Arguments are the same as in set_message. Default
|
||||
* timeout is 3500 milliseconds.
|
||||
*
|
||||
* @method info
|
||||
*/
|
||||
NotificationWidget.prototype.info = function (msg, timeout, click_callback, options) {
|
||||
options = options || {};
|
||||
options.class = options.class + ' info';
|
||||
timeout = timeout || 3500;
|
||||
this.set_message(msg, timeout, click_callback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Display a warning message (styled with the 'warning'
|
||||
* class). Arguments are the same as in set_message. Messages are
|
||||
* sticky by default.
|
||||
*
|
||||
* @method warning
|
||||
*/
|
||||
NotificationWidget.prototype.warning = function (msg, timeout, click_callback, options) {
|
||||
options = options || {};
|
||||
options.class = options.class + ' warning';
|
||||
this.set_message(msg, timeout, click_callback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Display a danger message (styled with the 'danger'
|
||||
* class). Arguments are the same as in set_message. Messages are
|
||||
* sticky by default.
|
||||
*
|
||||
* @method danger
|
||||
*/
|
||||
NotificationWidget.prototype.danger = function (msg, timeout, click_callback, options) {
|
||||
options = options || {};
|
||||
options.class = options.class + ' danger';
|
||||
this.set_message(msg, timeout, click_callback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the text of the widget message.
|
||||
*
|
||||
* @method get_message
|
||||
* @return {string} - the message text
|
||||
*/
|
||||
NotificationWidget.prototype.get_message = function () {
|
||||
return this.inner.html();
|
||||
};
|
||||
|
||||
return {'NotificationWidget': NotificationWidget};
|
||||
});
|
78
venv/Lib/site-packages/notebook/static/base/js/page.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'base/js/events',
|
||||
], function($, events){
|
||||
"use strict";
|
||||
|
||||
var Page = function (header_div_selector, site_div_selector) {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Parameters
|
||||
* header_div_selector: string
|
||||
* site_div_selector: string
|
||||
*/
|
||||
this.header_div_element = $(header_div_selector || 'div#header');
|
||||
this.site_div_element = $(site_div_selector || 'div#site');
|
||||
|
||||
this.bind_events();
|
||||
};
|
||||
|
||||
Page.prototype.bind_events = function () {
|
||||
// resize site on:
|
||||
// - window resize
|
||||
// - header change
|
||||
// - page load
|
||||
var _handle_resize = $.proxy(this._resize_site, this);
|
||||
|
||||
$(window).resize(_handle_resize);
|
||||
|
||||
// On document ready, resize codemirror.
|
||||
$(document).ready(_handle_resize);
|
||||
events.on('resize-header.Page', _handle_resize);
|
||||
};
|
||||
|
||||
Page.prototype.show = function () {
|
||||
/**
|
||||
* The header and site divs start out hidden to prevent FLOUC.
|
||||
* Main scripts should call this method after styling everything.
|
||||
*/
|
||||
this.show_header();
|
||||
this.show_site();
|
||||
};
|
||||
|
||||
Page.prototype.show_header = function () {
|
||||
/**
|
||||
* The header and site divs start out hidden to prevent FLOUC.
|
||||
* Main scripts should call this method after styling everything.
|
||||
*/
|
||||
this.header_div_element.css('display','block');
|
||||
};
|
||||
|
||||
Page.prototype.show_site = function () {
|
||||
/**
|
||||
* The header and site divs start out hidden to prevent FLOUC.
|
||||
* Main scripts should call this method after styling everything.
|
||||
*/
|
||||
this.site_div_element.css('display', 'block');
|
||||
this._resize_site();
|
||||
};
|
||||
|
||||
Page.prototype._resize_site = function(e) {
|
||||
/**
|
||||
* Update the site's size.
|
||||
*/
|
||||
|
||||
// In the case an event is passed in, only trigger if the event does
|
||||
// *not* have a target DOM node (i.e., it is not bubbling up). See
|
||||
// https://bugs.jquery.com/ticket/9841#comment:8
|
||||
if (!(e && e.target && e.target.tagName)) {
|
||||
$('div#site').height($(window).height() - $('#header').height());
|
||||
}
|
||||
};
|
||||
|
||||
return {'Page': Page};
|
||||
});
|
26
venv/Lib/site-packages/notebook/static/base/js/promises.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
// Define an object to attach promises to for one-time events.
|
||||
|
||||
define(['base/js/events', 'base/js/namespace'], function(events, Jupyter) {
|
||||
"use strict";
|
||||
|
||||
// Promise to be resolved when the application is initialized.
|
||||
// The value is the name of the app on the current page.
|
||||
var app_initialized = new Promise(function(resolve, reject) {
|
||||
events.on('app_initialized.NotebookApp', function() {
|
||||
resolve('NotebookApp');
|
||||
});
|
||||
events.on('app_initialized.DashboardApp', function() {
|
||||
resolve('DashboardApp');
|
||||
});
|
||||
});
|
||||
|
||||
var promises = {
|
||||
app_initialized: app_initialized
|
||||
};
|
||||
Jupyter.promises = promises;
|
||||
|
||||
return promises;
|
||||
});
|
152
venv/Lib/site-packages/notebook/static/base/js/security.js
Normal file
|
@ -0,0 +1,152 @@
|
|||
// Copyright (c) Jupyter Development Team.
|
||||
// Distributed under the terms of the Modified BSD License.
|
||||
|
||||
define([
|
||||
'jquery',
|
||||
'components/google-caja/html-css-sanitizer-minified',
|
||||
], function($, sanitize) {
|
||||
"use strict";
|
||||
|
||||
var noop = function (x) { return x; };
|
||||
|
||||
var caja;
|
||||
if (window && window.html) {
|
||||
caja = window.html;
|
||||
caja.html4 = window.html4;
|
||||
caja.sanitizeStylesheet = window.sanitizeStylesheet;
|
||||
}
|
||||
|
||||
var sanitizeAttribs = function (tagName, attribs, opt_naiveUriRewriter, opt_nmTokenPolicy, opt_logger) {
|
||||
/**
|
||||
* add trusting data-attributes to the default sanitizeAttribs from caja
|
||||
* this function is mostly copied from the caja source
|
||||
*/
|
||||
var ATTRIBS = caja.html4.ATTRIBS;
|
||||
for (var i = 0; i < attribs.length; i += 2) {
|
||||
var attribName = attribs[i];
|
||||
if (attribName.substr(0,5) == 'data-') {
|
||||
var attribKey = '*::' + attribName;
|
||||
if (!ATTRIBS.hasOwnProperty(attribKey)) {
|
||||
ATTRIBS[attribKey] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Caja doesn't allow data uri for img::src, see
|
||||
// https://github.com/google/caja/issues/1558
|
||||
// This is not a security issue for browser post ie6 though, so we
|
||||
// disable the check
|
||||
// https://www.owasp.org/index.php/Script_in_IMG_tags
|
||||
ATTRIBS['img::src'] = 0;
|
||||
return caja.sanitizeAttribs(tagName, attribs, opt_naiveUriRewriter, opt_nmTokenPolicy, opt_logger);
|
||||
};
|
||||
|
||||
var sanitize_css = function (css, tagPolicy) {
|
||||
/**
|
||||
* sanitize CSS
|
||||
* like sanitize_html, but for CSS
|
||||
* called by sanitize_stylesheets
|
||||
*/
|
||||
return caja.sanitizeStylesheet(
|
||||
window.location.pathname,
|
||||
css,
|
||||
{
|
||||
containerClass: null,
|
||||
idSuffix: '',
|
||||
tagPolicy: tagPolicy,
|
||||
virtualizeAttrName: noop
|
||||
},
|
||||
noop
|
||||
);
|
||||
};
|
||||
|
||||
var sanitize_stylesheets = function (html, tagPolicy) {
|
||||
/**
|
||||
* sanitize just the css in style tags in a block of html
|
||||
* called by sanitize_html, if allow_css is true
|
||||
*/
|
||||
var h = $("<div/>").append(html);
|
||||
var style_tags = h.find("style");
|
||||
if (!style_tags.length) {
|
||||
// no style tags to sanitize
|
||||
return html;
|
||||
}
|
||||
style_tags.each(function(i, style) {
|
||||
style.innerHTML = sanitize_css(style.innerHTML, tagPolicy);
|
||||
});
|
||||
return h.html();
|
||||
};
|
||||
|
||||
var sanitize_html = function (html, allow_css) {
|
||||
/**
|
||||
* sanitize HTML
|
||||
* if allow_css is true (default: false), CSS is sanitized as well.
|
||||
* otherwise, CSS elements and attributes are simply removed.
|
||||
*/
|
||||
var html4 = caja.html4;
|
||||
|
||||
if (allow_css) {
|
||||
// allow sanitization of style tags,
|
||||
// not just scrubbing
|
||||
html4.ELEMENTS.style &= ~html4.eflags.UNSAFE;
|
||||
html4.ATTRIBS.style = html4.atype.STYLE;
|
||||
} else {
|
||||
// scrub all CSS
|
||||
html4.ELEMENTS.style |= html4.eflags.UNSAFE;
|
||||
html4.ATTRIBS.style = html4.atype.SCRIPT;
|
||||
}
|
||||
|
||||
var record_messages = function (msg, opts) {
|
||||
console.log("HTML Sanitizer", msg, opts);
|
||||
};
|
||||
|
||||
var policy = function (tagName, attribs) {
|
||||
if (!(html4.ELEMENTS[tagName] & html4.eflags.UNSAFE)) {
|
||||
return {
|
||||
'attribs': sanitizeAttribs(tagName, attribs,
|
||||
noop, noop, record_messages)
|
||||
};
|
||||
} else {
|
||||
record_messages(tagName + " removed", {
|
||||
change: "removed",
|
||||
tagName: tagName
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var sanitized = caja.sanitizeWithPolicy(html, policy);
|
||||
|
||||
if (allow_css) {
|
||||
// sanitize style tags as stylesheets
|
||||
sanitized = sanitize_stylesheets(sanitized, policy);
|
||||
}
|
||||
|
||||
return sanitized;
|
||||
};
|
||||
|
||||
var sanitize_html_and_parse = function (html, allow_css) {
|
||||
/**
|
||||
* Sanitize HTML and parse it safely using jQuery.
|
||||
*
|
||||
* This disable's jQuery's html 'prefilter', which can make invalid
|
||||
* HTML valid after the sanitizer has checked it.
|
||||
*
|
||||
* Returns an array of DOM nodes.
|
||||
*/
|
||||
var sanitized_html = sanitize_html(html, allow_css);
|
||||
var prev_htmlPrefilter = $.htmlPrefilter;
|
||||
$.htmlPrefilter = function(html) {return html;}; // Don't modify HTML
|
||||
try {
|
||||
return $.parseHTML(sanitized_html);
|
||||
} finally {
|
||||
$.htmlPrefilter = prev_htmlPrefilter; // Set it back again
|
||||
}
|
||||
};
|
||||
|
||||
var security = {
|
||||
caja: caja,
|
||||
sanitize_html_and_parse: sanitize_html_and_parse,
|
||||
sanitize_html: sanitize_html
|
||||
};
|
||||
|
||||
return security;
|
||||
});
|