##// END OF EJS Templates
Remove uneccessary lines in String.js
Jonathan Frederic -
Show More
@@ -1,190 +1,188 b''
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 // StringWidget
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 StringWidgetModel = IPython.WidgetModel.extend({});
19 19 widget_manager.register_widget_model('StringWidgetModel', StringWidgetModel);
20 20
21 21 var HTMLView = IPython.WidgetView.extend({
22 22
23 23 // Called when view is rendered.
24 24 render : function(){
25 25 this.update(); // Set defaults.
26 26 },
27 27
28 28 // Handles: Backend -> Frontend Sync
29 29 // Frontent -> Frontend Sync
30 30 update : function(){
31 31 this.$el.html(this.model.get('value'));
32 32 return IPython.WidgetView.prototype.update.call(this);
33 33 },
34 34
35 35 });
36 36
37 37 widget_manager.register_widget_view('HTMLView', HTMLView);
38 38
39 39
40 40 var LatexView = IPython.WidgetView.extend({
41 41
42 42 // Called when view is rendered.
43 43 render : function(){
44 44 this.update(); // Set defaults.
45 45 },
46 46
47 47 // Handles: Backend -> Frontend Sync
48 48 // Frontent -> Frontend Sync
49 49 update : function(){
50 var that=this;
51 50 this.$el.html(this.model.get('value'));
52 var math_el = that.$el.get(0);
53 MathJax.Hub.Queue(["Typeset",MathJax.Hub,math_el]);
54
51 MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$el.get(0)]);
52
55 53 return IPython.WidgetView.prototype.update.call(this);
56 54 },
57 55
58 56 });
59 57
60 58 widget_manager.register_widget_view('LatexView', LatexView);
61 59
62 60 var TextAreaView = IPython.WidgetView.extend({
63 61
64 62 // Called when view is rendered.
65 63 render: function(){
66 64 this.$el
67 65 .addClass('widget-hbox')
68 66 .html('');
69 67 this.$label = $('<div />')
70 68 .appendTo(this.$el)
71 69 .addClass('widget-hlabel')
72 70 .hide();
73 71 this.$textbox = $('<textarea />')
74 72 .attr('rows', 5)
75 73 .addClass('widget-text')
76 74 .appendTo(this.$el);
77 75 this.$el_to_style = this.$textbox; // Set default element to style
78 76 this.update(); // Set defaults.
79 77
80 78 this.model.on_msg($.proxy(this._handle_textarea_msg, this));
81 79 },
82 80
83 81
84 82 _handle_textarea_msg: function (content){
85 83 if (content.method == "scroll_to_bottom") {
86 84 this.scroll_to_bottom();
87 85 }
88 86 },
89 87
90 88
91 89 scroll_to_bottom: function (){
92 90 this.$textbox.scrollTop(this.$textbox[0].scrollHeight);
93 91 },
94 92
95 93
96 94 // Handles: Backend -> Frontend Sync
97 95 // Frontent -> Frontend Sync
98 96 update: function(){
99 97 if (!this.user_invoked_update) {
100 98 this.$textbox.val(this.model.get('value'));
101 99 }
102 100
103 101 var disabled = this.model.get('disabled');
104 102 this.$textbox.prop('disabled', disabled);
105 103
106 104 var description = this.model.get('description');
107 105 if (description.length == 0) {
108 106 this.$label.hide();
109 107 } else {
110 108 this.$label.html(description);
111 109 this.$label.show();
112 110 }
113 111 return IPython.WidgetView.prototype.update.call(this);
114 112 },
115 113
116 114 events: {"keyup textarea": "handleChanging",
117 115 "paste textarea": "handleChanging",
118 116 "cut textarea": "handleChanging"},
119 117
120 118 // Handles and validates user input.
121 119 handleChanging: function(e) {
122 120 this.user_invoked_update = true;
123 121 this.model.set('value', e.target.value);
124 122 this.model.update_other_views(this);
125 123 this.user_invoked_update = false;
126 124 },
127 125 });
128 126
129 127 widget_manager.register_widget_view('TextAreaView', TextAreaView);
130 128
131 129 var TextBoxView = IPython.WidgetView.extend({
132 130
133 131 // Called when view is rendered.
134 132 render: function(){
135 133 this.$el
136 134 .addClass('widget-hbox-single')
137 135 .html('');
138 136 this.$label = $('<div />')
139 137 .addClass('widget-hlabel')
140 138 .appendTo(this.$el)
141 139 .hide();
142 140 this.$textbox = $('<input type="text" />')
143 141 .addClass('input')
144 142 .addClass('widget-text')
145 143 .appendTo(this.$el);
146 144 this.$el_to_style = this.$textbox; // Set default element to style
147 145 this.update(); // Set defaults.
148 146 },
149 147
150 148 // Handles: Backend -> Frontend Sync
151 149 // Frontent -> Frontend Sync
152 150 update: function(){
153 151 if (this.$textbox.val() != this.model.get('value')) {
154 152 this.$textbox.val(this.model.get('value'));
155 153 }
156 154
157 155 var disabled = this.model.get('disabled');
158 156 this.$textbox.prop('disabled', disabled);
159 157
160 158 var description = this.model.get('description');
161 159 if (description.length == 0) {
162 160 this.$label.hide();
163 161 } else {
164 162 this.$label.html(description);
165 163 this.$label.show();
166 164 }
167 165 return IPython.WidgetView.prototype.update.call(this);
168 166 },
169 167
170 168 events: {"keyup input": "handleChanging",
171 169 "paste input": "handleChanging",
172 170 "cut input": "handleChanging",
173 171 "keypress input": "handleKeypress"},
174 172
175 173 // Handles and validates user input.
176 174 handleChanging: function(e) {
177 175 this.model.set('value', e.target.value);
178 176 this.model.update_other_views(this);
179 177 },
180 178
181 179 // Handles text submition
182 180 handleKeypress: function(e) {
183 181 if (e.keyCode == 13) { // Return key
184 182 this.send({event: 'submit'});
185 183 }
186 184 },
187 185 });
188 186
189 187 widget_manager.register_widget_view('TextBoxView', TextBoxView);
190 188 });
General Comments 0
You need to be logged in to leave comments. Login now