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