blob: 73c8f01705234501365be5156506cb95935b6ac0 [file] [log] [blame]
/***********************************************
* Horizontal panning for editable fields that
* overflow their width
**********************************************/
Controller.open(function(_) {
_.scrollHoriz = function() {
var cursor = this.cursor, seln = cursor.selection;
var rootRect = this.root.jQ[0].getBoundingClientRect();
if (!seln) {
var x = cursor.jQ[0].getBoundingClientRect().left;
if (x > rootRect.right - 20) var scrollBy = x - (rootRect.right - 20);
else if (x < rootRect.left + 20) var scrollBy = x - (rootRect.left + 20);
else return;
}
else {
var rect = seln.jQ[0].getBoundingClientRect();
var overLeft = rect.left - (rootRect.left + 20);
var overRight = rect.right - (rootRect.right - 20);
if (seln.ends[L] === cursor[R]) {
if (overLeft < 0) var scrollBy = overLeft;
else if (overRight > 0) {
if (rect.left - overRight < rootRect.left + 20) var scrollBy = overLeft;
else var scrollBy = overRight;
}
else return;
}
else {
if (overRight > 0) var scrollBy = overRight;
else if (overLeft < 0) {
if (rect.right - overLeft > rootRect.right - 20) var scrollBy = overRight;
else var scrollBy = overLeft;
}
else return;
}
}
this.root.jQ.stop().animate({ scrollLeft: '+=' + scrollBy}, 100);
};
});