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,16 +142,26 @@
} }
}); });
// 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({ $('.cms-tree a.jstree-clicked').entwine({
onmatch: function(){ onmatch: function(){
var self = this, var self = this,
panel = self.parents('.cms-panel-content'); panel = self.parents('.cms-panel-content'),
scrollTo;
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({ panel.animate({
scrollTop: self.offset().top - (panel.height() / 2) scrollTop: scrollTo
}, 'slow'); }, 'slow');
} }
}
}); });
}); });