Last active
July 29, 2020 14:45
-
-
Save stevegardiner26/e85928aa180c927c8327fd72cb064534 to your computer and use it in GitHub Desktop.
Helpscout Beacon Button Hiding Elements? Use this to allow users to temporarily close the beacon button overlay. Embed this gist anywhere in your document and it will add the close button giving your users the ability to hide it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('load', function () { | |
// We wait for the window to load otherwise to make sure the beacon script is loaded | |
window.Beacon('on', 'ready', function () { | |
// Set the background color and icon color, (Works best with the same colors as the beacon) | |
var background_color = "rgb(97, 125, 236)"; | |
// Icon color usually works best as rgb(57, 73, 86) with a light background or #ffffff with a dark background | |
var icon_color = "#ffffff"; | |
var button = document.getElementsByClassName('BeaconFabButtonFrame')[0]; | |
var close = document.createElement("div"); | |
close.innerHTML = '<svg width="14" height="14" ' + | |
'style="position:relative;display:block;top:50%;transform:translateY(-50%);left:33px;">' + | |
'<path d="M13.707.293a.999.999 0 0 0-1.414 0L7 5.586 1.707.293A.999.999 0 1 0 .293 1.707L5.586 7 .293 ' + | |
'12.293a.999.999 0 1 0 1.414 1.414L7 8.414l5.293 5.293a.997.997 0 0 0 1.414 0 .999.999 0 0 0 0-1.414L8.414 ' + | |
'7l5.293-5.293a.999.999 0 0 0 0-1.414" fill="' + icon_color + '" fill-rule="evenodd"></path></svg>'; | |
// This allows the destroy button to look decent in icon only mode where there isn't much room to hide the button | |
var iconOnly = button.clientHeight === button.clientWidth; | |
if (iconOnly) close.style.display = "none"; | |
// Apply Button Styles | |
close.style.position = "absolute"; | |
close.style.width = button.clientHeight + "px"; | |
close.style.height = button.clientHeight + "px"; | |
close.style.left = (button.clientHeight - 28) + "px"; | |
close.style.top = "0"; | |
close.style.transition = "left .5s"; | |
close.style.background = background_color; | |
close.style.border = "1px solid rgba(0,0,0,.2)" | |
close.style.borderTopRightRadius = "50%"; | |
close.style.borderBottomRightRadius = "50%"; | |
close.style.cursor = "pointer"; | |
close.style.zIndex = "-1"; | |
button.onmouseenter = function () { | |
close.style.left = (button.clientWidth - 28) + "px"; | |
if (iconOnly) close.style.display = "block"; | |
}; | |
button.onmouseleave = function () { | |
close.style.left = (button.clientHeight - 28) + "px"; | |
if (iconOnly) close.style.display = "none"; | |
}; | |
close.onclick = function () { | |
window.Beacon('destroy'); | |
}; | |
button.appendChild(close); | |
}); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a Preview of what the beacon button looks like when hovered if you use this code. The beacon will come back if you refresh the page so it only temporarily hides the button.
![Screen Shot 2020-07-29 at 10 44 52 AM](https://user-images.githubusercontent.com/28448895/88814795-91cb5200-d188-11ea-912c-cd40cc7d23ab.png)