From bc86f21c24fe635901fb4275d87a0c9d6773dcd9 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Wed, 20 Apr 2016 09:52:51 -0700 Subject: [PATCH] Make menu reposition on scroll instead of closing. --- src/General/UI.coffee | 46 +++++++++++++++--------------- src/Monitoring/ReplyPruning.coffee | 2 -- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/General/UI.coffee b/src/General/UI.coffee index 700136650..960402825 100644 --- a/src/General/UI.coffee +++ b/src/General/UI.coffee @@ -65,31 +65,11 @@ class Menu $.addClass lastToggledButton, 'active' $.on d, 'click CloseMenu', @close - $.on d, 'scroll', @close unless @type is 'gallery' + $.on d, 'scroll', @setPosition + $.on window, 'resize', @setPosition $.add button, menu - # Position - mRect = menu.getBoundingClientRect() - bRect = button.getBoundingClientRect() - bTop = window.scrollY + bRect.top - bLeft = window.scrollX + bRect.left - cHeight = doc.clientHeight - cWidth = doc.clientWidth - [top, bottom] = if bRect.top + bRect.height + mRect.height < cHeight - [bRect.bottom, null] - else - [null, cHeight - bRect.top] - [left, right] = if bRect.left + mRect.width < cWidth - [bRect.left, null] - else - [null, cWidth - bRect.right] - {style} = menu - style.top = "#{top}px" - style.right = "#{right}px" - style.bottom = "#{bottom}px" - style.left = "#{left}px" - if right - $.addClass menu, 'left' + @setPosition() entry = $ '.entry', menu # We've removed flexbox, so we don't use order anymore. @@ -99,6 +79,24 @@ class Menu menu.focus() + setPosition: => + mRect = @menu.getBoundingClientRect() + bRect = lastToggledButton.getBoundingClientRect() + bTop = window.scrollY + bRect.top + bLeft = window.scrollX + bRect.left + cHeight = doc.clientHeight + cWidth = doc.clientWidth + [top, bottom] = if bRect.top + bRect.height + mRect.height < cHeight + ["#{bRect.bottom}px", ''] + else + ['', "#{cHeight - bRect.top}px"] + [left, right] = if bRect.left + mRect.width < cWidth + ["#{bRect.left}px", ''] + else + ['', "#{cWidth - bRect.right}px"] + $.extend @menu.style, {top, right, bottom, left} + @menu.classList.toggle 'left', right + insertEntry: (entry, parent, data) -> if typeof entry.open is 'function' try @@ -128,6 +126,8 @@ class Menu currentMenu = null lastToggledButton = null $.off d, 'click scroll CloseMenu', @close + $.off d, 'scroll', @setPosition + $.off window, 'resize', @setPosition findNextEntry: (entry, direction) -> entries = [entry.parentNode.children...] diff --git a/src/Monitoring/ReplyPruning.coffee b/src/Monitoring/ReplyPruning.coffee index effe0e26a..ea7a713ee 100644 --- a/src/Monitoring/ReplyPruning.coffee +++ b/src/Monitoring/ReplyPruning.coffee @@ -95,8 +95,6 @@ ReplyPruning = # Record position from bottom of document oldPos = d.body.clientHeight - window.scrollY - # Prevent header menu from closing due to scroll - $.off d, 'scroll', Header.menu.close if Header.menu.menu {posts} = ReplyPruning.thread