##// END OF EJS Templates
Added heading and slideshow scroll managers
Jonathan Frederic -
Show More
@@ -11,24 +11,6 b' define(['
11 var CellToolbar = celltoolbar.CellToolbar;
11 var CellToolbar = celltoolbar.CellToolbar;
12 var slideshow_preset = [];
12 var slideshow_preset = [];
13
13
14 var _update_cell = function(cell, old_slide_class) {
15 // Remove the old slide DOM class if set.
16 if (old_slide_class && old_slide_class != '-') {
17 cell.element.removeClass('slideshow-'+old_slide_class);
18 }
19 // add a DOM class to the cell
20 var value = _get_cell_type(cell);
21 if (value != '-') { cell.element.addClass('slideshow-'+value); }
22 };
23
24 var _get_cell_type = function(cell) {
25 var ns = cell.metadata.slideshow;
26 // if the slideshow namespace does not exist return `undefined`
27 // (will be interpreted as `false` by checkbox) otherwise
28 // return the value
29 return (ns === undefined)? undefined: ns.slide_type;
30 };
31
32 var select_type = CellToolbar.utils.select_ui_generator([
14 var select_type = CellToolbar.utils.select_ui_generator([
33 ["-" ,"-" ],
15 ["-" ,"-" ],
34 ["Slide" ,"slide" ],
16 ["Slide" ,"slide" ],
@@ -42,13 +24,15 b' define(['
42 // we check that the slideshow namespace exist and create it if needed
24 // we check that the slideshow namespace exist and create it if needed
43 if (cell.metadata.slideshow === undefined){cell.metadata.slideshow = {};}
25 if (cell.metadata.slideshow === undefined){cell.metadata.slideshow = {};}
44 // set the value
26 // set the value
45 var old = cell.metadata.slideshow.slide_type;
46 cell.metadata.slideshow.slide_type = value;
27 cell.metadata.slideshow.slide_type = value;
47 // update the slideshow class set on the cell
48 _update_cell(cell, old);
49 },
28 },
50 //geter
29 //geter
51 _get_cell_type,
30 function(cell){ var ns = cell.metadata.slideshow;
31 // if the slideshow namespace does not exist return `undefined`
32 // (will be interpreted as `false` by checkbox) otherwise
33 // return the value
34 return (ns === undefined)? undefined: ns.slide_type;
35 },
52 "Slide Type");
36 "Slide Type");
53
37
54 var register = function (notebook) {
38 var register = function (notebook) {
@@ -1625,7 +1625,7 b' define(['
1625 this._session_starting = false;
1625 this._session_starting = false;
1626 utils.log_ajax_error(jqxhr, status, error);
1626 utils.log_ajax_error(jqxhr, status, error);
1627 };
1627 };
1628
1628
1629 /**
1629 /**
1630 * Prompt the user to restart the IPython kernel.
1630 * Prompt the user to restart the IPython kernel.
1631 *
1631 *
@@ -27,7 +27,7 b" define(['jquery'], function($){"
27 var that = this;
27 var that = this;
28 this._combo.change(function(){
28 this._combo.change(function(){
29 var manager = that._registered[$(this).find("option:selected").val()];
29 var manager = that._registered[$(this).find("option:selected").val()];
30 that.notebook.ScrollSelector = manager;
30 that.notebook.scrollmanager = manager;
31 });
31 });
32 };
32 };
33
33
@@ -80,97 +80,94 b" define(['jquery'], function($){"
80 // is found. To guess the index, get the top of the last cell, and
80 // is found. To guess the index, get the top of the last cell, and
81 // divide that by the number of cells to get an average cell height.
81 // divide that by the number of cells to get an average cell height.
82 // Then divide the scroll height by the average cell height.
82 // Then divide the scroll height by the average cell height.
83 var cell_count = that.notebook.ncells();
83 var cell_count = this.notebook.ncells();
84 var first_cell_top = that.notebook.get_cell(0).element.offset.top();
84 var first_cell_top = this.notebook.get_cell(0).element.offset().top;
85 var last_cell_top = that.notebook.get_cell(cell_count-1).element.offset.top();
85 var last_cell_top = this.notebook.get_cell(cell_count-1).element.offset().top;
86 var avg_cell_height = (last_cell_top - first_cell_top) / cell_count;
86 var avg_cell_height = (last_cell_top - first_cell_top) / cell_count;
87 var $notebook = $('#notebook').scrollTop();
87 var notebook = $('#notebook');
88 var i = Math.ceil($notebook.scrollTop() / avg_cell_height);
88 var i = Math.ceil(notebook.scrollTop() / avg_cell_height);
89 i = min(max(i , 0), cell_count - 1);
89 i = Math.min(Math.max(i , 0), cell_count - 1);
90
90
91 while (that.notebook.get_cell(i).element.offset.top() - first_cell_top < $notebook.scrollTop() && i < cell_count - 1) {
91 while (this.notebook.get_cell(i).element.offset().top - first_cell_top < notebook.scrollTop() && i < cell_count - 1) {
92 i += 1;
92 i += 1;
93 }
93 }
94
94
95 while (that.notebook.get_cell(i).element.offset.top() - first_cell_top > $notebook.scrollTop() && i >= 0) {
95 while (this.notebook.get_cell(i).element.offset().top - first_cell_top > notebook.scrollTop() - 50 && i >= 0) {
96 i -= 1;
96 i -= 1;
97 }
97 }
98 return min(i + 1, cell_count - 1);
98 return Math.min(i + 1, cell_count - 1);
99 };
99 };
100
100
101
101
102 var HeadingScrollManager = function(notebook, heading_level) {
102 var TargetScrollManager = function(notebook) {
103 // Public constructor.
103 // Public constructor.
104 ScrollManager.apply(this, [notebook]);
104 };
105 };
106 TargetScrollManager.prototype = new ScrollManager();
105
107
106
108 TargetScrollManager.prototype.is_target = function (index) {
107 var SlideScrollManager = function(notebook) {
109 return false;
108 // Public constructor.
109 };
110 };
110
111
111 /*// Scroll the document.
112 TargetScrollManager.prototype.scroll = function (delta) {
113 // Scroll the document.
112 //
114 //
113 // Parameters
115 // Parameters
114 // ----------
116 // ----------
115 // delta: integer
117 // delta: integer
116 // direction to scroll the document. Positive is downwards.
118 // direction to scroll the document. Positive is downwards.
117
119
118 // If one or more slides exist, scroll to the slide.
120 // Try to scroll to the next slide.
119 var $slide_cells = $('.slideshow-slide');
121 var cell_count = this.notebook.ncells();
120 if ($slide_cells.length > 0) {
122 var selected_index = this.get_first_visible_cell() + delta;
121 var i, cell;
123 while (0 <= selected_index && selected_index < cell_count && !this.is_target(selected_index)) {
122
124 selected_index += delta;
123 // Get the active slide cell index.
125 }
124 var selected_index = this.notebook.find_cell_index(this.notebook.get_selected_cell());
125 var active_slide = -1;
126 var cells = this.notebook.get_cells();
127 for (i = selected_index; i >= 0; i--) {
128 cell = cells[i];
129 var ns = cell.metadata.slideshow;
130 if (ns && ns.slide_type == 'slide') {
131 active_slide = i;
132 break;
133 }
134 }
135
136 // Translate cell index into slide cell index.
137 if (active_slide != -1) {
138 for (i = 0; i < $slide_cells.length; i++) {
139 if (cells[active_slide].element[0] == $slide_cells[i]) {
140 active_slide = i;
141 break;
142 }
143 }
144 }
145
146 // Scroll.
147 if (active_slide != -1 || delta > 0) {
148 active_slide += delta;
149 active_slide = Math.max(0, Math.min($slide_cells.length-1, active_slide));
150
151 var cell_element = $slide_cells[active_slide];
152 cell = $(cell_element).data('cell');
153 this.notebook.select(this.notebook.find_cell_index(cell));
154
155 this.scroll_to(cell_element);
156 //cell_element.scrollIntoView(true);
157 }
158
126
159 // Cancel browser keyboard scroll.
127 if (selected_index < 0 || cell_count <= selected_index) {
160 return false;
128 return ScrollManager.prototype.scroll.apply(this, [delta]);
161
162 // No slides exist, scroll up or down one page height. Instead of using
163 // the browser's built in method to do this, animate it using jQuery.
164 } else {
129 } else {
165 this.scroll_some(delta);
130 this.scroll_to(this.notebook.get_cell(selected_index).element);
131
132 // Cancel browser keyboard scroll.
166 return false;
133 return false;
167 }*/
134 }
135 };
136
137
138 var SlideScrollManager = function(notebook) {
139 // Public constructor.
140 TargetScrollManager.apply(this, [notebook]);
141 };
142 SlideScrollManager.prototype = new TargetScrollManager();
143
144 SlideScrollManager.prototype.is_target = function (index) {
145 var cell = this.notebook.get_cell(index);
146 return cell.metadata && cell.metadata.slideshow &&
147 cell.metadata.slideshow.slide_type &&
148 cell.metadata.slideshow.slide_type === "slide";
149 };
150
151
152 var HeadingScrollManager = function(notebook, heading_level) {
153 // Public constructor.
154 TargetScrollManager.apply(this, [notebook]);
155 this._level = heading_level;
156 };
157 HeadingScrollManager.prototype = new TargetScrollManager();
158
159 HeadingScrollManager.prototype.is_target = function (index) {
160 var cell = this.notebook.get_cell(index);
161 return cell.cell_type === "heading" && cell.level == this._level;
162 };
163
168
164
169 // Return naemspace for require.js loads
165 // Return naemspace for require.js loads
170 return {
166 return {
171 'ScrollSelector': ScrollSelector,
167 'ScrollSelector': ScrollSelector,
172 'ScrollManager': ScrollManager,
168 'ScrollManager': ScrollManager,
173 'SlideScrollManager': SlideScrollManager,
169 'SlideScrollManager': SlideScrollManager,
174 'HeadingScrollManager': HeadingScrollManager
170 'HeadingScrollManager': HeadingScrollManager,
171 'TargetScrollManager': TargetScrollManager
175 };
172 };
176 });
173 });
General Comments 0
You need to be logged in to leave comments. Login now