Merge pull request #871 from simonwelsh/3.1-scroll

Calculate where to scroll to based off the position in the div
This commit is contained in:
Ingo Schommer 2013-10-10 03:48:24 -07:00
commit b08c70748f

View File

@ -142,17 +142,27 @@
}
});
// Scroll tree down to context of the current page
// Scroll tree down to context of the current page, if it isn't
// already visible
$('.cms-tree a.jstree-clicked').entwine({
onmatch: function(){
var self = this,
panel = self.parents('.cms-panel-content');
onmatch: function(){
var self = this,
panel = self.parents('.cms-panel-content'),
scrollTo;
panel.animate({
scrollTop: self.offset().top - (panel.height() / 2)
}, 'slow');
}
});
if(self.offset().top < 0 ||
self.offset().top > panel.height() - self.height()) {
// Current scroll top + our current offset top is our
// position in the panel
scrollTo = panel.scrollTop() + self.offset().top
+ (panel.height() / 2);
panel.animate({
scrollTop: scrollTo
}, 'slow');
}
}
});
});
}(jQuery));