##// END OF EJS Templates
Add ScrollManager to global ipy namespace in main.js instead of,...
Add ScrollManager to global ipy namespace in main.js instead of, in the bottom of the scroll manager js file.

File last commit:

r17868:7d0e0ec2
r17868:7d0e0ec2
Show More
scrollmanager.js
84 lines | 3.0 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Add scrollmanager
r17864 // Copyright (c) IPython Development Team.
// Distributed under the terms of the Modified BSD License.
define([], function(){
"use strict";
var ScrollManager = function (notebook) {
// Public constructor.
this.notebook = notebook;
Jonathan Frederic
Added smooth scroll to replace std browser behavior.
r17867 this.animation_speed = 250; //ms
Jonathan Frederic
Add scrollmanager
r17864 };
ScrollManager.prototype.scroll = function (delta) {
// Scroll the document.
//
// Parameters
// ----------
// delta: integer
// direction to scroll the document. Positive is downwards.
// If one or more slides exist, scroll to the slide.
var $slide_cells = $('.slideshow-slide');
if ($slide_cells.length > 0) {
var i, cell;
// Get the active slide cell index.
var selected_index = this.notebook.find_cell_index(this.notebook.get_selected_cell());
var active_slide = -1;
var cells = this.notebook.get_cells();
for (i = selected_index; i >= 0; i--) {
cell = cells[i];
var ns = cell.metadata.slideshow;
if (ns && ns.slide_type == 'slide') {
active_slide = i;
break;
}
}
// Translate cell index into slide cell index.
if (active_slide != -1) {
for (i = 0; i < $slide_cells.length; i++) {
if (cells[active_slide].element[0] == $slide_cells[i]) {
active_slide = i;
break;
}
}
}
// Scroll.
if (active_slide != -1 || delta > 0) {
active_slide += delta;
active_slide = Math.max(0, Math.min($slide_cells.length-1, active_slide));
var cell_element = $slide_cells[active_slide];
cell = $(cell_element).data('cell');
this.notebook.select(this.notebook.find_cell_index(cell));
this.scroll_to(cell_element);
//cell_element.scrollIntoView(true);
}
// Cancel browser keyboard scroll.
return false;
Jonathan Frederic
Added smooth scroll to replace std browser behavior.
r17867 // No slides exist, scroll up or down one page height. Instead of using
// the browser's built in method to do this, animate it using jQuery.
Jonathan Frederic
Add scrollmanager
r17864 } else {
Jonathan Frederic
Added smooth scroll to replace std browser behavior.
r17867 this.scroll_some(delta);
return false;
Jonathan Frederic
Add scrollmanager
r17864 }
};
ScrollManager.prototype.scroll_to = function(destination) {
Jonathan Frederic
Added smooth scroll to replace std browser behavior.
r17867 // Scroll to an element in the notebook.
$('#notebook').animate({'scrollTop': $(destination).offset().top + $('#notebook').scrollTop() - $('#notebook').offset().top}, this.animation_speed);
};
ScrollManager.prototype.scroll_some = function(pages) {
// Scroll up or down a given number of pages.
$('#notebook').animate({'scrollTop': $('#notebook').scrollTop() + pages * $('#notebook').height()}, this.animation_speed);
Jonathan Frederic
Add scrollmanager
r17864 };
// Return naemspace for require.js loads
return ScrollManager;
});