##// END OF EJS Templates
Added heading and slideshow scroll managers
Jonathan Frederic -
Show More
@@ -11,24 +11,6 define([
11 11 var CellToolbar = celltoolbar.CellToolbar;
12 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 14 var select_type = CellToolbar.utils.select_ui_generator([
33 15 ["-" ,"-" ],
34 16 ["Slide" ,"slide" ],
@@ -42,13 +24,15 define([
42 24 // we check that the slideshow namespace exist and create it if needed
43 25 if (cell.metadata.slideshow === undefined){cell.metadata.slideshow = {};}
44 26 // set the value
45 var old = cell.metadata.slideshow.slide_type;
46 27 cell.metadata.slideshow.slide_type = value;
47 // update the slideshow class set on the cell
48 _update_cell(cell, old);
49 28 },
50 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 36 "Slide Type");
53 37
54 38 var register = function (notebook) {
1 NO CONTENT: modified file
@@ -27,7 +27,7 define(['jquery'], function($){
27 27 var that = this;
28 28 this._combo.change(function(){
29 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 define(['jquery'], function($){
80 80 // is found. To guess the index, get the top of the last cell, and
81 81 // divide that by the number of cells to get an average cell height.
82 82 // Then divide the scroll height by the average cell height.
83 var cell_count = that.notebook.ncells();
84 var first_cell_top = that.notebook.get_cell(0).element.offset.top();
85 var last_cell_top = that.notebook.get_cell(cell_count-1).element.offset.top();
83 var cell_count = this.notebook.ncells();
84 var first_cell_top = this.notebook.get_cell(0).element.offset().top;
85 var last_cell_top = this.notebook.get_cell(cell_count-1).element.offset().top;
86 86 var avg_cell_height = (last_cell_top - first_cell_top) / cell_count;
87 var $notebook = $('#notebook').scrollTop();
88 var i = Math.ceil($notebook.scrollTop() / avg_cell_height);
89 i = min(max(i , 0), cell_count - 1);
87 var notebook = $('#notebook');
88 var i = Math.ceil(notebook.scrollTop() / avg_cell_height);
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 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 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 103 // Public constructor.
104 ScrollManager.apply(this, [notebook]);
104 105 };
106 TargetScrollManager.prototype = new ScrollManager();
105 107
106
107 var SlideScrollManager = function(notebook) {
108 // Public constructor.
108 TargetScrollManager.prototype.is_target = function (index) {
109 return false;
109 110 };
110 111
111 /*// Scroll the document.
112 TargetScrollManager.prototype.scroll = function (delta) {
113 // Scroll the document.
112 114 //
113 115 // Parameters
114 116 // ----------
115 117 // delta: integer
116 118 // direction to scroll the document. Positive is downwards.
117 119
118 // If one or more slides exist, scroll to the slide.
119 var $slide_cells = $('.slideshow-slide');
120 if ($slide_cells.length > 0) {
121 var i, cell;
122
123 // Get the active slide cell index.
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 }
120 // Try to scroll to the next slide.
121 var cell_count = this.notebook.ncells();
122 var selected_index = this.get_first_visible_cell() + delta;
123 while (0 <= selected_index && selected_index < cell_count && !this.is_target(selected_index)) {
124 selected_index += delta;
134 125 }
135 126
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 }
127 if (selected_index < 0 || cell_count <= selected_index) {
128 return ScrollManager.prototype.scroll.apply(this, [delta]);
129 } else {
130 this.scroll_to(this.notebook.get_cell(selected_index).element);
131
132 // Cancel browser keyboard scroll.
133 return false;
144 134 }
135 };
136
145 137
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));
138 var SlideScrollManager = function(notebook) {
139 // Public constructor.
140 TargetScrollManager.apply(this, [notebook]);
141 };
142 SlideScrollManager.prototype = new TargetScrollManager();
150 143
151 var cell_element = $slide_cells[active_slide];
152 cell = $(cell_element).data('cell');
153 this.notebook.select(this.notebook.find_cell_index(cell));
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 };
154 150
155 this.scroll_to(cell_element);
156 //cell_element.scrollIntoView(true);
157 }
158 151
159 // Cancel browser keyboard scroll.
160 return false;
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 };
161 163
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 {
165 this.scroll_some(delta);
166 return false;
167 }*/
168 164
169 165 // Return naemspace for require.js loads
170 166 return {
171 167 'ScrollSelector': ScrollSelector,
172 168 'ScrollManager': ScrollManager,
173 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