Show More
@@ -49,17 +49,18 define([ | |||||
49 |
|
49 | |||
50 | /** |
|
50 | /** | |
51 | * Contains and manages cells. |
|
51 | * Contains and manages cells. | |
|
52 | * | |||
52 | * @class Notebook |
|
53 | * @class Notebook | |
53 | * @param {string} selector |
|
54 | * @param {string} selector | |
54 |
* @param { |
|
55 | * @param {object} options - Dictionary of keyword arguments. | |
55 | * events: $(Events) instance |
|
56 | * @param {jQuery} options.events - selector of Events | |
56 | * keyboard_manager: KeyboardManager instance |
|
57 | * @param {KeyboardManager} options.keyboard_manager | |
57 | * contents: Contents instance |
|
58 | * @param {Contents} options.contents | |
58 | * save_widget: SaveWidget instance |
|
59 | * @param {SaveWidget} options.save_widget | |
59 | * config: dictionary |
|
60 | * @param {object} options.config | |
60 | * base_url : string |
|
61 | * @param {string} options.base_url | |
61 | * notebook_path : string |
|
62 | * @param {string} options.notebook_path | |
62 | * notebook_name : string |
|
63 | * @param {string} options.notebook_name | |
63 | */ |
|
64 | */ | |
64 | var Notebook = function (selector, options) { |
|
65 | var Notebook = function (selector, options) { | |
65 | this.config = utils.mergeopt(Notebook, options.config); |
|
66 | this.config = utils.mergeopt(Notebook, options.config); | |
@@ -354,16 +355,16 define([ | |||||
354 | /** |
|
355 | /** | |
355 | * Scroll the top of the page to a given cell. |
|
356 | * Scroll the top of the page to a given cell. | |
356 | * |
|
357 | * | |
357 |
* @param { |
|
358 | * @param {integer} index - An index of the cell to view | |
358 |
* @param { |
|
359 | * @param {integer} time - Animation time in milliseconds | |
359 |
* @return { |
|
360 | * @return {integer} Pixel offset from the top of the container | |
360 | */ |
|
361 | */ | |
361 |
Notebook.prototype.scroll_to_cell = function ( |
|
362 | Notebook.prototype.scroll_to_cell = function (index, time) { | |
362 | var cells = this.get_cells(); |
|
363 | var cells = this.get_cells(); | |
363 | time = time || 0; |
|
364 | time = time || 0; | |
364 |
|
|
365 | index = Math.min(cells.length-1,index); | |
365 |
|
|
366 | index = Math.max(0 ,index); | |
366 |
var scroll_value = cells[ |
|
367 | var scroll_value = cells[index].element.position().top-cells[0].element.position().top ; | |
367 | this.element.animate({scrollTop:scroll_value}, time); |
|
368 | this.element.animate({scrollTop:scroll_value}, time); | |
368 | return scroll_value; |
|
369 | return scroll_value; | |
369 | }; |
|
370 | }; | |
@@ -386,7 +387,6 define([ | |||||
386 |
|
387 | |||
387 | /** |
|
388 | /** | |
388 | * Display a dialog that allows the user to edit the Notebook's metadata. |
|
389 | * Display a dialog that allows the user to edit the Notebook's metadata. | |
389 | * @return {null} |
|
|||
390 | */ |
|
390 | */ | |
391 | Notebook.prototype.edit_metadata = function () { |
|
391 | Notebook.prototype.edit_metadata = function () { | |
392 | var that = this; |
|
392 | var that = this; | |
@@ -414,7 +414,7 define([ | |||||
414 | /** |
|
414 | /** | |
415 | * Get a particular cell element. |
|
415 | * Get a particular cell element. | |
416 | * |
|
416 | * | |
417 |
* @param { |
|
417 | * @param {integer} index An index of a cell to select | |
418 | * @return {jQuery} A selector of the given cell. |
|
418 | * @return {jQuery} A selector of the given cell. | |
419 | */ |
|
419 | */ | |
420 | Notebook.prototype.get_cell_element = function (index) { |
|
420 | Notebook.prototype.get_cell_element = function (index) { | |
@@ -439,7 +439,7 define([ | |||||
439 | /** |
|
439 | /** | |
440 | * Count the cells in this notebook. |
|
440 | * Count the cells in this notebook. | |
441 | * |
|
441 | * | |
442 |
* @return { |
|
442 | * @return {integer} The number of cells in this notebook | |
443 | */ |
|
443 | */ | |
444 | Notebook.prototype.ncells = function () { |
|
444 | Notebook.prototype.ncells = function () { | |
445 | return this.get_cell_elements().length; |
|
445 | return this.get_cell_elements().length; | |
@@ -459,9 +459,9 define([ | |||||
459 | }; |
|
459 | }; | |
460 |
|
460 | |||
461 | /** |
|
461 | /** | |
462 | * Get a Cell object from this notebook. |
|
462 | * Get a Cell objects from this notebook. | |
463 | * |
|
463 | * | |
464 |
* @param { |
|
464 | * @param {integer} index - An index of a cell to retrieve | |
465 | * @return {Cell} Cell or null if no cell was found. |
|
465 | * @return {Cell} Cell or null if no cell was found. | |
466 | */ |
|
466 | */ | |
467 | Notebook.prototype.get_cell = function (index) { |
|
467 | Notebook.prototype.get_cell = function (index) { | |
@@ -476,7 +476,7 define([ | |||||
476 | /** |
|
476 | /** | |
477 | * Get the cell below a given cell. |
|
477 | * Get the cell below a given cell. | |
478 | * |
|
478 | * | |
479 |
* @param {Cell} cell |
|
479 | * @param {Cell} cell | |
480 | * @return {Cell} the next cell or null if no cell was found. |
|
480 | * @return {Cell} the next cell or null if no cell was found. | |
481 | */ |
|
481 | */ | |
482 | Notebook.prototype.get_next_cell = function (cell) { |
|
482 | Notebook.prototype.get_next_cell = function (cell) { | |
@@ -491,7 +491,7 define([ | |||||
491 | /** |
|
491 | /** | |
492 | * Get the cell above a given cell. |
|
492 | * Get the cell above a given cell. | |
493 | * |
|
493 | * | |
494 |
* @param {Cell} cell |
|
494 | * @param {Cell} cell | |
495 | * @return {Cell} The previous cell or null if no cell was found. |
|
495 | * @return {Cell} The previous cell or null if no cell was found. | |
496 | */ |
|
496 | */ | |
497 | Notebook.prototype.get_prev_cell = function (cell) { |
|
497 | Notebook.prototype.get_prev_cell = function (cell) { | |
@@ -506,8 +506,8 define([ | |||||
506 | /** |
|
506 | /** | |
507 | * Get the numeric index of a given cell. |
|
507 | * Get the numeric index of a given cell. | |
508 | * |
|
508 | * | |
509 |
* @param {Cell} cell |
|
509 | * @param {Cell} cell | |
510 |
* @return { |
|
510 | * @return {integer} The cell's numeric index or null if no cell was found. | |
511 | */ |
|
511 | */ | |
512 | Notebook.prototype.find_cell_index = function (cell) { |
|
512 | Notebook.prototype.find_cell_index = function (cell) { | |
513 | var result = null; |
|
513 | var result = null; | |
@@ -520,10 +520,10 define([ | |||||
520 | }; |
|
520 | }; | |
521 |
|
521 | |||
522 | /** |
|
522 | /** | |
523 |
* |
|
523 | * Return given index if defined, or the selected index if not. | |
524 | * |
|
524 | * | |
525 |
* @param { |
|
525 | * @param {integer} [index] - A cell's index | |
526 | * @return {number} The given index, or selected index if none is provided. |
|
526 | * @return {integer} cell index | |
527 | */ |
|
527 | */ | |
528 | Notebook.prototype.index_or_selected = function (index) { |
|
528 | Notebook.prototype.index_or_selected = function (index) { | |
529 | var i; |
|
529 | var i; | |
@@ -540,6 +540,7 define([ | |||||
540 |
|
540 | |||
541 | /** |
|
541 | /** | |
542 | * Get the currently selected cell. |
|
542 | * Get the currently selected cell. | |
|
543 | * | |||
543 | * @return {Cell} The selected cell |
|
544 | * @return {Cell} The selected cell | |
544 | */ |
|
545 | */ | |
545 | Notebook.prototype.get_selected_cell = function () { |
|
546 | Notebook.prototype.get_selected_cell = function () { | |
@@ -550,7 +551,7 define([ | |||||
550 | /** |
|
551 | /** | |
551 | * Check whether a cell index is valid. |
|
552 | * Check whether a cell index is valid. | |
552 | * |
|
553 | * | |
553 |
* @param { |
|
554 | * @param {integer} index - A cell index | |
554 | * @return True if the index is valid, false otherwise |
|
555 | * @return True if the index is valid, false otherwise | |
555 | */ |
|
556 | */ | |
556 | Notebook.prototype.is_valid_cell_index = function (index) { |
|
557 | Notebook.prototype.is_valid_cell_index = function (index) { | |
@@ -563,8 +564,8 define([ | |||||
563 |
|
564 | |||
564 | /** |
|
565 | /** | |
565 | * Get the index of the currently selected cell. |
|
566 | * Get the index of the currently selected cell. | |
566 |
|
567 | * | ||
567 |
* @return { |
|
568 | * @return {integer} The selected cell's numeric index | |
568 | */ |
|
569 | */ | |
569 | Notebook.prototype.get_selected_index = function () { |
|
570 | Notebook.prototype.get_selected_index = function () { | |
570 | var result = null; |
|
571 | var result = null; | |
@@ -582,7 +583,7 define([ | |||||
582 | /** |
|
583 | /** | |
583 | * Programmatically select a cell. |
|
584 | * Programmatically select a cell. | |
584 | * |
|
585 | * | |
585 |
* @param { |
|
586 | * @param {integer} index - A cell's index | |
586 | * @return {Notebook} This notebook |
|
587 | * @return {Notebook} This notebook | |
587 | */ |
|
588 | */ | |
588 | Notebook.prototype.select = function (index) { |
|
589 | Notebook.prototype.select = function (index) { | |
@@ -639,8 +640,8 define([ | |||||
639 | /** |
|
640 | /** | |
640 | * Gets the index of the cell that is in edit mode. |
|
641 | * Gets the index of the cell that is in edit mode. | |
641 | * |
|
642 | * | |
642 |
* @return |
|
643 | * @return {integer} index | |
643 |
* |
|
644 | */ | |
644 | Notebook.prototype.get_edit_index = function () { |
|
645 | Notebook.prototype.get_edit_index = function () { | |
645 | var result = null; |
|
646 | var result = null; | |
646 | this.get_cell_elements().filter(function (index) { |
|
647 | this.get_cell_elements().filter(function (index) { | |
@@ -654,8 +655,8 define([ | |||||
654 | /** |
|
655 | /** | |
655 | * Handle when a a cell blurs and the notebook should enter command mode. |
|
656 | * Handle when a a cell blurs and the notebook should enter command mode. | |
656 | * |
|
657 | * | |
657 | * @param {Cell} [cell] Cell to enter command mode on. |
|
658 | * @param {Cell} [cell] - Cell to enter command mode on. | |
658 |
* |
|
659 | */ | |
659 | Notebook.prototype.handle_command_mode = function (cell) { |
|
660 | Notebook.prototype.handle_command_mode = function (cell) { | |
660 | if (this.mode !== 'command') { |
|
661 | if (this.mode !== 'command') { | |
661 | cell.command_mode(); |
|
662 | cell.command_mode(); | |
@@ -667,7 +668,7 define([ | |||||
667 |
|
668 | |||
668 | /** |
|
669 | /** | |
669 | * Make the notebook enter command mode. |
|
670 | * Make the notebook enter command mode. | |
670 |
* |
|
671 | */ | |
671 | Notebook.prototype.command_mode = function () { |
|
672 | Notebook.prototype.command_mode = function () { | |
672 | var cell = this.get_cell(this.get_edit_index()); |
|
673 | var cell = this.get_cell(this.get_edit_index()); | |
673 | if (cell && this.mode !== 'command') { |
|
674 | if (cell && this.mode !== 'command') { | |
@@ -682,7 +683,7 define([ | |||||
682 | * Handle when a cell fires it's edit_mode event. |
|
683 | * Handle when a cell fires it's edit_mode event. | |
683 | * |
|
684 | * | |
684 | * @param {Cell} [cell] Cell to enter edit mode on. |
|
685 | * @param {Cell} [cell] Cell to enter edit mode on. | |
685 |
* |
|
686 | */ | |
686 | Notebook.prototype.handle_edit_mode = function (cell) { |
|
687 | Notebook.prototype.handle_edit_mode = function (cell) { | |
687 | if (cell && this.mode !== 'edit') { |
|
688 | if (cell && this.mode !== 'edit') { | |
688 | cell.edit_mode(); |
|
689 | cell.edit_mode(); | |
@@ -694,7 +695,7 define([ | |||||
694 |
|
695 | |||
695 | /** |
|
696 | /** | |
696 | * Make a cell enter edit mode. |
|
697 | * Make a cell enter edit mode. | |
697 |
* |
|
698 | */ | |
698 | Notebook.prototype.edit_mode = function () { |
|
699 | Notebook.prototype.edit_mode = function () { | |
699 | var cell = this.get_selected_cell(); |
|
700 | var cell = this.get_selected_cell(); | |
700 | if (cell && this.mode !== 'edit') { |
|
701 | if (cell && this.mode !== 'edit') { | |
@@ -705,7 +706,7 define([ | |||||
705 |
|
706 | |||
706 | /** |
|
707 | /** | |
707 | * Focus the currently selected cell. |
|
708 | * Focus the currently selected cell. | |
708 |
* |
|
709 | */ | |
709 | Notebook.prototype.focus_cell = function () { |
|
710 | Notebook.prototype.focus_cell = function () { | |
710 | var cell = this.get_selected_cell(); |
|
711 | var cell = this.get_selected_cell(); | |
711 | if (cell === null) {return;} // No cell is selected |
|
712 | if (cell === null) {return;} // No cell is selected | |
@@ -717,9 +718,9 define([ | |||||
717 | /** |
|
718 | /** | |
718 | * Move given (or selected) cell up and select it. |
|
719 | * Move given (or selected) cell up and select it. | |
719 | * |
|
720 | * | |
720 | * @param {integer} [index] cell index |
|
721 | * @param {integer} [index] - cell index | |
721 | * @return {Notebook} This notebook |
|
722 | * @return {Notebook} This notebook | |
722 |
* |
|
723 | */ | |
723 | Notebook.prototype.move_cell_up = function (index) { |
|
724 | Notebook.prototype.move_cell_up = function (index) { | |
724 | var i = this.index_or_selected(index); |
|
725 | var i = this.index_or_selected(index); | |
725 | if (this.is_valid_cell_index(i) && i > 0) { |
|
726 | if (this.is_valid_cell_index(i) && i > 0) { | |
@@ -739,11 +740,11 define([ | |||||
739 |
|
740 | |||
740 |
|
741 | |||
741 | /** |
|
742 | /** | |
742 | * Move given (or selected) cell down and select it |
|
743 | * Move given (or selected) cell down and select it. | |
743 | * |
|
744 | * | |
744 | * @param {integer} [index] cell index |
|
745 | * @param {integer} [index] - cell index | |
745 | * @return {Notebook} This notebook |
|
746 | * @return {Notebook} This notebook | |
746 |
* |
|
747 | */ | |
747 | Notebook.prototype.move_cell_down = function (index) { |
|
748 | Notebook.prototype.move_cell_down = function (index) { | |
748 | var i = this.index_or_selected(index); |
|
749 | var i = this.index_or_selected(index); | |
749 | if (this.is_valid_cell_index(i) && this.is_valid_cell_index(i+1)) { |
|
750 | if (this.is_valid_cell_index(i) && this.is_valid_cell_index(i+1)) { | |
@@ -767,7 +768,7 define([ | |||||
767 | /** |
|
768 | /** | |
768 | * Delete a cell from the notebook. |
|
769 | * Delete a cell from the notebook. | |
769 | * |
|
770 | * | |
770 | * @param {integer} [index] cell's numeric index |
|
771 | * @param {integer} [index] - cell's numeric index | |
771 | * @return {Notebook} This notebook |
|
772 | * @return {Notebook} This notebook | |
772 | */ |
|
773 | */ | |
773 | Notebook.prototype.delete_cell = function (index) { |
|
774 | Notebook.prototype.delete_cell = function (index) { | |
@@ -846,15 +847,14 define([ | |||||
846 | * If cell type is not provided, it will default to the type of the |
|
847 | * If cell type is not provided, it will default to the type of the | |
847 | * currently active cell. |
|
848 | * currently active cell. | |
848 | * |
|
849 | * | |
849 | * Similar to insert_above, but index parameter is mandatory |
|
850 | * Similar to insert_above, but index parameter is mandatory. | |
850 | * |
|
|||
851 | * Index will be brought back into the accessible range [0,n] |
|
|||
852 | * |
|
851 | * | |
853 | * @param {string} [type] in ['code','markdown', 'raw'], defaults to 'code' |
|
852 | * Index will be brought back into the accessible range [0,n]. | |
854 | * @param {integer} [index] a valid index where to insert cell |
|
|||
855 | * |
|
853 | * | |
|
854 | * @param {string} [type] - in ['code','markdown', 'raw'], defaults to 'code' | |||
|
855 | * @param {integer} [index] - a valid index where to insert cell | |||
856 | * @return {Cell|null} created cell or null |
|
856 | * @return {Cell|null} created cell or null | |
857 |
* |
|
857 | */ | |
858 | Notebook.prototype.insert_cell_at_index = function(type, index){ |
|
858 | Notebook.prototype.insert_cell_at_index = function(type, index){ | |
859 |
|
859 | |||
860 | var ncells = this.ncells(); |
|
860 | var ncells = this.ncells(); | |
@@ -919,11 +919,11 define([ | |||||
919 |
|
919 | |||
920 | /** |
|
920 | /** | |
921 | * Insert an element at given cell index. |
|
921 | * Insert an element at given cell index. | |
922 | * return true if everything whent fine. |
|
|||
923 | * |
|
922 | * | |
924 | * @param {HTMLElement} element - a cell element |
|
923 | * @param {HTMLElement} element - a cell element | |
925 | * @param {integer} [index] a valid index where to inser cell |
|
924 | * @param {integer} [index] - a valid index where to inser cell | |
926 | **/ |
|
925 | * @returns {boolean} success | |
|
926 | */ | |||
927 | Notebook.prototype._insert_element_at_index = function(element, index){ |
|
927 | Notebook.prototype._insert_element_at_index = function(element, index){ | |
928 | if (element === undefined){ |
|
928 | if (element === undefined){ | |
929 | return false; |
|
929 | return false; | |
@@ -955,13 +955,10 define([ | |||||
955 | * Insert a cell of given type above given index, or at top |
|
955 | * Insert a cell of given type above given index, or at top | |
956 | * of notebook if index smaller than 0. |
|
956 | * of notebook if index smaller than 0. | |
957 | * |
|
957 | * | |
958 | * default index value is the one of currently selected cell |
|
958 | * @param {string} [type] - cell type | |
959 | * |
|
959 | * @param {integer} [index] - defaults to the currently selected cell | |
960 | * @param {string} [type] cell type |
|
|||
961 | * @param {integer} [index] |
|
|||
962 | * |
|
|||
963 | * @return {Cell|null} handle to created cell or null |
|
960 | * @return {Cell|null} handle to created cell or null | |
964 |
* |
|
961 | */ | |
965 | Notebook.prototype.insert_cell_above = function (type, index) { |
|
962 | Notebook.prototype.insert_cell_above = function (type, index) { | |
966 | index = this.index_or_selected(index); |
|
963 | index = this.index_or_selected(index); | |
967 | return this.insert_cell_at_index(type, index); |
|
964 | return this.insert_cell_at_index(type, index); | |
@@ -971,13 +968,10 define([ | |||||
971 | * Insert a cell of given type below given index, or at bottom |
|
968 | * Insert a cell of given type below given index, or at bottom | |
972 | * of notebook if index greater than number of cells |
|
969 | * of notebook if index greater than number of cells | |
973 | * |
|
970 | * | |
974 | * default index value is the one of currently selected cell |
|
971 | * @param {string} [type] - cell type | |
975 | * |
|
972 | * @param {integer} [index] - defaults to the currently selected cell | |
976 | * @param {string} [type] cell type |
|
|||
977 | * @param {integer} [index] |
|
|||
978 | * |
|
|||
979 | * @return {Cell|null} handle to created cell or null |
|
973 | * @return {Cell|null} handle to created cell or null | |
980 |
* |
|
974 | */ | |
981 | Notebook.prototype.insert_cell_below = function (type, index) { |
|
975 | Notebook.prototype.insert_cell_below = function (type, index) { | |
982 | index = this.index_or_selected(index); |
|
976 | index = this.index_or_selected(index); | |
983 | return this.insert_cell_at_index(type, index+1); |
|
977 | return this.insert_cell_at_index(type, index+1); | |
@@ -987,10 +981,9 define([ | |||||
987 | /** |
|
981 | /** | |
988 | * Insert cell at end of notebook |
|
982 | * Insert cell at end of notebook | |
989 | * |
|
983 | * | |
990 | * @param {string} type cell type |
|
984 | * @param {string} type - cell type | |
991 | * |
|
985 | * @return {Cell|null} handle to created cell or null | |
992 | * @return {Cell|null} the added cell; or null |
|
986 | */ | |
993 | **/ |
|
|||
994 | Notebook.prototype.insert_cell_at_bottom = function (type){ |
|
987 | Notebook.prototype.insert_cell_at_bottom = function (type){ | |
995 | var len = this.ncells(); |
|
988 | var len = this.ncells(); | |
996 | return this.insert_cell_below(type,len-1); |
|
989 | return this.insert_cell_below(type,len-1); | |
@@ -999,7 +992,7 define([ | |||||
999 | /** |
|
992 | /** | |
1000 | * Turn a cell into a code cell. |
|
993 | * Turn a cell into a code cell. | |
1001 | * |
|
994 | * | |
1002 |
* @param { |
|
995 | * @param {integer} [index] - cell index | |
1003 | */ |
|
996 | */ | |
1004 | Notebook.prototype.to_code = function (index) { |
|
997 | Notebook.prototype.to_code = function (index) { | |
1005 | var i = this.index_or_selected(index); |
|
998 | var i = this.index_or_selected(index); | |
@@ -1030,7 +1023,7 define([ | |||||
1030 | /** |
|
1023 | /** | |
1031 | * Turn a cell into a Markdown cell. |
|
1024 | * Turn a cell into a Markdown cell. | |
1032 | * |
|
1025 | * | |
1033 |
* @param { |
|
1026 | * @param {integer} [index] - cell index | |
1034 | */ |
|
1027 | */ | |
1035 | Notebook.prototype.to_markdown = function (index) { |
|
1028 | Notebook.prototype.to_markdown = function (index) { | |
1036 | var i = this.index_or_selected(index); |
|
1029 | var i = this.index_or_selected(index); | |
@@ -1067,7 +1060,7 define([ | |||||
1067 | /** |
|
1060 | /** | |
1068 | * Turn a cell into a raw text cell. |
|
1061 | * Turn a cell into a raw text cell. | |
1069 | * |
|
1062 | * | |
1070 |
* @param { |
|
1063 | * @param {integer} [index] - cell index | |
1071 | */ |
|
1064 | */ | |
1072 | Notebook.prototype.to_raw = function (index) { |
|
1065 | Notebook.prototype.to_raw = function (index) { | |
1073 | var i = this.index_or_selected(index); |
|
1066 | var i = this.index_or_selected(index); | |
@@ -1099,7 +1092,7 define([ | |||||
1099 | }; |
|
1092 | }; | |
1100 |
|
1093 | |||
1101 | /** |
|
1094 | /** | |
1102 |
* |
|
1095 | * Warn about heading cell support removal. | |
1103 | */ |
|
1096 | */ | |
1104 | Notebook.prototype._warn_heading = function () { |
|
1097 | Notebook.prototype._warn_heading = function () { | |
1105 | dialog.modal({ |
|
1098 | dialog.modal({ | |
@@ -1119,10 +1112,10 define([ | |||||
1119 | }; |
|
1112 | }; | |
1120 |
|
1113 | |||
1121 | /** |
|
1114 | /** | |
1122 |
* Turn a cell into a markdown cell |
|
1115 | * Turn a cell into a heading containing markdown cell. | |
1123 | * |
|
1116 | * | |
1124 |
* @param { |
|
1117 | * @param {integer} [index] - cell index | |
1125 |
* @param { |
|
1118 | * @param {integer} [level] - heading level (e.g., 1 for h1) | |
1126 | */ |
|
1119 | */ | |
1127 | Notebook.prototype.to_heading = function (index, level) { |
|
1120 | Notebook.prototype.to_heading = function (index, level) { | |
1128 | this.to_markdown(index); |
|
1121 | this.to_markdown(index); | |
@@ -1139,7 +1132,7 define([ | |||||
1139 | // Cut/Copy/Paste |
|
1132 | // Cut/Copy/Paste | |
1140 |
|
1133 | |||
1141 | /** |
|
1134 | /** | |
1142 | * Enable UI elements for pasting cells. |
|
1135 | * Enable the UI elements for pasting cells. | |
1143 | */ |
|
1136 | */ | |
1144 | Notebook.prototype.enable_paste = function () { |
|
1137 | Notebook.prototype.enable_paste = function () { | |
1145 | var that = this; |
|
1138 | var that = this; | |
@@ -1155,7 +1148,7 define([ | |||||
1155 | }; |
|
1148 | }; | |
1156 |
|
1149 | |||
1157 | /** |
|
1150 | /** | |
1158 | * Disable UI elements for pasting cells. |
|
1151 | * Disable the UI elements for pasting cells. | |
1159 | */ |
|
1152 | */ | |
1160 | Notebook.prototype.disable_paste = function () { |
|
1153 | Notebook.prototype.disable_paste = function () { | |
1161 | if (this.paste_enabled) { |
|
1154 | if (this.paste_enabled) { | |
@@ -1188,7 +1181,7 define([ | |||||
1188 | }; |
|
1181 | }; | |
1189 |
|
1182 | |||
1190 | /** |
|
1183 | /** | |
1191 |
* Replace the selected cell with |
|
1184 | * Replace the selected cell with the cell in the clipboard. | |
1192 | */ |
|
1185 | */ | |
1193 | Notebook.prototype.paste_cell_replace = function () { |
|
1186 | Notebook.prototype.paste_cell_replace = function () { | |
1194 | if (this.clipboard !== null && this.paste_enabled) { |
|
1187 | if (this.clipboard !== null && this.paste_enabled) { | |
@@ -1228,7 +1221,7 define([ | |||||
1228 | // Split/merge |
|
1221 | // Split/merge | |
1229 |
|
1222 | |||
1230 | /** |
|
1223 | /** | |
1231 |
* Split the selected cell into two |
|
1224 | * Split the selected cell into two cells. | |
1232 | */ |
|
1225 | */ | |
1233 | Notebook.prototype.split_cell = function () { |
|
1226 | Notebook.prototype.split_cell = function () { | |
1234 | var cell = this.get_selected_cell(); |
|
1227 | var cell = this.get_selected_cell(); | |
@@ -1244,7 +1237,7 define([ | |||||
1244 | }; |
|
1237 | }; | |
1245 |
|
1238 | |||
1246 | /** |
|
1239 | /** | |
1247 |
* |
|
1240 | * Merge the selected cell into the cell above it. | |
1248 | */ |
|
1241 | */ | |
1249 | Notebook.prototype.merge_cell_above = function () { |
|
1242 | Notebook.prototype.merge_cell_above = function () { | |
1250 | var index = this.get_selected_index(); |
|
1243 | var index = this.get_selected_index(); | |
@@ -1277,7 +1270,7 define([ | |||||
1277 | }; |
|
1270 | }; | |
1278 |
|
1271 | |||
1279 | /** |
|
1272 | /** | |
1280 |
* |
|
1273 | * Merge the selected cell into the cell below it. | |
1281 | */ |
|
1274 | */ | |
1282 | Notebook.prototype.merge_cell_below = function () { |
|
1275 | Notebook.prototype.merge_cell_below = function () { | |
1283 | var index = this.get_selected_index(); |
|
1276 | var index = this.get_selected_index(); | |
@@ -1315,7 +1308,7 define([ | |||||
1315 | /** |
|
1308 | /** | |
1316 | * Hide a cell's output. |
|
1309 | * Hide a cell's output. | |
1317 | * |
|
1310 | * | |
1318 |
* @param {integer} index - |
|
1311 | * @param {integer} index - cell index | |
1319 | */ |
|
1312 | */ | |
1320 | Notebook.prototype.collapse_output = function (index) { |
|
1313 | Notebook.prototype.collapse_output = function (index) { | |
1321 | var i = this.index_or_selected(index); |
|
1314 | var i = this.index_or_selected(index); | |
@@ -1342,7 +1335,7 define([ | |||||
1342 | /** |
|
1335 | /** | |
1343 | * Show a cell's output. |
|
1336 | * Show a cell's output. | |
1344 | * |
|
1337 | * | |
1345 |
* @param {integer} index - |
|
1338 | * @param {integer} index - cell index | |
1346 | */ |
|
1339 | */ | |
1347 | Notebook.prototype.expand_output = function (index) { |
|
1340 | Notebook.prototype.expand_output = function (index) { | |
1348 | var i = this.index_or_selected(index); |
|
1341 | var i = this.index_or_selected(index); | |
@@ -1369,7 +1362,7 define([ | |||||
1369 | /** |
|
1362 | /** | |
1370 | * Clear the selected CodeCell's output area. |
|
1363 | * Clear the selected CodeCell's output area. | |
1371 | * |
|
1364 | * | |
1372 |
* @param {integer} index - |
|
1365 | * @param {integer} index - cell index | |
1373 | */ |
|
1366 | */ | |
1374 | Notebook.prototype.clear_output = function (index) { |
|
1367 | Notebook.prototype.clear_output = function (index) { | |
1375 | var i = this.index_or_selected(index); |
|
1368 | var i = this.index_or_selected(index); | |
@@ -1395,7 +1388,7 define([ | |||||
1395 | /** |
|
1388 | /** | |
1396 | * Scroll the selected CodeCell's output area. |
|
1389 | * Scroll the selected CodeCell's output area. | |
1397 | * |
|
1390 | * | |
1398 |
* @param {integer} index - |
|
1391 | * @param {integer} index - cell index | |
1399 | */ |
|
1392 | */ | |
1400 | Notebook.prototype.scroll_output = function (index) { |
|
1393 | Notebook.prototype.scroll_output = function (index) { | |
1401 | var i = this.index_or_selected(index); |
|
1394 | var i = this.index_or_selected(index); | |
@@ -1407,7 +1400,7 define([ | |||||
1407 | }; |
|
1400 | }; | |
1408 |
|
1401 | |||
1409 | /** |
|
1402 | /** | |
1410 |
* Expand each code cell's output area |
|
1403 | * Expand each code cell's output area and add a scrollbar for long output. | |
1411 | */ |
|
1404 | */ | |
1412 | Notebook.prototype.scroll_all_output = function () { |
|
1405 | Notebook.prototype.scroll_all_output = function () { | |
1413 | this.get_cells().map(function (cell, i) { |
|
1406 | this.get_cells().map(function (cell, i) { | |
@@ -1419,9 +1412,10 define([ | |||||
1419 | this.set_dirty(true); |
|
1412 | this.set_dirty(true); | |
1420 | }; |
|
1413 | }; | |
1421 |
|
1414 | |||
1422 | /** Toggle whether a cell's output is collapsed or expanded. |
|
1415 | /** | |
|
1416 | * Toggle whether a cell's output is collapsed or expanded. | |||
1423 | * |
|
1417 | * | |
1424 |
* @param {integer} index - |
|
1418 | * @param {integer} index - cell index | |
1425 | */ |
|
1419 | */ | |
1426 | Notebook.prototype.toggle_output = function (index) { |
|
1420 | Notebook.prototype.toggle_output = function (index) { | |
1427 | var i = this.index_or_selected(index); |
|
1421 | var i = this.index_or_selected(index); | |
@@ -1433,7 +1427,7 define([ | |||||
1433 | }; |
|
1427 | }; | |
1434 |
|
1428 | |||
1435 | /** |
|
1429 | /** | |
1436 |
* |
|
1430 | * Toggle the output of all cells. | |
1437 | */ |
|
1431 | */ | |
1438 | Notebook.prototype.toggle_all_output = function () { |
|
1432 | Notebook.prototype.toggle_all_output = function () { | |
1439 | this.get_cells().map(function (cell, i) { |
|
1433 | this.get_cells().map(function (cell, i) { | |
@@ -1448,7 +1442,7 define([ | |||||
1448 | /** |
|
1442 | /** | |
1449 | * Toggle a scrollbar for long cell outputs. |
|
1443 | * Toggle a scrollbar for long cell outputs. | |
1450 | * |
|
1444 | * | |
1451 |
* @param {integer} index - |
|
1445 | * @param {integer} index - cell index | |
1452 | */ |
|
1446 | */ | |
1453 | Notebook.prototype.toggle_output_scroll = function (index) { |
|
1447 | Notebook.prototype.toggle_output_scroll = function (index) { | |
1454 | var i = this.index_or_selected(index); |
|
1448 | var i = this.index_or_selected(index); | |
@@ -1540,7 +1534,7 define([ | |||||
1540 |
|
1534 | |||
1541 | /** |
|
1535 | /** | |
1542 | * Once a session is started, link the code cells to the kernel and pass the |
|
1536 | * Once a session is started, link the code cells to the kernel and pass the | |
1543 | * comm manager to the widget manager |
|
1537 | * comm manager to the widget manager. | |
1544 | */ |
|
1538 | */ | |
1545 | Notebook.prototype._session_started = function (){ |
|
1539 | Notebook.prototype._session_started = function (){ | |
1546 | this._session_starting = false; |
|
1540 | this._session_starting = false; | |
@@ -1553,9 +1547,11 define([ | |||||
1553 | } |
|
1547 | } | |
1554 | } |
|
1548 | } | |
1555 | }; |
|
1549 | }; | |
|
1550 | ||||
1556 | /** |
|
1551 | /** | |
|
1552 | * Called when the session fails to start. | |||
1557 | */ |
|
1553 | */ | |
1558 |
Notebook.prototype._session_start_failed = function |
|
1554 | Notebook.prototype._session_start_failed = function(jqxhr, status, error){ | |
1559 | this._session_starting = false; |
|
1555 | this._session_starting = false; | |
1560 | utils.log_ajax_error(jqxhr, status, error); |
|
1556 | utils.log_ajax_error(jqxhr, status, error); | |
1561 | }; |
|
1557 | }; | |
@@ -1676,8 +1672,8 define([ | |||||
1676 | /** |
|
1672 | /** | |
1677 | * Execute a contiguous range of cells. |
|
1673 | * Execute a contiguous range of cells. | |
1678 | * |
|
1674 | * | |
1679 |
* @param {integer} start - |
|
1675 | * @param {integer} start - index of the first cell to execute (inclusive) | |
1680 |
* @param {integer} end - |
|
1676 | * @param {integer} end - index of the last cell to execute (exclusive) | |
1681 | */ |
|
1677 | */ | |
1682 | Notebook.prototype.execute_cell_range = function (start, end) { |
|
1678 | Notebook.prototype.execute_cell_range = function (start, end) { | |
1683 | this.command_mode(); |
|
1679 | this.command_mode(); | |
@@ -1702,7 +1698,7 define([ | |||||
1702 | /** |
|
1698 | /** | |
1703 | * Setter method for this notebook's name. |
|
1699 | * Setter method for this notebook's name. | |
1704 | * |
|
1700 | * | |
1705 |
* @param {string} name |
|
1701 | * @param {string} name | |
1706 | */ |
|
1702 | */ | |
1707 | Notebook.prototype.set_notebook_name = function (name) { |
|
1703 | Notebook.prototype.set_notebook_name = function (name) { | |
1708 | var parent = utils.url_path_split(this.notebook_path)[0]; |
|
1704 | var parent = utils.url_path_split(this.notebook_path)[0]; | |
@@ -1728,7 +1724,7 define([ | |||||
1728 | /** |
|
1724 | /** | |
1729 | * Load a notebook from JSON (.ipynb). |
|
1725 | * Load a notebook from JSON (.ipynb). | |
1730 | * |
|
1726 | * | |
1731 |
* @param { |
|
1727 | * @param {object} data - JSON representation of a notebook | |
1732 | */ |
|
1728 | */ | |
1733 | Notebook.prototype.fromJSON = function (data) { |
|
1729 | Notebook.prototype.fromJSON = function (data) { | |
1734 |
|
1730 | |||
@@ -1780,7 +1776,7 define([ | |||||
1780 | /** |
|
1776 | /** | |
1781 | * Dump this notebook into a JSON-friendly object. |
|
1777 | * Dump this notebook into a JSON-friendly object. | |
1782 | * |
|
1778 | * | |
1783 |
* @return { |
|
1779 | * @return {object} A JSON-friendly representation of this notebook. | |
1784 | */ |
|
1780 | */ | |
1785 | Notebook.prototype.toJSON = function () { |
|
1781 | Notebook.prototype.toJSON = function () { | |
1786 | // remove the conversion indicator, which only belongs in-memory |
|
1782 | // remove the conversion indicator, which only belongs in-memory | |
@@ -1812,7 +1808,7 define([ | |||||
1812 | }; |
|
1808 | }; | |
1813 |
|
1809 | |||
1814 | /** |
|
1810 | /** | |
1815 |
* Start an autosave timer |
|
1811 | * Start an autosave timer which periodically saves the notebook. | |
1816 | * |
|
1812 | * | |
1817 | * @param {integer} interval - the autosave interval in milliseconds |
|
1813 | * @param {integer} interval - the autosave interval in milliseconds | |
1818 | */ |
|
1814 | */ | |
@@ -1883,7 +1879,7 define([ | |||||
1883 | * Success callback for saving a notebook. |
|
1879 | * Success callback for saving a notebook. | |
1884 | * |
|
1880 | * | |
1885 | * @param {integer} start - Time when the save request start |
|
1881 | * @param {integer} start - Time when the save request start | |
1886 |
* @param { |
|
1882 | * @param {object} data - JSON representation of a notebook | |
1887 | */ |
|
1883 | */ | |
1888 | Notebook.prototype.save_notebook_success = function (start, data) { |
|
1884 | Notebook.prototype.save_notebook_success = function (start, data) { | |
1889 | this.set_dirty(false); |
|
1885 | this.set_dirty(false); | |
@@ -1920,7 +1916,7 define([ | |||||
1920 | }; |
|
1916 | }; | |
1921 |
|
1917 | |||
1922 | /** |
|
1918 | /** | |
1923 |
* |
|
1919 | * Update the autosave interval based on the duration of the last save. | |
1924 | * |
|
1920 | * | |
1925 | * @param {integer} timestamp - when the save request started |
|
1921 | * @param {integer} timestamp - when the save request started | |
1926 | */ |
|
1922 | */ | |
@@ -1988,7 +1984,6 define([ | |||||
1988 |
|
1984 | |||
1989 | /** |
|
1985 | /** | |
1990 | * Make a copy of the current notebook. |
|
1986 | * Make a copy of the current notebook. | |
1991 | * @return {null} |
|
|||
1992 | */ |
|
1987 | */ | |
1993 | Notebook.prototype.copy_notebook = function () { |
|
1988 | Notebook.prototype.copy_notebook = function () { | |
1994 | var that = this; |
|
1989 | var that = this; | |
@@ -2009,7 +2004,7 define([ | |||||
2009 | }; |
|
2004 | }; | |
2010 |
|
2005 | |||
2011 | /** |
|
2006 | /** | |
2012 | * Rename the notebook |
|
2007 | * Rename the notebook. | |
2013 | * @param {string} new_name |
|
2008 | * @param {string} new_name | |
2014 | * @return {Promise} promise that resolves when the notebook is renamed. |
|
2009 | * @return {Promise} promise that resolves when the notebook is renamed. | |
2015 | */ |
|
2010 | */ | |
@@ -2033,7 +2028,6 define([ | |||||
2033 |
|
2028 | |||
2034 | /** |
|
2029 | /** | |
2035 | * Delete this notebook |
|
2030 | * Delete this notebook | |
2036 | * @return {null} |
|
|||
2037 | */ |
|
2031 | */ | |
2038 | Notebook.prototype.delete = function () { |
|
2032 | Notebook.prototype.delete = function () { | |
2039 | this.contents.delete(this.notebook_path); |
|
2033 | this.contents.delete(this.notebook_path); | |
@@ -2059,7 +2053,7 define([ | |||||
2059 | * |
|
2053 | * | |
2060 | * Load notebook data from the JSON response. |
|
2054 | * Load notebook data from the JSON response. | |
2061 | * |
|
2055 | * | |
2062 |
* @param { |
|
2056 | * @param {object} data JSON representation of a notebook | |
2063 | */ |
|
2057 | */ | |
2064 | Notebook.prototype.load_notebook_success = function (data) { |
|
2058 | Notebook.prototype.load_notebook_success = function (data) { | |
2065 | var failed, msg; |
|
2059 | var failed, msg; | |
@@ -2220,7 +2214,7 define([ | |||||
2220 | }); |
|
2214 | }); | |
2221 | }; |
|
2215 | }; | |
2222 |
|
2216 | |||
2223 |
/********************* checkpoint-related ******************** |
|
2217 | /********************* checkpoint-related ********************/ | |
2224 |
|
2218 | |||
2225 | /** |
|
2219 | /** | |
2226 | * Save the notebook then immediately create a checkpoint. |
|
2220 | * Save the notebook then immediately create a checkpoint. | |
@@ -2232,7 +2226,6 define([ | |||||
2232 |
|
2226 | |||
2233 | /** |
|
2227 | /** | |
2234 | * Add a checkpoint for this notebook. |
|
2228 | * Add a checkpoint for this notebook. | |
2235 | * for use as a callback from checkpoint creation. |
|
|||
2236 | */ |
|
2229 | */ | |
2237 | Notebook.prototype.add_checkpoint = function (checkpoint) { |
|
2230 | Notebook.prototype.add_checkpoint = function (checkpoint) { | |
2238 | var found = false; |
|
2231 | var found = false; | |
@@ -2266,7 +2259,7 define([ | |||||
2266 | /** |
|
2259 | /** | |
2267 | * Success callback for listing checkpoints. |
|
2260 | * Success callback for listing checkpoints. | |
2268 | * |
|
2261 | * | |
2269 |
* @param { |
|
2262 | * @param {object} data - JSON representation of a checkpoint | |
2270 | */ |
|
2263 | */ | |
2271 | Notebook.prototype.list_checkpoints_success = function (data) { |
|
2264 | Notebook.prototype.list_checkpoints_success = function (data) { | |
2272 | this.checkpoints = data; |
|
2265 | this.checkpoints = data; | |
@@ -2294,7 +2287,7 define([ | |||||
2294 | /** |
|
2287 | /** | |
2295 | * Success callback for creating a checkpoint. |
|
2288 | * Success callback for creating a checkpoint. | |
2296 | * |
|
2289 | * | |
2297 |
* @param { |
|
2290 | * @param {object} data - JSON representation of a checkpoint | |
2298 | */ |
|
2291 | */ | |
2299 | Notebook.prototype.create_checkpoint_success = function (data) { |
|
2292 | Notebook.prototype.create_checkpoint_success = function (data) { | |
2300 | this.add_checkpoint(data); |
|
2293 | this.add_checkpoint(data); | |
@@ -2304,7 +2297,6 define([ | |||||
2304 | /** |
|
2297 | /** | |
2305 | * Display the restore checkpoint dialog |
|
2298 | * Display the restore checkpoint dialog | |
2306 | * @param {string} checkpoint ID |
|
2299 | * @param {string} checkpoint ID | |
2307 | * @return {null} |
|
|||
2308 | */ |
|
2300 | */ | |
2309 | Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) { |
|
2301 | Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) { | |
2310 | var that = this; |
|
2302 | var that = this; | |
@@ -2388,7 +2380,7 define([ | |||||
2388 | }; |
|
2380 | }; | |
2389 |
|
2381 | |||
2390 | /** |
|
2382 | /** | |
2391 | * Success callback for deleting a notebook checkpoint |
|
2383 | * Success callback for deleting a notebook checkpoint. | |
2392 | */ |
|
2384 | */ | |
2393 | Notebook.prototype.delete_checkpoint_success = function () { |
|
2385 | Notebook.prototype.delete_checkpoint_success = function () { | |
2394 | this.events.trigger('checkpoint_deleted.Notebook'); |
|
2386 | this.events.trigger('checkpoint_deleted.Notebook'); |
General Comments 0
You need to be logged in to leave comments.
Login now