Show More
@@ -1,87 +1,84 b'' | |||||
1 | // Copyright (c) IPython Development Team. |
|
1 | // Copyright (c) IPython Development Team. | |
2 | // Distributed under the terms of the Modified BSD License. |
|
2 | // Distributed under the terms of the Modified BSD License. | |
3 | define([], function(){ |
|
3 | define([], function(){ | |
4 | "use strict"; |
|
4 | "use strict"; | |
5 |
|
5 | |||
6 | var ScrollManager = function (notebook) { |
|
6 | var ScrollManager = function (notebook) { | |
7 | // Public constructor. |
|
7 | // Public constructor. | |
8 | this.notebook = notebook; |
|
8 | this.notebook = notebook; | |
9 | this.animation_speed = 250; //ms |
|
9 | this.animation_speed = 250; //ms | |
10 | }; |
|
10 | }; | |
11 |
|
11 | |||
12 | ScrollManager.prototype.scroll = function (delta) { |
|
12 | ScrollManager.prototype.scroll = function (delta) { | |
13 | // Scroll the document. |
|
13 | // Scroll the document. | |
14 | // |
|
14 | // | |
15 | // Parameters |
|
15 | // Parameters | |
16 | // ---------- |
|
16 | // ---------- | |
17 | // delta: integer |
|
17 | // delta: integer | |
18 | // direction to scroll the document. Positive is downwards. |
|
18 | // direction to scroll the document. Positive is downwards. | |
19 |
|
19 | |||
20 | // If one or more slides exist, scroll to the slide. |
|
20 | // If one or more slides exist, scroll to the slide. | |
21 | var $slide_cells = $('.slideshow-slide'); |
|
21 | var $slide_cells = $('.slideshow-slide'); | |
22 | if ($slide_cells.length > 0) { |
|
22 | if ($slide_cells.length > 0) { | |
23 | var i, cell; |
|
23 | var i, cell; | |
24 |
|
24 | |||
25 | // Get the active slide cell index. |
|
25 | // Get the active slide cell index. | |
26 | var selected_index = this.notebook.find_cell_index(this.notebook.get_selected_cell()); |
|
26 | var selected_index = this.notebook.find_cell_index(this.notebook.get_selected_cell()); | |
27 | var active_slide = -1; |
|
27 | var active_slide = -1; | |
28 | var cells = this.notebook.get_cells(); |
|
28 | var cells = this.notebook.get_cells(); | |
29 | for (i = selected_index; i >= 0; i--) { |
|
29 | for (i = selected_index; i >= 0; i--) { | |
30 | cell = cells[i]; |
|
30 | cell = cells[i]; | |
31 | var ns = cell.metadata.slideshow; |
|
31 | var ns = cell.metadata.slideshow; | |
32 | if (ns && ns.slide_type == 'slide') { |
|
32 | if (ns && ns.slide_type == 'slide') { | |
33 | active_slide = i; |
|
33 | active_slide = i; | |
34 | break; |
|
34 | break; | |
35 | } |
|
35 | } | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | // Translate cell index into slide cell index. |
|
38 | // Translate cell index into slide cell index. | |
39 | if (active_slide != -1) { |
|
39 | if (active_slide != -1) { | |
40 | for (i = 0; i < $slide_cells.length; i++) { |
|
40 | for (i = 0; i < $slide_cells.length; i++) { | |
41 | if (cells[active_slide].element[0] == $slide_cells[i]) { |
|
41 | if (cells[active_slide].element[0] == $slide_cells[i]) { | |
42 | active_slide = i; |
|
42 | active_slide = i; | |
43 | break; |
|
43 | break; | |
44 | } |
|
44 | } | |
45 | } |
|
45 | } | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | // Scroll. |
|
48 | // Scroll. | |
49 | if (active_slide != -1 || delta > 0) { |
|
49 | if (active_slide != -1 || delta > 0) { | |
50 | active_slide += delta; |
|
50 | active_slide += delta; | |
51 | active_slide = Math.max(0, Math.min($slide_cells.length-1, active_slide)); |
|
51 | active_slide = Math.max(0, Math.min($slide_cells.length-1, active_slide)); | |
52 |
|
52 | |||
53 | var cell_element = $slide_cells[active_slide]; |
|
53 | var cell_element = $slide_cells[active_slide]; | |
54 | cell = $(cell_element).data('cell'); |
|
54 | cell = $(cell_element).data('cell'); | |
55 | this.notebook.select(this.notebook.find_cell_index(cell)); |
|
55 | this.notebook.select(this.notebook.find_cell_index(cell)); | |
56 |
|
56 | |||
57 | this.scroll_to(cell_element); |
|
57 | this.scroll_to(cell_element); | |
58 | //cell_element.scrollIntoView(true); |
|
58 | //cell_element.scrollIntoView(true); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | // Cancel browser keyboard scroll. |
|
61 | // Cancel browser keyboard scroll. | |
62 | return false; |
|
62 | return false; | |
63 |
|
63 | |||
64 | // No slides exist, scroll up or down one page height. Instead of using |
|
64 | // No slides exist, scroll up or down one page height. Instead of using | |
65 | // the browser's built in method to do this, animate it using jQuery. |
|
65 | // the browser's built in method to do this, animate it using jQuery. | |
66 | } else { |
|
66 | } else { | |
67 | this.scroll_some(delta); |
|
67 | this.scroll_some(delta); | |
68 | return false; |
|
68 | return false; | |
69 | } |
|
69 | } | |
70 | }; |
|
70 | }; | |
71 |
|
71 | |||
72 | ScrollManager.prototype.scroll_to = function(destination) { |
|
72 | ScrollManager.prototype.scroll_to = function(destination) { | |
73 | // Scroll to an element in the notebook. |
|
73 | // Scroll to an element in the notebook. | |
74 | $('#notebook').animate({'scrollTop': $(destination).offset().top + $('#notebook').scrollTop() - $('#notebook').offset().top}, this.animation_speed); |
|
74 | $('#notebook').animate({'scrollTop': $(destination).offset().top + $('#notebook').scrollTop() - $('#notebook').offset().top}, this.animation_speed); | |
75 | }; |
|
75 | }; | |
76 |
|
76 | |||
77 | ScrollManager.prototype.scroll_some = function(pages) { |
|
77 | ScrollManager.prototype.scroll_some = function(pages) { | |
78 | // Scroll up or down a given number of pages. |
|
78 | // Scroll up or down a given number of pages. | |
79 | $('#notebook').animate({'scrollTop': $('#notebook').scrollTop() + pages * $('#notebook').height()}, this.animation_speed); |
|
79 | $('#notebook').animate({'scrollTop': $('#notebook').scrollTop() + pages * $('#notebook').height()}, this.animation_speed); | |
80 | }; |
|
80 | }; | |
81 |
|
81 | |||
82 | // For convinience, add the ScrollManager class to the global namespace |
|
|||
83 | IPython.ScrollManager = ScrollManager; |
|
|||
84 | // Return naemspace for require.js loads |
|
82 | // Return naemspace for require.js loads | |
85 | return ScrollManager; |
|
83 | return ScrollManager; | |
86 |
|
||||
87 | }); |
|
84 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now