demarches-normaliennes/app/assets/javascripts/new_design/messagerie.js
2017-12-14 13:57:19 +01:00

24 lines
639 B
JavaScript

TPS.scrollMessagerie = function () {
var scrollTo = function ($container, $scrollTo) {
$container.scrollTop(
$scrollTo.offset().top - $container.offset().top + $container.scrollTop()
);
}
var scrollToBottom = function ($container) {
$container.scrollTop($container.prop('scrollHeight'));
}
var $ul = $(".messagerie ul").first();
if($ul.length) {
var $elementToScroll = $('.date.highlighted').first();
if ($elementToScroll.length != 0) {
scrollTo($ul, $elementToScroll);
} else {
scrollToBottom($ul);
}
}
};
document.addEventListener("turbolinks:load", TPS.scrollMessagerie);