Skip to content

Instantly share code, notes, and snippets.

View anova's full-sized avatar

Necat Bolpaça anova

View GitHub Profile
@anova
anova / custom-scrollbar.css
Created August 11, 2023 09:30
Custom scrollbar example
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-thumb {
background-color: black;
}
::-webkit-scrollbar-track {
box-shadow: inset 0 0 2px gray;
@anova
anova / .htaccess
Created August 9, 2023 13:23
Enforce SSL and www with one redirect. Change example.com with your domain.
# https://stackoverflow.com/a/36986520
RewriteEngine On
RewriteCond %{HTTP_HOST} example\.com$
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]
@anova
anova / cjs - search_term (q).js
Created August 8, 2023 11:12
Custom JavaScript Variable for GTM search_term query string
// cjs variable name: cjs - search_term (q)
function() {
var params = new URLSearchParams(window.location.search);
return params.get('q');
}
@anova
anova / createObserver.js
Created November 16, 2022 12:09
creates an Intersection Observer.
/** @return IntersectionObserver */
function createObserver(p_threshold) {
return new IntersectionObserver(
(entries) => {
entries.forEach((/** @type IntersectionObserverEntry */ entry) => {
if (entry.isIntersecting) {
const eventIntersecting = new CustomEvent("intersecting");
entry.target.dispatchEvent(eventIntersecting);
return;
}
@anova
anova / intersection-observer.js
Last active October 7, 2022 11:36
Trigger something when marked element's half percent is visible in viewport.
// define the observer
const observer = new IntersectionObserver((entries) => {
entries.forEach((/** @type IntersectionObserverEntry */ entry) => {
if (entry.isIntersecting) {
const eventIntersecting = new CustomEvent("intersecting");
entry.target.dispatchEvent(eventIntersecting);
return;
}
const eventNotIntersecting = new CustomEvent("not-intersecting");
entry.target.dispatchEvent(eventNotIntersecting);
@anova
anova / fetch-send-post-data.js
Created September 30, 2022 18:16
Send POST form data, serialized by FormData with fetch
const the_form = document.getElementById('the_form');
const formData = new FormData(the_form);
fetch('the-handler.php',{
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
console.log('data is:', data);
});
<style>
.instagram-link {
display: block;
background-image: linear-gradient(49.12deg, #fd5 6.61%, #FF543E 50.05%, #C837AB 93.49%);
border-radius: 50%;
width: 45px;
height: 45px;
}
</style>
@anova
anova / gtm-onscroll.js
Created July 4, 2022 08:30
A scroll trigger for Google Tag Manager
function documentScrolled() {
console.log('document is scrolled');
document.removeEventListener('scroll', documentScrolled);
}
document.addEventListener('scroll', documentScrolled);
<?php
// get_pages
$pages = get_pages( [
'child_of' => $id,
//'sort_column' => 'rand',
'sort_column' => 'menu_order',
'post_status' => 'publish,draft',
] );
// WP_Query
@anova
anova / breakpoint-event-handler.js
Created February 23, 2022 10:58
Trigger events by breakpoint change.
const breakpoint_lg = window.matchMedia('(min-width: 992px)');
breakpoint_lg.addEventListener('change', () => {
if(breakpoint_lg.matches) {
console.log('lg');
return;
}
console.log('not lg');
});