Show More
@@ -1,84 +1,84 b'' | |||
|
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 | "use strict"; |
|
16 | 16 | |
|
17 | 17 | var modal = function (options) { |
|
18 | 18 | var dialog = $("<div/>").addClass("modal").attr("role", "dialog"); |
|
19 | 19 | dialog.append( |
|
20 | 20 | $("<div/>") |
|
21 | 21 | .addClass("modal-header") |
|
22 | 22 | .append($("<button>") |
|
23 | 23 | .addClass("close") |
|
24 | 24 | .attr("data-dismiss", "modal") |
|
25 | 25 | .html("×") |
|
26 | 26 | ).append( |
|
27 | 27 | $("<h3/>").text(options.title || "") |
|
28 | 28 | ) |
|
29 | 29 | ).append( |
|
30 | 30 | $("<div/>").addClass("modal-body").append( |
|
31 | 31 | options.body || $("<p/>") |
|
32 | 32 | ) |
|
33 | 33 | ); |
|
34 | 34 | |
|
35 | 35 | var footer = $("<div/>").addClass("modal-footer"); |
|
36 | 36 | |
|
37 | 37 | for (var label in options.buttons) { |
|
38 | 38 | var btn_opts = options.buttons[label]; |
|
39 | 39 | var button = $("<button/>") |
|
40 | 40 | .addClass("btn") |
|
41 | 41 | .attr("data-dismiss", "modal") |
|
42 | 42 | .text(label); |
|
43 | 43 | if (btn_opts.click) { |
|
44 | 44 | button.click($.proxy(btn_opts.click, dialog)); |
|
45 | 45 | } |
|
46 | 46 | if (btn_opts.class) { |
|
47 | 47 | button.addClass(btn_opts.class); |
|
48 | 48 | } |
|
49 | 49 | footer.append(button); |
|
50 | 50 | } |
|
51 | 51 | dialog.append(footer); |
|
52 | 52 | // hook up on-open event |
|
53 | 53 | dialog.on("shown", function() { |
|
54 | 54 | setTimeout(function() { |
|
55 | 55 | footer.find("button").last().focus(); |
|
56 | 56 | if (options.open) { |
|
57 | 57 | $.proxy(options.open, dialog)(); |
|
58 | 58 | } |
|
59 | 59 | }, 0); |
|
60 | 60 | }); |
|
61 | 61 | |
|
62 | 62 | // destroy dialog on hide, unless explicitly asked not to |
|
63 | 63 | if (options.destroy == undefined || options.destroy) { |
|
64 | 64 | dialog.on("hidden", function () { |
|
65 | 65 | dialog.remove(); |
|
66 | 66 | }); |
|
67 | 67 | } |
|
68 | 68 | if (options.reselect_cell !== false) { |
|
69 | 69 | dialog.on("hidden", function () { |
|
70 | 70 | if (IPython.notebook) { |
|
71 | cell = IPython.notebook.get_selected_cell(); | |
|
71 | var cell = IPython.notebook.get_selected_cell(); | |
|
72 | 72 | if (cell) cell.select(); |
|
73 | 73 | } |
|
74 | 74 | }); |
|
75 | 75 | } |
|
76 | 76 | |
|
77 | 77 | return dialog.modal(options); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | return { |
|
81 | 81 | modal : modal, |
|
82 | 82 | }; |
|
83 | 83 | |
|
84 | 84 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now