From 2cc3fc457281e452b37b705de74e4bb43b75e7e9 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 6 Nov 2016 22:04:31 -0800 Subject: [PATCH] Only activate `Catalog Hover Expand` when catalog is clicked. Deactivate on second click. #489 --- src/General/Get.coffee | 2 +- src/General/Index.coffee | 22 +++++++++++++--------- src/classes/Post.coffee | 1 + src/config/Config.coffee | 2 +- src/css/style.css | 5 +++++ 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/General/Get.coffee b/src/General/Get.coffee index 004011645..e51f70cc4 100644 --- a/src/General/Get.coffee +++ b/src/General/Get.coffee @@ -18,7 +18,7 @@ Get = index = root.dataset.clone if index then post.clones[index] else post postFromNode: (root) -> - Get.postFromRoot $.x '(ancestor::div[contains(@class,"postContainer")][1]|following::div[contains(@class,"postContainer")][1])', root + Get.postFromRoot $.x '(ancestor-or-self::div[contains(@class,"postContainer")][1]|following::div[contains(@class,"postContainer")][1])', root postDataFromLink: (link) -> if link.hostname is 'boards.4chan.org' path = link.pathname.split /\/+/ diff --git a/src/General/Index.coffee b/src/General/Index.coffee index ea35d0ce4..a6d24ff75 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -109,8 +109,8 @@ Index = # Thread container @root = $.el 'div', className: 'board json-index' + $.on @root, 'click', @cb.hoverToggle @cb.size() - @cb.hover() # Page list @pagelist = $.el 'div', className: 'pagelist json-index' @@ -278,9 +278,14 @@ Index = replies: -> Index.buildIndex() - hover: (e) -> - doc.classList.toggle 'catalog-hover-expand', Conf['Catalog Hover Expand'] - Index.cb.replies() if e and Conf['Show Replies'] and Conf['Catalog Hover Expand'] + hover: -> + $.rmClass doc, 'catalog-hover-expand' unless Conf['Catalog Hover Expand'] + + hoverToggle: (e) -> + if Conf['Catalog Hover Expand'] and !$.modifiedClick(e) and !$.x('ancestor-or-self::a', e.target) + $.toggleClass doc, 'catalog-hover-expand' + if (post = Get.postFromNode e.target) + Index.cb.hoverAdjust.call post.nodes popstate: (e) -> if e?.state @@ -315,13 +320,13 @@ Index = Index.update() catalogReplies: -> - $.off @, 'mouseover', Index.cb.catalogReplies - return unless Conf['Show Replies'] and Conf['Catalog Hover Expand'] and @parentNode + return unless Conf['Show Replies'] and $.hasClass(doc, 'catalog-hover-expand') + $.off @, 'mouseenter', Index.cb.catalogReplies Index.buildCatalogReplies Get.threadFromRoot @ hoverAdjust: -> # Prevent hovered catalog threads from going offscreen. - return unless Conf['Catalog Hover Expand'] + return unless $.hasClass(doc, 'catalog-hover-expand') rect = @post.getBoundingClientRect() if (x = $.minmax 0, -rect.left, doc.clientWidth - rect.right) {style} = @post @@ -852,8 +857,7 @@ Index = thread.OP.setCatalogOP true $.add thread.catalogView.nodes.root, thread.OP.nodes.root nodes.push thread.catalogView.nodes.root - if Conf['Show Replies'] and Conf['Catalog Hover Expand'] - $.on thread.catalogView.nodes.root, 'mouseover', Index.cb.catalogReplies + $.on thread.catalogView.nodes.root, 'mouseenter', Index.cb.catalogReplies $.on thread.OP.nodes.root, 'mouseenter', Index.cb.hoverAdjust.bind(thread.OP.nodes) $.add Index.root, nodes nodes diff --git a/src/classes/Post.coffee b/src/classes/Post.coffee index 92ff3c18f..fb05354e6 100644 --- a/src/classes/Post.coffee +++ b/src/classes/Post.coffee @@ -272,3 +272,4 @@ class Post @nodes.root.classList.toggle 'opContainer', !isCatalogOP @nodes.post.classList.toggle 'catalog-post', isCatalogOP @nodes.post.classList.toggle 'op', !isCatalogOP + @nodes.post.style.left = @nodes.post.style.right = null diff --git a/src/config/Config.coffee b/src/config/Config.coffee index 3a38e5985..28fc7512c 100644 --- a/src/config/Config.coffee +++ b/src/config/Config.coffee @@ -737,7 +737,7 @@ Config = 'Previous Index Mode': 'paged' 'Index Size': 'small' 'Show Replies': [true, 'Show replies in the index, and also in the catalog if "Catalog hover expand" is checked.'] - 'Catalog Hover Expand': [true, 'Expand the comment and show more details when you hover over a thread in the catalog.'] + 'Catalog Hover Expand': [true, 'Clicking in the catalog shows more details in the thread you are hovering over.'] 'Pin Watched Threads': [false, 'Move watched threads to the start of the index.'] 'Anchor Hidden Threads': [true, 'Move hidden threads to the end of the index.'] 'Refreshed Navigation': [false, 'Refresh index when navigating through pages.'] diff --git a/src/css/style.css b/src/css/style.css index 3afae29f1..a4348ac8d 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -760,6 +760,11 @@ div[data-checked="false"] > .suboption-list { border: 1px solid transparent; padding-top: 20px; } +/* overrides inline CSS from Index.cb.hoverAdjust */ +:root:not(.catalog-hover-expand) .catalog-post { + left: 0 !important; + right: 0 !important; +} /* overrides 4chan CSS on div.post */ .catalog-post.catalog-post { margin: -21px -1px -1px;