0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Add scrollPointIntoView event for integrations.

This commit is contained in:
Neil Jenkins 2015-12-09 17:29:47 +11:00
parent 9ccf765ba8
commit 8b183c6ef6
3 changed files with 28 additions and 12 deletions

View file

@ -2424,22 +2424,30 @@ proto._createRange =
};
proto.scrollRangeIntoView = function ( range ) {
var win = this._win;
var top = range.getBoundingClientRect().top;
var height = win.innerHeight;
// Get the bounding rect
var rect = range.getBoundingClientRect();
var node, parent;
if ( !top ) {
if ( !rect.top ) {
node = this._doc.createElement( 'SPAN' );
range = range.cloneRange();
insertNodeInRange( range, node );
top = node.getBoundingClientRect().top;
rect = node.getBoundingClientRect();
parent = node.parentNode;
parent.removeChild( node );
parent.normalize();
}
// Then check and scroll
var win = this._win;
var height = win.innerHeight;
var top = rect.top;
if ( top > height ) {
win.scrollBy( 0, top - height + 20 );
}
// And fire event for integrations to use
this.fireEvent( 'scrollPointIntoView', {
x: rect.left,
y: top
});
};
proto._moveCursorTo = function ( toStart ) {

File diff suppressed because one or more lines are too long

View file

@ -302,22 +302,30 @@ proto._createRange =
};
proto.scrollRangeIntoView = function ( range ) {
var win = this._win;
var top = range.getBoundingClientRect().top;
var height = win.innerHeight;
// Get the bounding rect
var rect = range.getBoundingClientRect();
var node, parent;
if ( !top ) {
if ( !rect.top ) {
node = this._doc.createElement( 'SPAN' );
range = range.cloneRange();
insertNodeInRange( range, node );
top = node.getBoundingClientRect().top;
rect = node.getBoundingClientRect();
parent = node.parentNode;
parent.removeChild( node );
parent.normalize();
}
// Then check and scroll
var win = this._win;
var height = win.innerHeight;
var top = rect.top;
if ( top > height ) {
win.scrollBy( 0, top - height + 20 );
}
// And fire event for integrations to use
this.fireEvent( 'scrollPointIntoView', {
x: rect.left,
y: top
});
};
proto._moveCursorTo = function ( toStart ) {