mirror of
https://github.com/jupyter/notebook.git
synced 2025-03-19 13:20:36 +08:00
add missing dialog.js
This commit is contained in:
parent
78199220da
commit
9f2e3975b3
78
IPython/frontend/html/notebook/static/base/js/dialog.js
Normal file
78
IPython/frontend/html/notebook/static/base/js/dialog.js
Normal file
@ -0,0 +1,78 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// Copyright (C) 2013 The IPython Development Team
|
||||
//
|
||||
// Distributed under the terms of the BSD License. The full license is in
|
||||
// the file COPYING, distributed as part of this software.
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
//============================================================================
|
||||
// Utility for modal dialogs with bootstrap
|
||||
//============================================================================
|
||||
|
||||
IPython.namespace('IPython.dialog');
|
||||
|
||||
IPython.dialog = (function (IPython) {
|
||||
|
||||
var modal = function (options) {
|
||||
var dialog = $("<div/>").addClass("modal").attr("role", "dialog");
|
||||
dialog.append(
|
||||
$("<div/>")
|
||||
.addClass("modal-header")
|
||||
.append($("<button>")
|
||||
.addClass("close")
|
||||
.attr("data-dismiss", "modal")
|
||||
.html("×")
|
||||
).append(
|
||||
$("<h3/>").text(options.title || "")
|
||||
)
|
||||
).append(
|
||||
$("<div/>").addClass("modal-body").append(
|
||||
options.body || $("<p/>")
|
||||
)
|
||||
);
|
||||
|
||||
var footer = $("<div/>").addClass("modal-footer");
|
||||
|
||||
for (var label in options.buttons) {
|
||||
var btn_opts = options.buttons[label];
|
||||
var button = $("<button/>")
|
||||
.addClass("btn")
|
||||
.attr("data-dismiss", "modal")
|
||||
.text(label);
|
||||
if (btn_opts.click) {
|
||||
button.click($.proxy(btn_opts.click, dialog));
|
||||
}
|
||||
if (btn_opts.class) {
|
||||
button.addClass(btn_opts.class);
|
||||
}
|
||||
footer.append(button);
|
||||
}
|
||||
dialog.append(footer);
|
||||
// hook up on-open event
|
||||
dialog.on("shown", function() {
|
||||
setTimeout(function() {
|
||||
footer.find("button").last().focus();
|
||||
if (options.open) {
|
||||
$.proxy(options.open, dialog)();
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
|
||||
// destroy dialog on hide, unless explicitly asked not to
|
||||
if (options.destroy == undefined || options.destroy) {
|
||||
dialog.on("hidden", function () {
|
||||
dialog.remove();
|
||||
});
|
||||
}
|
||||
|
||||
dialog.modal(options);
|
||||
// setTimeout(function() {
|
||||
// footer.find("button").last().focus()
|
||||
// }, 0);
|
||||
}
|
||||
|
||||
return {
|
||||
modal : modal,
|
||||
};
|
||||
|
||||
}(IPython));
|
Loading…
x
Reference in New Issue
Block a user