Skip to content

Commit

Permalink
Condensed share/passive-share badge listener assignements into one fu…
Browse files Browse the repository at this point in the history
…nction
  • Loading branch information
maxxcrawford committed Dec 26, 2019
1 parent 5480dae commit 6d0df08
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions src/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,48 +227,12 @@ function addFacebookBadge (target, badgeClassUId, socialAction) {
} else if (socialAction === "share-passive") {
htmlBadgeDiv.classList.add("fbc-badge-share-passive", "fbc-badge-share");

target.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
});

target.addEventListener("mouseover", () => {
// console.log(["mouseover", target, htmlBadgeDiv]);
target.classList.add("fbc-badge-tooltip-active");
htmlBadgeDiv.classList.add("fbc-badge-tooltip-active");
setTimeout( ()=> {
positionPrompt( htmlBadgeDiv );
}, 50 );
});

target.addEventListener("mouseout", () => {
// console.log(["mouseout", target, htmlBadgeDiv]);
target.classList.remove("fbc-badge-tooltip-active");
htmlBadgeDiv.classList.remove("fbc-badge-tooltip-active");
});
shareBadgeEventListenerInit(target, htmlBadgeDiv);

} else if (socialAction === "share") {
htmlBadgeDiv.classList.add("fbc-badge-share");

target.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
});

target.addEventListener("mouseover", () => {
// console.log(["mouseover", target, htmlBadgeDiv]);
target.classList.add("fbc-badge-tooltip-active");
htmlBadgeDiv.classList.add("fbc-badge-tooltip-active");
setTimeout( ()=> {
positionPrompt( htmlBadgeDiv );
}, 50 );
});

target.addEventListener("mouseout", () => {
// console.log(["mouseout", target, htmlBadgeDiv]);
target.classList.remove("fbc-badge-tooltip-active");
htmlBadgeDiv.classList.remove("fbc-badge-tooltip-active");
});
shareBadgeEventListenerInit(target, htmlBadgeDiv);

}

Expand All @@ -279,6 +243,29 @@ function addFacebookBadge (target, badgeClassUId, socialAction) {

}

// Add Event Listener actions/hooks to share badges
function shareBadgeEventListenerInit(target, htmlBadgeDiv) {
target.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
});

target.addEventListener("mouseover", () => {
// console.log(["mouseover", target, htmlBadgeDiv]);
target.classList.add("fbc-badge-tooltip-active");
htmlBadgeDiv.classList.add("fbc-badge-tooltip-active");
setTimeout( ()=> {
positionPrompt( htmlBadgeDiv );
}, 50 );
});

target.addEventListener("mouseout", () => {
// console.log(["mouseout", target, htmlBadgeDiv]);
target.classList.remove("fbc-badge-tooltip-active");
htmlBadgeDiv.classList.remove("fbc-badge-tooltip-active");
});
}

function findActivePrompt() {
const allBadges = document.querySelectorAll(".fbc-badge.active");
for (let badge of allBadges) {
Expand Down

0 comments on commit 6d0df08

Please sign in to comment.