From 77ec5bcff99e7a5a9d922a52ee54c0b942cc374e Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 30 Aug 2016 11:39:50 +0200 Subject: [PATCH] Reposition comment dropdowns horizontally if needed Closes SCI-258 --- app/assets/javascripts/comments.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/assets/javascripts/comments.js b/app/assets/javascripts/comments.js index 62fb1c5c3..02b3e5a8d 100644 --- a/app/assets/javascripts/comments.js +++ b/app/assets/javascripts/comments.js @@ -1,6 +1,20 @@ function initCommentOptions(scrollableContainer, useParentOffset = true) { scrollCommentOptions($(".dropdown-comment"), useParentOffset); + // Reposition dropdown to the left + // (only do this when using parent offset) + if (useParentOffset) { + $(document).on("shown.bs.dropdown", ".dropdown-comment", function() { + var $el = $(this); + var menu = $el.find(".dropdown-menu"); + var leftPos = $el.offset().left; + if (leftPos + menu.width() > $(window).width()) { + menu.offset({ left: leftPos - menu.width() }); + } + }); + } + + // Reposition dropdowns vertically on scroll events document.addEventListener('scroll', function (event) { var $target = $(event.target); var parent = $(scrollableContainer);