Show More
@@ -1,187 +1,188 | |||
|
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 | // ContainerWidget |
|
10 | 10 | //============================================================================ |
|
11 | 11 | |
|
12 | 12 | /** |
|
13 | 13 | * @module IPython |
|
14 | 14 | * @namespace IPython |
|
15 | 15 | **/ |
|
16 | 16 | |
|
17 | 17 | define(["notebook/js/widget"], function(widget_manager) { |
|
18 | 18 | var ContainerModel = IPython.WidgetModel.extend({}); |
|
19 | 19 | widget_manager.register_widget_model('ContainerWidgetModel', ContainerModel); |
|
20 | 20 | |
|
21 | 21 | var ContainerView = IPython.WidgetView.extend({ |
|
22 | 22 | |
|
23 | 23 | render: function(){ |
|
24 | 24 | this.$el |
|
25 | 25 | .addClass('widget-container'); |
|
26 | 26 | }, |
|
27 | 27 | |
|
28 | 28 | update: function(){ |
|
29 | 29 | |
|
30 | 30 | // Apply flexible box model properties by adding and removing |
|
31 | 31 | // corrosponding CSS classes. |
|
32 | 32 | // Defined in IPython/html/static/base/less/flexbox.less |
|
33 | 33 | this.set_flex_property('vbox', this.model.get('_vbox')); |
|
34 | 34 | this.set_flex_property('hbox', this.model.get('_hbox')); |
|
35 | 35 | this.set_flex_property('start', this.model.get('_pack_start')); |
|
36 | 36 | this.set_flex_property('center', this.model.get('_pack_center')); |
|
37 | 37 | this.set_flex_property('end', this.model.get('_pack_end')); |
|
38 | 38 | this.set_flex_property('align-start', this.model.get('_align_start')); |
|
39 | 39 | this.set_flex_property('align-center', this.model.get('_align_center')); |
|
40 | 40 | this.set_flex_property('align-end', this.model.get('_align_end')); |
|
41 | 41 | this.set_flex_property('box-flex0', this.model.get('_flex0')); |
|
42 | 42 | this.set_flex_property('box-flex1', this.model.get('_flex1')); |
|
43 | 43 | this.set_flex_property('box-flex2', this.model.get('_flex2')); |
|
44 | 44 | |
|
45 | 45 | return IPython.WidgetView.prototype.update.call(this); |
|
46 | 46 | }, |
|
47 | 47 | |
|
48 | 48 | set_flex_property: function(property_name, enabled) { |
|
49 | 49 | if (enabled) { |
|
50 | 50 | this.$el.addClass(property_name); |
|
51 | 51 | } else { |
|
52 | 52 | this.$el.removeClass(property_name); |
|
53 | 53 | } |
|
54 | 54 | }, |
|
55 | 55 | |
|
56 | 56 | display_child: function(view) { |
|
57 | 57 | this.$el.append(view.$el); |
|
58 | 58 | }, |
|
59 | 59 | }); |
|
60 | 60 | |
|
61 | 61 | widget_manager.register_widget_view('ContainerView', ContainerView); |
|
62 | 62 | |
|
63 | 63 | |
|
64 | 64 | var ModalView = IPython.WidgetView.extend({ |
|
65 | 65 | |
|
66 | 66 | render: function(){ |
|
67 | 67 | var that = this; |
|
68 | 68 | this.$el |
|
69 | 69 | .html('') |
|
70 | 70 | .on("remove", function(){ |
|
71 | 71 | that.$window.remove(); |
|
72 | 72 | }); |
|
73 | 73 | this.$window = $('<div />') |
|
74 | 74 | .addClass('modal widget-modal') |
|
75 | 75 | .appendTo($('#notebook-container')); |
|
76 | 76 | this.$title_bar = $('<div />') |
|
77 | 77 | .addClass('popover-title') |
|
78 | 78 | .appendTo(this.$window); |
|
79 | 79 | var that = this; |
|
80 | 80 | $('<button />') |
|
81 | 81 | .addClass('close') |
|
82 | 82 | .html('×') |
|
83 | 83 | .appendTo(this.$title_bar) |
|
84 | 84 | .click(function(){ |
|
85 | 85 | that.hide(); |
|
86 | 86 | event.stopPropagation(); |
|
87 | 87 | }); |
|
88 | 88 | this.$title = $('<div />') |
|
89 | 89 | .addClass('widget-modal-title') |
|
90 | 90 | .html(' ') |
|
91 | 91 | .appendTo(this.$title_bar); |
|
92 | 92 | this.$body = $('<div />') |
|
93 | 93 | .addClass('modal-body') |
|
94 | 94 | .addClass('widget-modal-body') |
|
95 | 95 | .addClass('widget-container') |
|
96 | 96 | .appendTo(this.$window); |
|
97 | 97 | |
|
98 | 98 | this.$show_button = $('<button />') |
|
99 | 99 | .html(' ') |
|
100 | 100 | .addClass('btn btn-info widget-modal-show') |
|
101 | 101 | .appendTo(this.$el) |
|
102 | 102 | .click(function(){ |
|
103 | 103 | that.show(); |
|
104 | 104 | }); |
|
105 | 105 | |
|
106 | 106 | this.$window.draggable({handle: '.popover-title', snap: '#notebook, .modal', snapMode: 'both'}); |
|
107 | 107 | this.$window.resizable(); |
|
108 | 108 | this.$window.on('resize', function(){ |
|
109 | 109 | that.$body.outerHeight(that.$window.innerHeight() - that.$title_bar.outerHeight()); |
|
110 | 110 | }) |
|
111 | 111 | |
|
112 | 112 | this._shown_once = false; |
|
113 | 113 | }, |
|
114 | 114 | |
|
115 | 115 | hide: function() { |
|
116 | 116 | this.$window.hide(); |
|
117 | 117 | this.$show_button.removeClass('btn-info'); |
|
118 | 118 | }, |
|
119 | 119 | |
|
120 | 120 | show: function() { |
|
121 | 121 | this.$window.show(); |
|
122 | 122 | this.$show_button.addClass('btn-info'); |
|
123 | var position = this.$show_button.offset(); | |
|
124 | this.$window.css('left', position.left + this.$show_button.outerWidth()); | |
|
125 | this.$window.css('top', position.top); | |
|
123 | this.$window.css("top", Math.max(0, (($(window).height() - this.$window.outerHeight()) / 2) + | |
|
124 | $(window).scrollTop()) + "px"); | |
|
125 | this.$window.css("left", Math.max(0, (($(window).width() - this.$window.outerWidth()) / 2) + | |
|
126 | $(window).scrollLeft()) + "px"); | |
|
126 | 127 | }, |
|
127 | 128 | |
|
128 | 129 | update: function(){ |
|
129 | 130 | |
|
130 | 131 | // Apply flexible box model properties by adding and removing |
|
131 | 132 | // corrosponding CSS classes. |
|
132 | 133 | // Defined in IPython/html/static/base/less/flexbox.less |
|
133 | 134 | this.set_flex_property('vbox', this.model.get('_vbox')); |
|
134 | 135 | this.set_flex_property('hbox', this.model.get('_hbox')); |
|
135 | 136 | this.set_flex_property('start', this.model.get('_pack_start')); |
|
136 | 137 | this.set_flex_property('center', this.model.get('_pack_center')); |
|
137 | 138 | this.set_flex_property('end', this.model.get('_pack_end')); |
|
138 | 139 | this.set_flex_property('align-start', this.model.get('_align_start')); |
|
139 | 140 | this.set_flex_property('align-center', this.model.get('_align_center')); |
|
140 | 141 | this.set_flex_property('align-end', this.model.get('_align_end')); |
|
141 | 142 | this.set_flex_property('box-flex0', this.model.get('_flex0')); |
|
142 | 143 | this.set_flex_property('box-flex1', this.model.get('_flex1')); |
|
143 | 144 | this.set_flex_property('box-flex2', this.model.get('_flex2')); |
|
144 | 145 | |
|
145 | 146 | var description = this.model.get('description'); |
|
146 | 147 | description = description.replace(/ /g, ' ', 'm'); |
|
147 | 148 | description = description.replace(/\n/g, '<br>\n', 'm'); |
|
148 | 149 | if (description.length == 0) { |
|
149 | 150 | this.$title.html(' '); // Preserve title height |
|
150 | 151 | } else { |
|
151 | 152 | this.$title.html(description); |
|
152 | 153 | } |
|
153 | 154 | |
|
154 | 155 | var button_text = this.model.get('button_text'); |
|
155 | 156 | button_text = button_text.replace(/ /g, ' ', 'm'); |
|
156 | 157 | button_text = button_text.replace(/\n/g, '<br>\n', 'm'); |
|
157 | 158 | if (button_text.length == 0) { |
|
158 | 159 | this.$show_button.html(' '); // Preserve button height |
|
159 | 160 | } else { |
|
160 | 161 | this.$show_button.html(button_text); |
|
161 | 162 | } |
|
162 | 163 | |
|
163 | 164 | if (!this._shown_once) { |
|
164 | 165 | this._shown_once = true; |
|
165 | 166 | this.show(); |
|
166 | 167 | } |
|
167 | 168 | |
|
168 | 169 | return IPython.WidgetView.prototype.update.call(this); |
|
169 | 170 | }, |
|
170 | 171 | |
|
171 | 172 | set_flex_property: function(property_name, enabled) { |
|
172 | 173 | if (enabled) { |
|
173 | 174 | this.$body.addClass(property_name); |
|
174 | 175 | } else { |
|
175 | 176 | this.$body.removeClass(property_name); |
|
176 | 177 | } |
|
177 | 178 | }, |
|
178 | 179 | |
|
179 | 180 | display_child: function(view) { |
|
180 | 181 | this.$body.append(view.$el); |
|
181 | 182 | }, |
|
182 | 183 | |
|
183 | 184 | |
|
184 | 185 | }); |
|
185 | 186 | |
|
186 | 187 | widget_manager.register_widget_view('ModalView', ModalView); |
|
187 | 188 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now