aboutsummaryrefslogtreecommitdiff
path: root/static/fluoride.js
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-01-26 08:58:15 +0000
committerr <r@freesoftwareextremist.com>2020-01-26 08:58:15 +0000
commit04934ee643ea02667de7dbef09638b89fcce61db (patch)
treecb5743ceb5c451f6b45ef379aaffe1b0ffc936bc /static/fluoride.js
parented15e18b696f32f0512fd3123313889c3d72ef62 (diff)
downloadbloat-04934ee643ea02667de7dbef09638b89fcce61db.tar.gz
bloat-04934ee643ea02667de7dbef09638b89fcce61db.zip
Change link hover behaviour
Highlight div if the target status is inside the viewport and show popup otherwise.
Diffstat (limited to 'static/fluoride.js')
-rw-r--r--static/fluoride.js60
1 files changed, 42 insertions, 18 deletions
diff --git a/static/fluoride.js b/static/fluoride.js
index 3c0d7f2..6be61c0 100644
--- a/static/fluoride.js
+++ b/static/fluoride.js
@@ -112,47 +112,71 @@ function handleRetweetForm(id, f) {
}
}
-function handleReplyToLink(link) {
- if (!link) {
+function isInView(el) {
+ var ract = el.getBoundingClientRect();
+ if (ract.top > 0 && ract.bottom < window.innerHeight) {
+ return true;
+ }
+ return false;
+}
+
+function handleReplyToLink(div) {
+ if (!div) {
return;
}
- var id = link.firstElementChild.getAttribute('href');
+ var id = div.firstElementChild.getAttribute('href');
if (!id || id[0] != '#') {
return;
}
- link.onmouseenter = function(event) {
- var id = event.target.firstElementChild.getAttribute('href');
+ div.firstElementChild.onmouseenter = function(event) {
+ var id = event.target.getAttribute('href');
var status = document.querySelector(id);
if (!status) {
return;
}
- var copy = status.cloneNode(true);
- copy.id = "reply-to-popup";
- link.appendChild(copy);
+ if (isInView(status)) {
+ status.classList.add("highlight");
+ } else {
+ var copy = status.cloneNode(true);
+ copy.id = "reply-to-popup";
+ event.target.parentElement.appendChild(copy);
+ }
}
- link.onmouseleave = function(event) {
+ div.firstElementChild.onmouseleave = function(event) {
var popup = document.getElementById("reply-to-popup");
if (popup) {
- event.target.removeChild(popup);
+ event.target.parentElement.removeChild(popup);
+ } else {
+ var id = event.target.getAttribute('href');
+ document.querySelector(id)
+ .classList.remove("highlight");
}
}
}
-function handleReplyLink(link) {
- link.onmouseenter = function(event) {
- var id = event.target.firstElementChild.getAttribute('href');
+function handleReplyLink(div) {
+ div.firstElementChild.onmouseenter = function(event) {
+ var id = event.target.getAttribute('href');
var status = document.querySelector(id);
if (!status) {
return;
}
- var copy = status.cloneNode(true);
- copy.id = "reply-popup";
- link.appendChild(copy);
+ if (isInView(status)) {
+ status.classList.add("highlight");
+ } else {
+ var copy = status.cloneNode(true);
+ copy.id = "reply-popup";
+ event.target.parentElement.appendChild(copy);
+ }
}
- link.onmouseleave = function(event) {
+ div.firstElementChild.onmouseleave = function(event) {
var popup = document.getElementById("reply-popup");
if (popup) {
- event.target.removeChild(popup);
+ event.target.parentElement.removeChild(popup);
+ } else {
+ var id = event.target.getAttribute('href');
+ document.querySelector(id)
+ .classList.remove("highlight");
}
}
}