Show More
@@ -14,7 +14,7 b'' | |||||
14 | }, |
|
14 | }, | |
15 | { |
|
15 | { | |
16 | "cell_type": "code", |
|
16 | "cell_type": "code", | |
17 |
"execution_count": |
|
17 | "execution_count": null, | |
18 | "metadata": { |
|
18 | "metadata": { | |
19 | "collapsed": false |
|
19 | "collapsed": false | |
20 | }, |
|
20 | }, | |
@@ -70,7 +70,7 b'' | |||||
70 | }, |
|
70 | }, | |
71 | { |
|
71 | { | |
72 | "cell_type": "code", |
|
72 | "cell_type": "code", | |
73 |
"execution_count": |
|
73 | "execution_count": null, | |
74 | "metadata": { |
|
74 | "metadata": { | |
75 | "collapsed": false |
|
75 | "collapsed": false | |
76 | }, |
|
76 | }, | |
@@ -108,27 +108,11 b'' | |||||
108 | }, |
|
108 | }, | |
109 | { |
|
109 | { | |
110 | "cell_type": "code", |
|
110 | "cell_type": "code", | |
111 |
"execution_count": |
|
111 | "execution_count": null, | |
112 | "metadata": { |
|
112 | "metadata": { | |
113 | "collapsed": false |
|
113 | "collapsed": false | |
114 | }, |
|
114 | }, | |
115 | "outputs": [ |
|
115 | "outputs": [], | |
116 | { |
|
|||
117 | "data": { |
|
|||
118 | "application/javascript": [ |
|
|||
119 | "\n", |
|
|||
120 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
|||
121 | "\n", |
|
|||
122 | "});" |
|
|||
123 | ], |
|
|||
124 | "text/plain": [ |
|
|||
125 | "<IPython.core.display.Javascript at 0x109491690>" |
|
|||
126 | ] |
|
|||
127 | }, |
|
|||
128 | "metadata": {}, |
|
|||
129 | "output_type": "display_data" |
|
|||
130 | } |
|
|||
131 | ], |
|
|||
132 | "source": [ |
|
116 | "source": [ | |
133 | "%%javascript\n", |
|
117 | "%%javascript\n", | |
134 | "\n", |
|
118 | "\n", | |
@@ -146,53 +130,30 b'' | |||||
146 | "**A render function must be defined**.\n", |
|
130 | "**A render function must be defined**.\n", | |
147 | "The render function is used to render a widget view instance to the DOM.\n", |
|
131 | "The render function is used to render a widget view instance to the DOM.\n", | |
148 | "For now, the render function renders a div that contains the text *Hello World!*\n", |
|
132 | "For now, the render function renders a div that contains the text *Hello World!*\n", | |
149 | "Lastly, the view needs to be registered with the widget manager.\n", |
|
133 | "Lastly, the view needs to be registered with the widget manager, for which we need to load another module.\n", | |
150 | "\n", |
|
134 | "\n", | |
151 | "**Final JavaScript code below:**" |
|
135 | "**Final JavaScript code below:**" | |
152 | ] |
|
136 | ] | |
153 | }, |
|
137 | }, | |
154 | { |
|
138 | { | |
155 | "cell_type": "code", |
|
139 | "cell_type": "code", | |
156 |
"execution_count": |
|
140 | "execution_count": null, | |
157 | "metadata": { |
|
141 | "metadata": { | |
158 | "collapsed": false |
|
142 | "collapsed": false | |
159 | }, |
|
143 | }, | |
160 | "outputs": [ |
|
144 | "outputs": [], | |
161 | { |
|
|||
162 | "data": { |
|
|||
163 | "application/javascript": [ |
|
|||
164 | "\n", |
|
|||
165 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
|||
166 | " \n", |
|
|||
167 | " // Define the DatePickerView\n", |
|
|||
168 | " var DatePickerView = IPython.DOMWidgetView.extend({\n", |
|
|||
169 | " render: function(){ this.$el.text('Hello World!'); },\n", |
|
|||
170 | " });\n", |
|
|||
171 | " \n", |
|
|||
172 | " // Register the DatePickerView with the widget manager.\n", |
|
|||
173 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
|||
174 | "});" |
|
|||
175 | ], |
|
|||
176 | "text/plain": [ |
|
|||
177 | "<IPython.core.display.Javascript at 0x1094917d0>" |
|
|||
178 | ] |
|
|||
179 | }, |
|
|||
180 | "metadata": {}, |
|
|||
181 | "output_type": "display_data" |
|
|||
182 | } |
|
|||
183 | ], |
|
|||
184 | "source": [ |
|
145 | "source": [ | |
185 | "%%javascript\n", |
|
146 | "%%javascript\n", | |
186 | "\n", |
|
147 | "\n", | |
187 |
"require([\"widgets/js/widget\"], function( |
|
148 | "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
188 | " \n", |
|
149 | " \n", | |
189 | " // Define the DatePickerView\n", |
|
150 | " // Define the DatePickerView\n", | |
190 |
" var DatePickerView = |
|
151 | " var DatePickerView = widget.DOMWidgetView.extend({\n", | |
191 | " render: function(){ this.$el.text('Hello World!'); },\n", |
|
152 | " render: function(){ this.$el.text('Hello World!'); },\n", | |
192 | " });\n", |
|
153 | " });\n", | |
193 | " \n", |
|
154 | " \n", | |
194 | " // Register the DatePickerView with the widget manager.\n", |
|
155 | " // Register the DatePickerView with the widget manager.\n", | |
195 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
156 | " manager.WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", | |
196 | "});" |
|
157 | "});" | |
197 | ] |
|
158 | ] | |
198 | }, |
|
159 | }, | |
@@ -212,7 +173,7 b'' | |||||
212 | }, |
|
173 | }, | |
213 | { |
|
174 | { | |
214 | "cell_type": "code", |
|
175 | "cell_type": "code", | |
215 |
"execution_count": |
|
176 | "execution_count": null, | |
216 | "metadata": { |
|
177 | "metadata": { | |
217 | "collapsed": false |
|
178 | "collapsed": false | |
218 | }, |
|
179 | }, | |
@@ -248,7 +209,7 b'' | |||||
248 | }, |
|
209 | }, | |
249 | { |
|
210 | { | |
250 | "cell_type": "code", |
|
211 | "cell_type": "code", | |
251 |
"execution_count": |
|
212 | "execution_count": null, | |
252 | "metadata": { |
|
213 | "metadata": { | |
253 | "collapsed": false |
|
214 | "collapsed": false | |
254 | }, |
|
215 | }, | |
@@ -278,47 +239,18 b'' | |||||
278 | }, |
|
239 | }, | |
279 | { |
|
240 | { | |
280 | "cell_type": "code", |
|
241 | "cell_type": "code", | |
281 |
"execution_count": |
|
242 | "execution_count": null, | |
282 | "metadata": { |
|
243 | "metadata": { | |
283 | "collapsed": false |
|
244 | "collapsed": false | |
284 | }, |
|
245 | }, | |
285 | "outputs": [ |
|
246 | "outputs": [], | |
286 | { |
|
|||
287 | "data": { |
|
|||
288 | "application/javascript": [ |
|
|||
289 | "\n", |
|
|||
290 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
|||
291 | " \n", |
|
|||
292 | " // Define the DatePickerView\n", |
|
|||
293 | " var DatePickerView = IPython.DOMWidgetView.extend({\n", |
|
|||
294 | " render: function(){\n", |
|
|||
295 | " \n", |
|
|||
296 | " // Create the date picker control.\n", |
|
|||
297 | " this.$date = $('<input />')\n", |
|
|||
298 | " .attr('type', 'date')\n", |
|
|||
299 | " .appendTo(this.$el);\n", |
|
|||
300 | " },\n", |
|
|||
301 | " });\n", |
|
|||
302 | " \n", |
|
|||
303 | " // Register the DatePickerView with the widget manager.\n", |
|
|||
304 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
|||
305 | "});" |
|
|||
306 | ], |
|
|||
307 | "text/plain": [ |
|
|||
308 | "<IPython.core.display.Javascript at 0x109491750>" |
|
|||
309 | ] |
|
|||
310 | }, |
|
|||
311 | "metadata": {}, |
|
|||
312 | "output_type": "display_data" |
|
|||
313 | } |
|
|||
314 | ], |
|
|||
315 | "source": [ |
|
247 | "source": [ | |
316 | "%%javascript\n", |
|
248 | "%%javascript\n", | |
317 | "\n", |
|
249 | "\n", | |
318 |
"require([\"widgets/js/widget\"], function( |
|
250 | "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
319 | " \n", |
|
251 | " \n", | |
320 | " // Define the DatePickerView\n", |
|
252 | " // Define the DatePickerView\n", | |
321 |
" var DatePickerView = |
|
253 | " var DatePickerView = widget.DOMWidgetView.extend({\n", | |
322 | " render: function(){\n", |
|
254 | " render: function(){\n", | |
323 | " \n", |
|
255 | " \n", | |
324 | " // Create the date picker control.\n", |
|
256 | " // Create the date picker control.\n", | |
@@ -329,7 +261,7 b'' | |||||
329 | " });\n", |
|
261 | " });\n", | |
330 | " \n", |
|
262 | " \n", | |
331 | " // Register the DatePickerView with the widget manager.\n", |
|
263 | " // Register the DatePickerView with the widget manager.\n", | |
332 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
264 | " manager.WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", | |
333 | "});" |
|
265 | "});" | |
334 | ] |
|
266 | ] | |
335 | }, |
|
267 | }, | |
@@ -342,54 +274,18 b'' | |||||
342 | }, |
|
274 | }, | |
343 | { |
|
275 | { | |
344 | "cell_type": "code", |
|
276 | "cell_type": "code", | |
345 |
"execution_count": |
|
277 | "execution_count": null, | |
346 | "metadata": { |
|
278 | "metadata": { | |
347 | "collapsed": false |
|
279 | "collapsed": false | |
348 | }, |
|
280 | }, | |
349 | "outputs": [ |
|
281 | "outputs": [], | |
350 | { |
|
|||
351 | "data": { |
|
|||
352 | "application/javascript": [ |
|
|||
353 | "\n", |
|
|||
354 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
|||
355 | " \n", |
|
|||
356 | " // Define the DatePickerView\n", |
|
|||
357 | " var DatePickerView = IPython.DOMWidgetView.extend({\n", |
|
|||
358 | " render: function(){\n", |
|
|||
359 | " \n", |
|
|||
360 | " // Create the date picker control.\n", |
|
|||
361 | " this.$date = $('<input />')\n", |
|
|||
362 | " .attr('type', 'date')\n", |
|
|||
363 | " .appendTo(this.$el);\n", |
|
|||
364 | " },\n", |
|
|||
365 | " \n", |
|
|||
366 | " update: function() {\n", |
|
|||
367 | " \n", |
|
|||
368 | " // Set the value of the date control and then call base.\n", |
|
|||
369 | " this.$date.val(this.model.get('value')); // ISO format \"YYYY-MM-DDTHH:mm:ss.sssZ\" is required\n", |
|
|||
370 | " return DatePickerView.__super__.update.apply(this);\n", |
|
|||
371 | " },\n", |
|
|||
372 | " });\n", |
|
|||
373 | " \n", |
|
|||
374 | " // Register the DatePickerView with the widget manager.\n", |
|
|||
375 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
|||
376 | "});" |
|
|||
377 | ], |
|
|||
378 | "text/plain": [ |
|
|||
379 | "<IPython.core.display.Javascript at 0x109491750>" |
|
|||
380 | ] |
|
|||
381 | }, |
|
|||
382 | "metadata": {}, |
|
|||
383 | "output_type": "display_data" |
|
|||
384 | } |
|
|||
385 | ], |
|
|||
386 | "source": [ |
|
282 | "source": [ | |
387 | "%%javascript\n", |
|
283 | "%%javascript\n", | |
388 | "\n", |
|
284 | "\n", | |
389 |
"require([\"widgets/js/widget\"], function( |
|
285 | "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
390 | " \n", |
|
286 | " \n", | |
391 | " // Define the DatePickerView\n", |
|
287 | " // Define the DatePickerView\n", | |
392 |
" var DatePickerView = |
|
288 | " var DatePickerView = widget.DOMWidgetView.extend({\n", | |
393 | " render: function(){\n", |
|
289 | " render: function(){\n", | |
394 | " \n", |
|
290 | " \n", | |
395 | " // Create the date picker control.\n", |
|
291 | " // Create the date picker control.\n", | |
@@ -407,7 +303,7 b'' | |||||
407 | " });\n", |
|
303 | " });\n", | |
408 | " \n", |
|
304 | " \n", | |
409 | " // Register the DatePickerView with the widget manager.\n", |
|
305 | " // Register the DatePickerView with the widget manager.\n", | |
410 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
306 | " manager.WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", | |
411 | "});" |
|
307 | "});" | |
412 | ] |
|
308 | ] | |
413 | }, |
|
309 | }, | |
@@ -426,65 +322,19 b'' | |||||
426 | }, |
|
322 | }, | |
427 | { |
|
323 | { | |
428 | "cell_type": "code", |
|
324 | "cell_type": "code", | |
429 |
"execution_count": |
|
325 | "execution_count": null, | |
430 | "metadata": { |
|
326 | "metadata": { | |
431 | "collapsed": false |
|
327 | "collapsed": false | |
432 | }, |
|
328 | }, | |
433 | "outputs": [ |
|
329 | "outputs": [], | |
434 | { |
|
|||
435 | "data": { |
|
|||
436 | "application/javascript": [ |
|
|||
437 | "\n", |
|
|||
438 | "\n", |
|
|||
439 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
|||
440 | " \n", |
|
|||
441 | " // Define the DatePickerView\n", |
|
|||
442 | " var DatePickerView = IPython.DOMWidgetView.extend({\n", |
|
|||
443 | " render: function(){\n", |
|
|||
444 | " \n", |
|
|||
445 | " // Create the date picker control.\n", |
|
|||
446 | " this.$date = $('<input />')\n", |
|
|||
447 | " .attr('type', 'date')\n", |
|
|||
448 | " .appendTo(this.$el);\n", |
|
|||
449 | " },\n", |
|
|||
450 | " \n", |
|
|||
451 | " update: function() {\n", |
|
|||
452 | " \n", |
|
|||
453 | " // Set the value of the date control and then call base.\n", |
|
|||
454 | " this.$date.val(this.model.get('value')); // ISO format \"YYYY-MM-DDTHH:mm:ss.sssZ\" is required\n", |
|
|||
455 | " return DatePickerView.__super__.update.apply(this);\n", |
|
|||
456 | " },\n", |
|
|||
457 | " \n", |
|
|||
458 | " // Tell Backbone to listen to the change event of input controls (which the HTML date picker is)\n", |
|
|||
459 | " events: {\"change\": \"handle_date_change\"},\n", |
|
|||
460 | " \n", |
|
|||
461 | " // Callback for when the date is changed.\n", |
|
|||
462 | " handle_date_change: function(event) {\n", |
|
|||
463 | " this.model.set('value', this.$date.val());\n", |
|
|||
464 | " this.touch();\n", |
|
|||
465 | " },\n", |
|
|||
466 | " });\n", |
|
|||
467 | " \n", |
|
|||
468 | " // Register the DatePickerView with the widget manager.\n", |
|
|||
469 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
|||
470 | "});" |
|
|||
471 | ], |
|
|||
472 | "text/plain": [ |
|
|||
473 | "<IPython.core.display.Javascript at 0x109491b10>" |
|
|||
474 | ] |
|
|||
475 | }, |
|
|||
476 | "metadata": {}, |
|
|||
477 | "output_type": "display_data" |
|
|||
478 | } |
|
|||
479 | ], |
|
|||
480 | "source": [ |
|
330 | "source": [ | |
481 | "%%javascript\n", |
|
331 | "%%javascript\n", | |
482 | "\n", |
|
332 | "\n", | |
483 | "\n", |
|
333 | "\n", | |
484 |
"require([\"widgets/js/widget\"], function( |
|
334 | "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
485 | " \n", |
|
335 | " \n", | |
486 | " // Define the DatePickerView\n", |
|
336 | " // Define the DatePickerView\n", | |
487 |
" var DatePickerView = |
|
337 | " var DatePickerView = widget.DOMWidgetView.extend({\n", | |
488 | " render: function(){\n", |
|
338 | " render: function(){\n", | |
489 | " \n", |
|
339 | " \n", | |
490 | " // Create the date picker control.\n", |
|
340 | " // Create the date picker control.\n", | |
@@ -511,7 +361,7 b'' | |||||
511 | " });\n", |
|
361 | " });\n", | |
512 | " \n", |
|
362 | " \n", | |
513 | " // Register the DatePickerView with the widget manager.\n", |
|
363 | " // Register the DatePickerView with the widget manager.\n", | |
514 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
364 | " manager.WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", | |
515 | "});" |
|
365 | "});" | |
516 | ] |
|
366 | ] | |
517 | }, |
|
367 | }, | |
@@ -531,7 +381,7 b'' | |||||
531 | }, |
|
381 | }, | |
532 | { |
|
382 | { | |
533 | "cell_type": "code", |
|
383 | "cell_type": "code", | |
534 |
"execution_count": |
|
384 | "execution_count": null, | |
535 | "metadata": { |
|
385 | "metadata": { | |
536 | "collapsed": false |
|
386 | "collapsed": false | |
537 | }, |
|
387 | }, | |
@@ -550,7 +400,7 b'' | |||||
550 | }, |
|
400 | }, | |
551 | { |
|
401 | { | |
552 | "cell_type": "code", |
|
402 | "cell_type": "code", | |
553 |
"execution_count": |
|
403 | "execution_count": null, | |
554 | "metadata": { |
|
404 | "metadata": { | |
555 | "collapsed": false |
|
405 | "collapsed": false | |
556 | }, |
|
406 | }, | |
@@ -568,22 +418,11 b'' | |||||
568 | }, |
|
418 | }, | |
569 | { |
|
419 | { | |
570 | "cell_type": "code", |
|
420 | "cell_type": "code", | |
571 |
"execution_count": |
|
421 | "execution_count": null, | |
572 | "metadata": { |
|
422 | "metadata": { | |
573 | "collapsed": false |
|
423 | "collapsed": false | |
574 | }, |
|
424 | }, | |
575 | "outputs": [ |
|
425 | "outputs": [], | |
576 | { |
|
|||
577 | "data": { |
|
|||
578 | "text/plain": [ |
|
|||
579 | "u''" |
|
|||
580 | ] |
|
|||
581 | }, |
|
|||
582 | "execution_count": 12, |
|
|||
583 | "metadata": {}, |
|
|||
584 | "output_type": "execute_result" |
|
|||
585 | } |
|
|||
586 | ], |
|
|||
587 | "source": [ |
|
426 | "source": [ | |
588 | "my_widget.value" |
|
427 | "my_widget.value" | |
589 | ] |
|
428 | ] | |
@@ -597,7 +436,7 b'' | |||||
597 | }, |
|
436 | }, | |
598 | { |
|
437 | { | |
599 | "cell_type": "code", |
|
438 | "cell_type": "code", | |
600 |
"execution_count": |
|
439 | "execution_count": null, | |
601 | "metadata": { |
|
440 | "metadata": { | |
602 | "collapsed": false |
|
441 | "collapsed": false | |
603 | }, |
|
442 | }, | |
@@ -622,7 +461,7 b'' | |||||
622 | }, |
|
461 | }, | |
623 | { |
|
462 | { | |
624 | "cell_type": "code", |
|
463 | "cell_type": "code", | |
625 |
"execution_count": |
|
464 | "execution_count": null, | |
626 | "metadata": { |
|
465 | "metadata": { | |
627 | "collapsed": false |
|
466 | "collapsed": false | |
628 | }, |
|
467 | }, | |
@@ -659,7 +498,7 b'' | |||||
659 | }, |
|
498 | }, | |
660 | { |
|
499 | { | |
661 | "cell_type": "code", |
|
500 | "cell_type": "code", | |
662 |
"execution_count": |
|
501 | "execution_count": null, | |
663 | "metadata": { |
|
502 | "metadata": { | |
664 | "collapsed": false |
|
503 | "collapsed": false | |
665 | }, |
|
504 | }, | |
@@ -682,7 +521,7 b'' | |||||
682 | }, |
|
521 | }, | |
683 | { |
|
522 | { | |
684 | "cell_type": "code", |
|
523 | "cell_type": "code", | |
685 |
"execution_count": |
|
524 | "execution_count": null, | |
686 | "metadata": { |
|
525 | "metadata": { | |
687 | "collapsed": false |
|
526 | "collapsed": false | |
688 | }, |
|
527 | }, | |
@@ -709,7 +548,7 b'' | |||||
709 | }, |
|
548 | }, | |
710 | { |
|
549 | { | |
711 | "cell_type": "code", |
|
550 | "cell_type": "code", | |
712 |
"execution_count": |
|
551 | "execution_count": null, | |
713 | "metadata": { |
|
552 | "metadata": { | |
714 | "collapsed": false |
|
553 | "collapsed": false | |
715 | }, |
|
554 | }, | |
@@ -749,7 +588,7 b'' | |||||
749 | }, |
|
588 | }, | |
750 | { |
|
589 | { | |
751 | "cell_type": "code", |
|
590 | "cell_type": "code", | |
752 |
"execution_count": |
|
591 | "execution_count": null, | |
753 | "metadata": { |
|
592 | "metadata": { | |
754 | "collapsed": false |
|
593 | "collapsed": false | |
755 | }, |
|
594 | }, | |
@@ -811,80 +650,18 b'' | |||||
811 | }, |
|
650 | }, | |
812 | { |
|
651 | { | |
813 | "cell_type": "code", |
|
652 | "cell_type": "code", | |
814 |
"execution_count": |
|
653 | "execution_count": null, | |
815 | "metadata": { |
|
654 | "metadata": { | |
816 | "collapsed": false |
|
655 | "collapsed": false | |
817 | }, |
|
656 | }, | |
818 | "outputs": [ |
|
657 | "outputs": [], | |
819 | { |
|
|||
820 | "data": { |
|
|||
821 | "application/javascript": [ |
|
|||
822 | "\n", |
|
|||
823 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
|||
824 | " \n", |
|
|||
825 | " // Define the DatePickerView\n", |
|
|||
826 | " var DatePickerView = IPython.DOMWidgetView.extend({\n", |
|
|||
827 | " render: function(){\n", |
|
|||
828 | " this.$el.addClass('widget-hbox-single'); /* Apply this class to the widget container to make\n", |
|
|||
829 | " it fit with the other built in widgets.*/\n", |
|
|||
830 | " // Create a label.\n", |
|
|||
831 | " this.$label = $('<div />')\n", |
|
|||
832 | " .addClass('widget-hlabel')\n", |
|
|||
833 | " .appendTo(this.$el)\n", |
|
|||
834 | " .hide(); // Hide the label by default.\n", |
|
|||
835 | " \n", |
|
|||
836 | " // Create the date picker control.\n", |
|
|||
837 | " this.$date = $('<input />')\n", |
|
|||
838 | " .attr('type', 'date')\n", |
|
|||
839 | " .appendTo(this.$el);\n", |
|
|||
840 | " },\n", |
|
|||
841 | " \n", |
|
|||
842 | " update: function() {\n", |
|
|||
843 | " \n", |
|
|||
844 | " // Set the value of the date control and then call base.\n", |
|
|||
845 | " this.$date.val(this.model.get('value')); // ISO format \"YYYY-MM-DDTHH:mm:ss.sssZ\" is required\n", |
|
|||
846 | " \n", |
|
|||
847 | " // Hide or show the label depending on the existance of a description.\n", |
|
|||
848 | " var description = this.model.get('description');\n", |
|
|||
849 | " if (description == undefined || description == '') {\n", |
|
|||
850 | " this.$label.hide();\n", |
|
|||
851 | " } else {\n", |
|
|||
852 | " this.$label.show();\n", |
|
|||
853 | " this.$label.text(description);\n", |
|
|||
854 | " }\n", |
|
|||
855 | " \n", |
|
|||
856 | " return DatePickerView.__super__.update.apply(this);\n", |
|
|||
857 | " },\n", |
|
|||
858 | " \n", |
|
|||
859 | " // Tell Backbone to listen to the change event of input controls (which the HTML date picker is)\n", |
|
|||
860 | " events: {\"change\": \"handle_date_change\"},\n", |
|
|||
861 | " \n", |
|
|||
862 | " // Callback for when the date is changed.\n", |
|
|||
863 | " handle_date_change: function(event) {\n", |
|
|||
864 | " this.model.set('value', this.$date.val());\n", |
|
|||
865 | " this.touch();\n", |
|
|||
866 | " },\n", |
|
|||
867 | " });\n", |
|
|||
868 | " \n", |
|
|||
869 | " // Register the DatePickerView with the widget manager.\n", |
|
|||
870 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
|||
871 | "});" |
|
|||
872 | ], |
|
|||
873 | "text/plain": [ |
|
|||
874 | "<IPython.core.display.Javascript at 0x1094eef90>" |
|
|||
875 | ] |
|
|||
876 | }, |
|
|||
877 | "metadata": {}, |
|
|||
878 | "output_type": "display_data" |
|
|||
879 | } |
|
|||
880 | ], |
|
|||
881 | "source": [ |
|
658 | "source": [ | |
882 | "%%javascript\n", |
|
659 | "%%javascript\n", | |
883 | "\n", |
|
660 | "\n", | |
884 |
"require([\"widgets/js/widget\"], function( |
|
661 | "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
885 | " \n", |
|
662 | " \n", | |
886 | " // Define the DatePickerView\n", |
|
663 | " // Define the DatePickerView\n", | |
887 |
" var DatePickerView = |
|
664 | " var DatePickerView = widget.DOMWidgetView.extend({\n", | |
888 | " render: function(){\n", |
|
665 | " render: function(){\n", | |
889 | " this.$el.addClass('widget-hbox-single'); /* Apply this class to the widget container to make\n", |
|
666 | " this.$el.addClass('widget-hbox-single'); /* Apply this class to the widget container to make\n", | |
890 | " it fit with the other built in widgets.*/\n", |
|
667 | " it fit with the other built in widgets.*/\n", | |
@@ -928,7 +705,7 b'' | |||||
928 | " });\n", |
|
705 | " });\n", | |
929 | " \n", |
|
706 | " \n", | |
930 | " // Register the DatePickerView with the widget manager.\n", |
|
707 | " // Register the DatePickerView with the widget manager.\n", | |
931 | " WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", |
|
708 | " manager.WidgetManager.register_widget_view('DatePickerView', DatePickerView);\n", | |
932 | "});" |
|
709 | "});" | |
933 | ] |
|
710 | ] | |
934 | }, |
|
711 | }, | |
@@ -948,15 +725,15 b'' | |||||
948 | }, |
|
725 | }, | |
949 | { |
|
726 | { | |
950 | "cell_type": "code", |
|
727 | "cell_type": "code", | |
951 |
"execution_count": |
|
728 | "execution_count": null, | |
952 | "metadata": { |
|
729 | "metadata": { | |
953 | "collapsed": false |
|
730 | "collapsed": false | |
954 | }, |
|
731 | }, | |
955 | "outputs": [], |
|
732 | "outputs": [], | |
956 | "source": [ |
|
733 | "source": [ | |
957 | "# Add some additional widgets for aesthetic purpose\n", |
|
734 | "# Add some additional widgets for aesthetic purpose\n", | |
958 |
"display(widgets.Text |
|
735 | "display(widgets.Text(description=\"First:\"))\n", | |
959 |
"display(widgets.Text |
|
736 | "display(widgets.Text(description=\"Last:\"))\n", | |
960 | "\n", |
|
737 | "\n", | |
961 | "my_widget = DateWidget()\n", |
|
738 | "my_widget = DateWidget()\n", | |
962 | "display(my_widget)\n", |
|
739 | "display(my_widget)\n", | |
@@ -972,7 +749,7 b'' | |||||
972 | }, |
|
749 | }, | |
973 | { |
|
750 | { | |
974 | "cell_type": "code", |
|
751 | "cell_type": "code", | |
975 |
"execution_count": |
|
752 | "execution_count": null, | |
976 | "metadata": { |
|
753 | "metadata": { | |
977 | "collapsed": false |
|
754 | "collapsed": false | |
978 | }, |
|
755 | }, | |
@@ -988,7 +765,7 b'' | |||||
988 | }, |
|
765 | }, | |
989 | { |
|
766 | { | |
990 | "cell_type": "code", |
|
767 | "cell_type": "code", | |
991 |
"execution_count": |
|
768 | "execution_count": null, | |
992 | "metadata": { |
|
769 | "metadata": { | |
993 | "collapsed": false |
|
770 | "collapsed": false | |
994 | }, |
|
771 | }, | |
@@ -1000,7 +777,7 b'' | |||||
1000 | }, |
|
777 | }, | |
1001 | { |
|
778 | { | |
1002 | "cell_type": "code", |
|
779 | "cell_type": "code", | |
1003 |
"execution_count": |
|
780 | "execution_count": null, | |
1004 | "metadata": { |
|
781 | "metadata": { | |
1005 | "collapsed": false |
|
782 | "collapsed": false | |
1006 | }, |
|
783 | }, | |
@@ -1012,25 +789,23 b'' | |||||
1012 | }, |
|
789 | }, | |
1013 | { |
|
790 | { | |
1014 | "cell_type": "code", |
|
791 | "cell_type": "code", | |
1015 |
"execution_count": |
|
792 | "execution_count": null, | |
1016 | "metadata": { |
|
793 | "metadata": { | |
1017 | "collapsed": false |
|
794 | "collapsed": false | |
1018 | }, |
|
795 | }, | |
1019 | "outputs": [ |
|
796 | "outputs": [], | |
1020 | { |
|
|||
1021 | "data": { |
|
|||
1022 | "text/plain": [ |
|
|||
1023 | "u'2014-12-02'" |
|
|||
1024 | ] |
|
|||
1025 | }, |
|
|||
1026 | "execution_count": 24, |
|
|||
1027 | "metadata": {}, |
|
|||
1028 | "output_type": "execute_result" |
|
|||
1029 | } |
|
|||
1030 | ], |
|
|||
1031 | "source": [ |
|
797 | "source": [ | |
1032 | "my_widget.value" |
|
798 | "my_widget.value" | |
1033 | ] |
|
799 | ] | |
|
800 | }, | |||
|
801 | { | |||
|
802 | "cell_type": "code", | |||
|
803 | "execution_count": null, | |||
|
804 | "metadata": { | |||
|
805 | "collapsed": true | |||
|
806 | }, | |||
|
807 | "outputs": [], | |||
|
808 | "source": [] | |||
1034 | } |
|
809 | } | |
1035 | ], |
|
810 | ], | |
1036 | "metadata": { |
|
811 | "metadata": { | |
@@ -1039,8 +814,24 b'' | |||||
1039 | "<None>", |
|
814 | "<None>", | |
1040 | null |
|
815 | null | |
1041 | ] |
|
816 | ] | |
1042 | ] |
|
817 | ], | |
|
818 | "kernelspec": { | |||
|
819 | "display_name": "Python 3", | |||
|
820 | "name": "python3" | |||
|
821 | }, | |||
|
822 | "language_info": { | |||
|
823 | "codemirror_mode": { | |||
|
824 | "name": "ipython", | |||
|
825 | "version": 3 | |||
|
826 | }, | |||
|
827 | "file_extension": ".py", | |||
|
828 | "mimetype": "text/x-python", | |||
|
829 | "name": "python", | |||
|
830 | "nbconvert_exporter": "python", | |||
|
831 | "pygments_lexer": "ipython3", | |||
|
832 | "version": "3.4.2" | |||
|
833 | } | |||
1043 | }, |
|
834 | }, | |
1044 | "nbformat": 4, |
|
835 | "nbformat": 4, | |
1045 | "nbformat_minor": 0 |
|
836 | "nbformat_minor": 0 | |
1046 | } No newline at end of file |
|
837 | } |
General Comments 0
You need to be logged in to leave comments.
Login now