Skip to content

Instantly share code, notes, and snippets.

@Nodws
Last active April 4, 2022 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nodws/8778622 to your computer and use it in GitHub Desktop.
Save Nodws/8778622 to your computer and use it in GitHub Desktop.
JQuery
(function (a, e, h, b, d) {
b = e.createElement(h);
b.src = "//www.googleadservices.com/pagead/conversion.js"; b.async=1;
d = e.getElementsByTagName(h)[0];
d.parentNode.insertBefore(b, d);
})(window, document, "script");
$('body').on('click','a[href*="pop-"]',function(e){
e.preventDefault();
var id = $(this).attr('href').split('#pop-')[1];
elementorProFrontend.modules.popup.showPopup({'id':id});
});
var wrap = $(".navbar");
$(document).scroll(function(e) {
if ($(this).scrollTop() > 247)
wrap.addClass("fixed");
else
wrap.removeClass("fixed");
});
$("#content").load("somefile.html");
setInterval(function() {
$("#refresh").load(location.href+" #refresh>*","");
}, 10000); // milliseconds to wait
String.prototype.str_replace = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
string.str_replace('needle','replaced');
var maxheight = 0;
$("div.col").each(function(){
if($(this).height() > maxheight) { maxheight = $(this).height(); }
});
$("div.col").height(maxheight);
if(location.hash){
var e = document.getElementById(location.hash.substr(1));
e.scrollIntoView();
}
$("a[href='#top']").click(function() {
//$("#section").offset().top
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
const updateDebounceText = debounce(() => {
incrementCount(debounceText)
})
const updateThrottleText = throttle(() => {
incrementCount(throttleText)
}, 100)
function debounce(cb, delay = 1000) {
let timeout
return (...args) => {
clearTimeout(timeout)
timeout = setTimeout(() => {
cb(...args)
}, delay)
}
}
function throttle(cb, delay = 1000) {
let shouldWait = false
let waitingArgs
const timeoutFunc = () => {
if (waitingArgs == null) {
shouldWait = false
} else {
cb(...waitingArgs)
waitingArgs = null
setTimeout(timeoutFunc, delay)
}
}
return (...args) => {
if (shouldWait) {
waitingArgs = args
return
}
cb(...args)
shouldWait = true
setTimeout(timeoutFunc, delay)
}
}
document.addEventListener("mousemove", e => {
incrementCount(defaultText)
updateDebounceText()
updateThrottleText()
})
function incrementCount(element) {
element.textContent = (parseInt(element.innerText) || 0) + 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment