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