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