Show More
@@ -366,7 +366,7 b' define([' | |||||
366 | index = Math.min(cells.length-1,index); |
|
366 | index = Math.min(cells.length-1,index); | |
367 | index = Math.max(0 ,index); |
|
367 | index = Math.max(0 ,index); | |
368 | var scroll_value = cells[index].element.position().top-cells[0].element.position().top ; |
|
368 | var scroll_value = cells[index].element.position().top-cells[0].element.position().top ; | |
369 | this.element.animate({scrollTop:scroll_value}, time); |
|
369 | this.scroll_manager.element.animate({scrollTop:scroll_value}, time); | |
370 | return scroll_value; |
|
370 | return scroll_value; | |
371 | }; |
|
371 | }; | |
372 |
|
372 | |||
@@ -374,14 +374,14 b' define([' | |||||
374 | * Scroll to the bottom of the page. |
|
374 | * Scroll to the bottom of the page. | |
375 | */ |
|
375 | */ | |
376 | Notebook.prototype.scroll_to_bottom = function () { |
|
376 | Notebook.prototype.scroll_to_bottom = function () { | |
377 | this.element.animate({scrollTop:this.element.get(0).scrollHeight}, 0); |
|
377 | this.scroll_manager.element.animate({scrollTop:this.element.get(0).scrollHeight}, 0); | |
378 | }; |
|
378 | }; | |
379 |
|
379 | |||
380 | /** |
|
380 | /** | |
381 | * Scroll to the top of the page. |
|
381 | * Scroll to the top of the page. | |
382 | */ |
|
382 | */ | |
383 | Notebook.prototype.scroll_to_top = function () { |
|
383 | Notebook.prototype.scroll_to_top = function () { | |
384 | this.element.animate({scrollTop:0}, 0); |
|
384 | this.scroll_manager.element.animate({scrollTop:0}, 0); | |
385 | }; |
|
385 | }; | |
386 |
|
386 | |||
387 | // Edit Notebook metadata |
|
387 | // Edit Notebook metadata |
@@ -8,6 +8,7 b" define(['jquery'], function($){" | |||||
8 | * Public constructor. |
|
8 | * Public constructor. | |
9 | */ |
|
9 | */ | |
10 | this.notebook = notebook; |
|
10 | this.notebook = notebook; | |
|
11 | this.element = $('body'); | |||
11 | options = options || {}; |
|
12 | options = options || {}; | |
12 | this.animation_speed = options.animation_speed || 250; //ms |
|
13 | this.animation_speed = options.animation_speed || 250; //ms | |
13 | }; |
|
14 | }; | |
@@ -30,7 +31,7 b" define(['jquery'], function($){" | |||||
30 | /** |
|
31 | /** | |
31 | * Scroll to an element in the notebook. |
|
32 | * Scroll to an element in the notebook. | |
32 | */ |
|
33 | */ | |
33 |
|
|
34 | this.element.animate({'scrollTop': $(selector).offset().top + this.element.scrollTop() - this.element.offset().top}, this.animation_speed); | |
34 | }; |
|
35 | }; | |
35 |
|
36 | |||
36 | ScrollManager.prototype.scroll_some = function(pages) { |
|
37 | ScrollManager.prototype.scroll_some = function(pages) { | |
@@ -42,7 +43,7 b" define(['jquery'], function($){" | |||||
42 | * pages: integer |
|
43 | * pages: integer | |
43 | * number of pages to scroll the document, may be positive or negative. |
|
44 | * number of pages to scroll the document, may be positive or negative. | |
44 | */ |
|
45 | */ | |
45 |
|
|
46 | this.element.animate({'scrollTop': this.element.scrollTop() + pages * this.element.height()}, this.animation_speed); | |
46 | }; |
|
47 | }; | |
47 |
|
48 | |||
48 | ScrollManager.prototype.get_first_visible_cell = function() { |
|
49 | ScrollManager.prototype.get_first_visible_cell = function() { | |
@@ -59,15 +60,14 b" define(['jquery'], function($){" | |||||
59 | var first_cell_top = this.notebook.get_cell(0).element.offset().top; |
|
60 | var first_cell_top = this.notebook.get_cell(0).element.offset().top; | |
60 | var last_cell_top = this.notebook.get_cell(cell_count-1).element.offset().top; |
|
61 | var last_cell_top = this.notebook.get_cell(cell_count-1).element.offset().top; | |
61 | var avg_cell_height = (last_cell_top - first_cell_top) / cell_count; |
|
62 | var avg_cell_height = (last_cell_top - first_cell_top) / cell_count; | |
62 | var notebook = $('#notebook'); |
|
63 | var i = Math.ceil(this.element.scrollTop() / avg_cell_height); | |
63 | var i = Math.ceil(notebook.scrollTop() / avg_cell_height); |
|
|||
64 | i = Math.min(Math.max(i , 0), cell_count - 1); |
|
64 | i = Math.min(Math.max(i , 0), cell_count - 1); | |
65 |
|
65 | |||
66 |
while (this.notebook.get_cell(i).element.offset().top - first_cell_top < |
|
66 | while (this.notebook.get_cell(i).element.offset().top - first_cell_top < this.element.scrollTop() && i < cell_count - 1) { | |
67 | i += 1; |
|
67 | i += 1; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 |
while (this.notebook.get_cell(i).element.offset().top - first_cell_top > |
|
70 | while (this.notebook.get_cell(i).element.offset().top - first_cell_top > this.element.scrollTop() - 50 && i >= 0) { | |
71 | i -= 1; |
|
71 | i -= 1; | |
72 | } |
|
72 | } | |
73 | return Math.min(i + 1, cell_count - 1); |
|
73 | return Math.min(i + 1, cell_count - 1); | |
@@ -151,7 +151,7 b" define(['jquery'], function($){" | |||||
151 | options = options || {}; |
|
151 | options = options || {}; | |
152 | this._level = options.heading_level || 1; |
|
152 | this._level = options.heading_level || 1; | |
153 | }; |
|
153 | }; | |
154 | HeadingScrollManager.prototype = Object.create(ScrollManager.prototype) |
|
154 | HeadingScrollManager.prototype = Object.create(ScrollManager.prototype); | |
155 |
|
155 | |||
156 | HeadingScrollManager.prototype.scroll = function (delta) { |
|
156 | HeadingScrollManager.prototype.scroll = function (delta) { | |
157 | /** |
|
157 | /** | |
@@ -174,8 +174,7 b" define(['jquery'], function($){" | |||||
174 |
|
174 | |||
175 | // Find the header the user is on or below. |
|
175 | // Find the header the user is on or below. | |
176 | var first_cell_top = this.notebook.get_cell(0).element.offset().top; |
|
176 | var first_cell_top = this.notebook.get_cell(0).element.offset().top; | |
177 | var notebook = $('#notebook'); |
|
177 | var current_scroll = this.element.scrollTop(); | |
178 | var current_scroll = notebook.scrollTop(); |
|
|||
179 | var header_scroll = 0; |
|
178 | var header_scroll = 0; | |
180 | i = -1; |
|
179 | i = -1; | |
181 | while (current_scroll >= header_scroll && i < headers.length) { |
|
180 | while (current_scroll >= header_scroll && i < headers.length) { |
General Comments 0
You need to be logged in to leave comments.
Login now