Show More
@@ -15,16 +15,47 IPython.dialog = (function (IPython) { | |||||
15 | "use strict"; |
|
15 | "use strict"; | |
16 |
|
16 | |||
17 | var modal = function (options) { |
|
17 | var modal = function (options) { | |
18 | var dialog = $("<div/>").addClass("modal").attr("role", "dialog"); |
|
18 | // <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> | |
19 | dialog.append( |
|
19 | // <div class="modal-dialog"> | |
|
20 | // <div class="modal-content"> | |||
|
21 | // <div class="modal-header"> | |||
|
22 | // <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | |||
|
23 | // <h4 class="modal-title" id="myModalLabel">Modal title</h4> | |||
|
24 | // </div> | |||
|
25 | // <div class="modal-body"> | |||
|
26 | // ... | |||
|
27 | // </div> | |||
|
28 | // <div class="modal-footer"> | |||
|
29 | // <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | |||
|
30 | // <button type="button" class="btn btn-primary">Save changes</button> | |||
|
31 | // </div> | |||
|
32 | // </div> | |||
|
33 | // </div> | |||
|
34 | // </div> | |||
|
35 | ||||
|
36 | var modal = $("<div/>") | |||
|
37 | .addClass("modal") | |||
|
38 | .addClass("fade") | |||
|
39 | .attr("role", "dialog"); | |||
|
40 | var dialog = $("<div/>") | |||
|
41 | .addClass("modal-dialog") | |||
|
42 | .appendTo(modal); | |||
|
43 | var dialog_content = $("<div/>") | |||
|
44 | .addClass("modal-content") | |||
|
45 | .appendTo(dialog); | |||
|
46 | dialog_content.append( | |||
20 | $("<div/>") |
|
47 | $("<div/>") | |
21 | .addClass("modal-header") |
|
48 | .addClass("modal-header") | |
22 | .append($("<button>") |
|
49 | .append($("<button>") | |
|
50 | .attr("type", "button") | |||
23 | .addClass("close") |
|
51 | .addClass("close") | |
24 | .attr("data-dismiss", "modal") |
|
52 | .attr("data-dismiss", "modal") | |
|
53 | .attr("aria-hidden", "true") | |||
25 | .html("×") |
|
54 | .html("×") | |
26 | ).append( |
|
55 | ).append( | |
27 |
$("<h |
|
56 | $("<h4/>") | |
|
57 | .addClass('modal-title') | |||
|
58 | .text(options.title || "") | |||
28 | ) |
|
59 | ) | |
29 | ).append( |
|
60 | ).append( | |
30 | $("<div/>").addClass("modal-body").append( |
|
61 | $("<div/>").addClass("modal-body").append( | |
@@ -41,31 +72,31 IPython.dialog = (function (IPython) { | |||||
41 | .attr("data-dismiss", "modal") |
|
72 | .attr("data-dismiss", "modal") | |
42 | .text(label); |
|
73 | .text(label); | |
43 | if (btn_opts.click) { |
|
74 | if (btn_opts.click) { | |
44 | button.click($.proxy(btn_opts.click, dialog)); |
|
75 | button.click($.proxy(btn_opts.click, dialog_content)); | |
45 | } |
|
76 | } | |
46 | if (btn_opts.class) { |
|
77 | if (btn_opts.class) { | |
47 | button.addClass(btn_opts.class); |
|
78 | button.addClass(btn_opts.class); | |
48 | } |
|
79 | } | |
49 | footer.append(button); |
|
80 | footer.append(button); | |
50 | } |
|
81 | } | |
51 | dialog.append(footer); |
|
82 | dialog_content.append(footer); | |
52 | // hook up on-open event |
|
83 | // hook up on-open event | |
53 |
d |
|
84 | modal.on("shown", function() { | |
54 | setTimeout(function() { |
|
85 | setTimeout(function() { | |
55 | footer.find("button").last().focus(); |
|
86 | footer.find("button").last().focus(); | |
56 | if (options.open) { |
|
87 | if (options.open) { | |
57 |
$.proxy(options.open, d |
|
88 | $.proxy(options.open, modal)(); | |
58 | } |
|
89 | } | |
59 | }, 0); |
|
90 | }, 0); | |
60 | }); |
|
91 | }); | |
61 |
|
92 | |||
62 |
// destroy d |
|
93 | // destroy modal on hide, unless explicitly asked not to | |
63 | if (options.destroy === undefined || options.destroy) { |
|
94 | if (options.destroy === undefined || options.destroy) { | |
64 |
d |
|
95 | modal.on("hidden", function () { | |
65 |
d |
|
96 | modal.remove(); | |
66 | }); |
|
97 | }); | |
67 | } |
|
98 | } | |
68 |
d |
|
99 | modal.on("hidden", function () { | |
69 | if (IPython.notebook) { |
|
100 | if (IPython.notebook) { | |
70 | var cell = IPython.notebook.get_selected_cell(); |
|
101 | var cell = IPython.notebook.get_selected_cell(); | |
71 | if (cell) cell.select(); |
|
102 | if (cell) cell.select(); | |
@@ -78,7 +109,7 IPython.dialog = (function (IPython) { | |||||
78 | IPython.keyboard_manager.disable(); |
|
109 | IPython.keyboard_manager.disable(); | |
79 | } |
|
110 | } | |
80 |
|
111 | |||
81 |
return d |
|
112 | return modal.modal(options); | |
82 | }; |
|
113 | }; | |
83 |
|
114 | |||
84 | var edit_metadata = function (md, callback, name) { |
|
115 | var edit_metadata = function (md, callback, name) { |
@@ -80,9 +80,9 span#login_widget { | |||||
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | // class for stretching dialogs to fill the screen |
|
82 | // class for stretching dialogs to fill the screen | |
83 | .modal_stretch { |
|
83 | .modal_stretch .modal-dialog { | |
84 | .vbox(); |
|
84 | .vbox(); | |
85 | height: 80%; |
|
85 | min-height: 80%; | |
86 | .modal-body { |
|
86 | .modal-body { | |
87 | max-height: none; |
|
87 | max-height: none; | |
88 | flex: 1; |
|
88 | flex: 1; | |
@@ -90,9 +90,8 span#login_widget { | |||||
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | @media (min-width: 768px) { |
|
92 | @media (min-width: 768px) { | |
93 | .modal { |
|
93 | .modal .modal-dialog { | |
94 | width: 700px; |
|
94 | width: 700px; | |
95 | margin-left: -350px; |
|
|||
96 | } |
|
95 | } | |
97 | } |
|
96 | } | |
98 |
|
97 |
General Comments 0
You need to be logged in to leave comments.
Login now