Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nocodesupplyco's full-sized avatar

No-Code Supply Co nocodesupplyco

View GitHub Profile
@nocodesupplyco
nocodesupplyco / hide-section-with-empty-collection.css
Created April 2, 2024 16:31
Hide Static Section if Child Webflow Collection is Empty
/* Give section an attribute of "data-cms-section" */
[data-cms-section]:not(:has(.w-dyn-item)) {
display: none;
}
@nocodesupplyco
nocodesupplyco / set-canonical-if-pagination.js
Created January 9, 2024 19:52
Set canonical to match pagination if using Webflow pagination
// Original code source and use agreement here: https://gist.github.com/rileyrichter/b2e5b5d9fe8952372ce49fafc75dea8b
const canonical = document.querySelector('link[rel="canonical"]');
const urlParams = new URLSearchParams(window.location.search);
const paginationParam = Array.from(urlParams.entries()).find(([key]) =>
/^[a-z0-9]{8}_page$/.test(key)
);
if (paginationParam) {
const canonical = document.querySelector('link[rel="canonical"]');
@nocodesupplyco
nocodesupplyco / show-preloader-once.js
Last active January 3, 2024 20:17
Show a Preloader Once Per Day
// Target the preloader element
const preloaderElement = document.getElementById('preloader');
// Set the amount of time to wait in milliseconds
// Test by changing to 1 * 60 * 1000 for 1 min
const waitTime = 24 * 60 * 60 * 1000; // 24 hours
// Check if the local storage item is present and valid
if (!localStorage.getItem('preloaderShown') || Date.now() - localStorage.getItem('preloaderShown') >
waitTime) {
@nocodesupplyco
nocodesupplyco / email-input-validation.js
Created December 15, 2023 21:43
Email Input Validation
// Validate email field for only business emails
document.addEventListener("DOMContentLoaded", function () {
// UPDATE THIS - ID on the <form>
let form = document.getElementById("pardot-form");
// UPDATE THIS - ID on text element to display errors
let errorElement = document.getElementById("email-domain-error");
form.addEventListener("submit", function (event) {
// UPDATE THIS - ID on the email <input>
let emailInput = document.getElementById("email");
@nocodesupplyco
nocodesupplyco / dark-light-mode-favicon.html
Created September 12, 2023 16:45
Dark/Light Mode Favicon
<!-- Place this in the <head> and update the href to your images for each color mode -->
<link href="favicon-light.png" rel="icon" media="(prefers-color-scheme: light)" />
<link href="favicon-dark.png" rel="icon" media="(prefers-color-scheme: dark)" />
@nocodesupplyco
nocodesupplyco / remove-http.js
Last active November 4, 2023 01:29
Remove https:// from text link
// See test example of this here: https://codepen.io/cmoen89/pen/Baxdwxe?editors=1010
$(function () {
$( "a[data-clean='remove-http']" ).each(function() {
var clean = $(this).text().replace(/^\/\/|^.*?:(\/\/)?/, '');
$(this).text(clean);
});
});
@nocodesupplyco
nocodesupplyco / responsive-script.js
Created July 26, 2023 01:29
Only run some javascript when the browser is 767px or smaller.
function responsiveScript() {
// only run script below 767 px screen width
if (window.innerWidth <= 767) {
// do something awesome on mobile only here
}
}
// run script on page load
responsiveScript();
// run script on window resize
window.addEventListener("resize", responsiveScript);
@nocodesupplyco
nocodesupplyco / skip-nav.js
Created June 14, 2023 13:55
Skip Nav to Main Function
window.addEventListener("DOMContentLoaded", (event) => {
let skipLinkEle = document.getElementById("skip-link");
if (!skipLinkEle) {
return;
}
skipLinkEle.addEventListener("click keydown", function (e) {
if (e.type === "keydown" && e.which !== 13) {
return;
}
@nocodesupplyco
nocodesupplyco / aspect-ratio.css
Created December 16, 2022 18:36
CSS Aspect Ratio
/* Set aspect ratio on an element/class */
.div {
aspect-ratio: 16 / 9;
}
/* Minimum aspect ratio */
@media (min-aspect-ratio: 8/5) {
div {
background: #9af; /* blue */
}
@nocodesupplyco
nocodesupplyco / input-value-to-url.js
Created December 13, 2022 16:12
Redirect Form on Submit and Pass Input Value to URL
$(function() {
//run when form submits - ID must be on the <form> element!
$("#your-form").submit(function(event) {
//store email input value
var emailValue = $("#email").val();
//redirect to sign up
window.location.replace("example.com/signup?email=" + emailValue);