Skip to content

Instantly share code, notes, and snippets.

@geoaxis
Last active February 10, 2023 15:25
Show Gist options
  • Save geoaxis/480db39f7bc7070edd8905d8448e0c7b to your computer and use it in GitHub Desktop.
Save geoaxis/480db39f7bc7070edd8905d8448e0c7b to your computer and use it in GitHub Desktop.
Add copy links to elements dynamically when page loads (for doc360)
.product-help-section {
background: #3d1177 url(https://doc360-dev-cdn.azureedge.net/39a4a157-6e9f-426c-832b-c9b83cfcfdc0/Images/Documentation/help-section-bg.jpg) top center no-repeat;
color: #fff;
padding: 35px 0px;
text-align: center;
position: relative;
}
.product-help-section .product-help-section-title {
margin-bottom: 10px;
font-size: 1.6rem;
}
.product-help-section .product-help-section-des {
margin-bottom: 25px;
font-size: 1.1rem;
font-weight: 300;
}
.product-help-section a {
display: inline-block;
border: 1px solid #fff;
border-radius: 2px;
color: #fff;
font-weight: 600;
font-size: .95rem;
padding: .70rem 1.25rem;
margin: 0px 10px 0px 0px;
vertical-align: middle;
text-align: center;
cursor: pointer;
text-decoration: none;
line-height: 1;
transition: all .3s ease;
text-transform: uppercase;
}
.product-help-section a:hover {
background: #fff;
color: #3d1177;
text-decoration: none;
}
.product-help-link-section {
background: #f3f0f8;
padding: 50px 0px;
position: relative;
}
.product-help-link-section .product-help-link-section-title {
margin-bottom: 10px;
font-size: 1.6rem;
text-align: center;
}
.product-help-link-section ul.help-links {
padding: 0px;
margin: 0px;
list-style: none;
display: flex;
justify-content: space-between;
}
.product-help-link-section ul.help-links li {
margin: 0px;
padding: 25px;
text-align: center;
flex: 0 0 28%;
background: #FFF;
border-radius: 3px;
box-shadow: rgba(0, 0, 0, .1) 0 0 8px;
}
.product-help-link-section ul.help-links li .help-link-icon {
margin: 0 auto;
padding: 0px;
width: 200px;
height: 135px;
background: url(https://doc360-dev-cdn.azureedge.net/39a4a157-6e9f-426c-832b-c9b83cfcfdc0/Images/Documentation/quick-link-icon-bg.jpg);
}
.product-help-link-section ul.help-links li .help-link-icon.chart {
background-position: 0 0;
}
.product-help-link-section ul.help-links li .help-link-icon.email {
background-position: -183px 0px;
}
.product-help-link-section ul.help-links li .help-link-icon.telephone {
background-position: -388px 0px;
}
.product-help-link-section .product-help-link-section-title {
margin-bottom: 40px;
font-size: 2.2rem;
font-weight: 600;
color: #5a5a5a;
text-align: center;
}
.product-help-link-section ul.help-links li .help-link-title {
font-size: 1.3rem;
font-weight: 600;
padding: 10px 0px;
}
.product-help-link-section ul.help-links li .help-link-des {
font-size: .9rem;
line-height: 1.5;
color: #666666;
padding: 0 30px;
}
hr {
border: none;
border-bottom: #000 dashed 1px;
margin: 15px 0px;
}
.content_block .content_container .content_block_text blockquote {
padding: 0px 0px;
margin: 0px 0px 1rem 0px;
border-left: 0px solid #ddd;
color: grey;
font-weight: 400;
font-size: 11pt;
}
.content_block .content_container .content_block_text b,
.content_block .content_container .content_block_text strong {
font-weight: bolder;
color: black;
font-size: 12pt;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}
.content_block .content_container .content_block_text {
display: block;
font-size: 0.9rem;
line-height: 1.8em;
letter-spacing: 0.05em;
word-break: break-word;
word-wrap: break-word;
}
.errorBox {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border-radius: 5px;
background: #DCE2E6;
color: slategrey;
}
.errorBox .title {
font-weight: normal;
}
.footer-theme-b .f-top .footer-left-section .w-25 {
width: 25%;
float: right !important;
}
.footer-theme-b .f-top .brand-description {
font-size: 0.8125rem;
margin: 0px;
padding: 10px 75px 19px 0px !important;
line-height: 1.5;
color: #929292;
font-weight: bolder;
}
h1 {
font-size: 1.65rem !important;
}
h2 {
font-size: 1.45rem !important;
}
h3 {
font-size: 1.15rem !important;
}
h4 {
font-size: 1.05rem !important;
}
.self-login-container-out .self-login-container .sso-login-link {
padding: 6px;
background: #f1f1f1;
display: flex;
justify-content: center;
align-items: center;
color: #464646;
text-align: center;
border-radius: 2px;
text-decoration: none;
font-size: .9375rem;
height: 38px;
flex: 0 0 98%;
display: none important !;
}
.sperator.sperator-top hr {
display: none
}
.content_block_text img[data-lightbox=box] {
cursor: default;
pointer-events: none;
margin-bottom: 4px;
}
.content_block .content_container .content_block_text b,
.content_block .content_container .content_block_text strong {
font-weight: bold;
color: black;
font-size: 11pt;
}
.left_sidebar .left_sidebar_nav ul a[data-option=off] .article-title,
.left_sidebar .left_sidebar_nav ul a[data-option=on] .article-title {
font-weight: 550;
}
#snackbar {
visibility: hidden;
/* Hidden by default. Visible on click */
min-width: 250px;
/* Set a default minimum width */
margin-left: -125px;
/* Divide value of min-width by 2 */
background-color: #333;
/* Black background color */
color: #fff;
/* White text color */
text-align: center;
/* Centered text */
border-radius: 2px;
/* Rounded borders */
padding: 16px;
/* Padding */
position: fixed;
/* Sit on top of the screen */
z-index: 1;
/* Add a z-index if needed */
left: 50%;
/* Center the snackbar */
bottom: 30px;
/* 30px from the bottom */
}
/* Show the snackbar when clicking on a button (class added with JavaScript) */
#snackbar.show {
visibility: visible;
/* Show the snackbar */
/* Add animation: Take 0.5 seconds to fade in and out the snackbar.
However, delay the fade out process for 2.5 seconds */
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
/* Animations to fade the snackbar in and out */
@-webkit-keyframes fadein {
from {
bottom: 0;
opacity: 0;
}
to {
bottom: 30px;
opacity: 1;
}
}
@keyframes fadein {
from {
bottom: 0;
opacity: 0;
}
to {
bottom: 30px;
opacity: 1;
}
}
@-webkit-keyframes fadeout {
from {
bottom: 30px;
opacity: 1;
}
to {
bottom: 0;
opacity: 0;
}
}
@keyframes fadeout {
from {
bottom: 30px;
opacity: 1;
}
to {
bottom: 0;
opacity: 0;
}
}
.copy-button {
font-size: 0.8rem;
padding: 10px;
cursor: pointer;
}
.copy-button: {
background-color: #59C27C;
;
}
[data-title] {
outline: red dotted 1px;
/*optional styling*/
font-size: 30px;
/*optional styling*/
position: relative;
cursor: help;
}
[data-title]:hover::before {
content: attr(data-title);
position: absolute;
bottom: -26px;
display: inline-block;
padding: 3px 6px;
border-radius: 2px;
background: #ddd;
color: #000;
font-size: 12px;
font-family: sans-serif;
white-space: nowrap;
}
[data-title]:hover::after {
content: '';
position: absolute;
bottom: -10px;
left: 8px;
display: inline-block;
color: #ddd;
border: 8px solid transparent;
border-bottom: 8px solid #ddd;
}
//copied from https://www.w3schools.com/howto/howto_js_snackbar.asp
function toast() {
// Get the snackbar DIV
var x = document.getElementById("snackbar");
// Add the "show" class to DIV
x.className = "show";
// After 3 seconds, remove the show class from DIV
setTimeout(function () {
x.className = x.className.replace("show", "");
}, 3000);
}
//copied from https://stackoverflow.com/questions/12243661/javascript-use-xpath-in-jquery
$.fn.xpathEvaluate = function (xpathExpression) {
// NOTE: vars not declared local for debug purposes
$this = this.first(); // Don't make me deal with multiples before coffee
// Evaluate xpath and retrieve matching nodes
xpathResult = this[0].evaluate(xpathExpression, this[0], null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
result = [];
while (elem = xpathResult.iterateNext()) {
result.push(elem);
}
$result = jQuery([]).pushStack(result);
return $result;
}
//a simple script that takes all elements of interest that don't have an id, tags them,
//then find all the elements of interest that do have an id , uses that id to create a link
// and then finally at the end scrolls to the # passed in url, that was already present or just dynamically created
//this script will create different URLs if code elements or headings change. So older URLs will not function
//This means that removing elements or changing them would result in broken links. Use accordingly.
$(document).ready(function () {
//add a hidden snack notification
$snack = $('<div id="snackbar">Link copied..</div>').appendTo('body');
//find all code-items , tag them, make sure we do'nt have colon as URL encoded. Space is turned to _
$(document).xpathEvaluate('//blockquote/p/strong').each(function () {
$(this).attr('id', 'code-item-' + encodeURIComponent($(this).text().replace(/ /g, '_').replace(/\:/g, '-')));
});
$("h2:not([id]),h3:not([id]),h4:not([id])").each(function () {
//make sure we dont have question marks as URL encoded. Space is turned to _
$(this).attr('id', encodeURIComponent($(this).text().replace(/ /g, '_').replace(/\?/g, '-Q')));
});
$("strong[id], h2[id], h3[id], h4[id]").each(function () {
if($(this).parent().attr('class') != 'category-r'){
var link = '"' + location.href.split(/\?|#/)[0] + '#' + $(this).attr('id') + '"';
$(this).wrap("<div class='element-with-link'></div>");
$(this).append(
"<span onclick='navigator.clipboard.writeText(" + link + "); toast();' style='padding=10px'>" +
" <div class='fal fa-link fa-2xs copy-button' aria-hidden='true'></div>" +
"</span>");
}
});
//scroll to what was given in the url
if (window.location?.hash) {
location.hash = window.location.hash
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment