##// END OF EJS Templates
Merge pull request #3660 from minrk/focusclick...
Min RK -
r11531:402e85e9 merge
parent child Browse files
Show More
@@ -1,75 +1,83
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2013 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // Utility for modal dialogs with bootstrap
10 10 //============================================================================
11 11
12 12 IPython.namespace('IPython.dialog');
13 13
14 14 IPython.dialog = (function (IPython) {
15 15
16 16 var modal = function (options) {
17 17 var dialog = $("<div/>").addClass("modal").attr("role", "dialog");
18 18 dialog.append(
19 19 $("<div/>")
20 20 .addClass("modal-header")
21 21 .append($("<button>")
22 22 .addClass("close")
23 23 .attr("data-dismiss", "modal")
24 24 .html("&times;")
25 25 ).append(
26 26 $("<h3/>").text(options.title || "")
27 27 )
28 28 ).append(
29 29 $("<div/>").addClass("modal-body").append(
30 30 options.body || $("<p/>")
31 31 )
32 32 );
33 33
34 34 var footer = $("<div/>").addClass("modal-footer");
35 35
36 36 for (var label in options.buttons) {
37 37 var btn_opts = options.buttons[label];
38 38 var button = $("<button/>")
39 39 .addClass("btn")
40 40 .attr("data-dismiss", "modal")
41 41 .text(label);
42 42 if (btn_opts.click) {
43 43 button.click($.proxy(btn_opts.click, dialog));
44 44 }
45 45 if (btn_opts.class) {
46 46 button.addClass(btn_opts.class);
47 47 }
48 48 footer.append(button);
49 49 }
50 50 dialog.append(footer);
51 51 // hook up on-open event
52 52 dialog.on("shown", function() {
53 53 setTimeout(function() {
54 54 footer.find("button").last().focus();
55 55 if (options.open) {
56 56 $.proxy(options.open, dialog)();
57 57 }
58 58 }, 0);
59 59 });
60 60
61 61 // destroy dialog on hide, unless explicitly asked not to
62 62 if (options.destroy == undefined || options.destroy) {
63 63 dialog.on("hidden", function () {
64 64 dialog.remove();
65 65 });
66 66 }
67 if (options.reselect_cell !== false) {
68 dialog.on("hidden", function () {
69 if (IPython.notebook) {
70 cell = IPython.notebook.get_selected_cell();
71 if (cell) cell.select();
72 }
73 });
74 }
67 75
68 76 return dialog.modal(options);
69 77 }
70 78
71 79 return {
72 80 modal : modal,
73 81 };
74 82
75 83 }(IPython));
General Comments 0
You need to be logged in to leave comments. Login now