demarches-normaliennes/app/assets/javascripts/new_design/messagerie.js
2018-03-01 10:33:53 +01:00

24 lines
637 B
JavaScript

DS.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", DS.scrollMessagerie);