2018-02-28 16:07:52 +01:00
|
|
|
DS.scrollMessagerie = function () {
|
2017-12-05 17:20:10 +01:00
|
|
|
var scrollTo = function ($container, $scrollTo) {
|
|
|
|
$container.scrollTop(
|
|
|
|
$scrollTo.offset().top - $container.offset().top + $container.scrollTop()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var scrollToBottom = function ($container) {
|
|
|
|
$container.scrollTop($container.prop('scrollHeight'));
|
|
|
|
}
|
|
|
|
|
2017-09-08 16:54:25 +02:00
|
|
|
var $ul = $(".messagerie ul").first();
|
|
|
|
if($ul.length) {
|
2017-12-05 17:20:10 +01:00
|
|
|
var $elementToScroll = $('.date.highlighted').first();
|
|
|
|
|
|
|
|
if ($elementToScroll.length != 0) {
|
|
|
|
scrollTo($ul, $elementToScroll);
|
|
|
|
} else {
|
|
|
|
scrollToBottom($ul);
|
|
|
|
}
|
2017-09-08 16:54:25 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-28 16:07:52 +01:00
|
|
|
document.addEventListener("turbolinks:load", DS.scrollMessagerie);
|