Skip to content

Instantly share code, notes, and snippets.

View KevinBatdorf's full-sized avatar
⚔️
I am undefined

Kevin Batdorf KevinBatdorf

⚔️
I am undefined
View GitHub Profile
@KevinBatdorf
KevinBatdorf / metaslider-dynamic-loading.php
Last active February 5, 2021 14:49
An mu-plugin to enable lazy loading on MetaSlider
<?php
// Add this to wp-content/mu-plugins/metaslider-dynamic-loading.php
// Update the id to include the slideshows you want to use
// Works best with "fade" transitions
$slideshow_id = ['34', '123'];
// $slideshow_id = ['34'];
// TODO: Accept a color background option and an optional loading icon.
@KevinBatdorf
KevinBatdorf / latest -toggl-tasks.php
Last active March 28, 2020 14:57
This will show your tasks for a particular workspace since Monday
<?php
$key = YOUR_API_KEY;
$workspace = '2385201'; // Your team workspace
$curl = curl_init();
if (!$curl) {
die("Couldn't initialize a cURL handle");
}
@KevinBatdorf
KevinBatdorf / wp-support-add-live-preview-userscript.js
Created March 8, 2020 21:12
Adds a live preview window for support on WP.org
// ==UserScript==
// @name WP Support Live Preview
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://wordpress.org/support/*
// @grant none
// ==/UserScript==
@KevinBatdorf
KevinBatdorf / remove-alpine-js-from-tailwind.js
Last active April 8, 2020 16:03
Filter unwanted AlpineJS attributes from Tailwind UI components
// ==UserScript==
// @name Filter unwanted AlpineJS attributes from Tailwind UI components
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remove Alpine JS code from Tailwind Ui copy/paste
// @author https://github.com/KevinBatdorf
// @match https://tailwindui.com/components/*
// @grant none
// ==/UserScript==
const code = document.querySelectorAll('[x-ref=clipboardCode]')
@KevinBatdorf
KevinBatdorf / add-alpine-js-to-tailwind-ui.js
Last active May 7, 2024 18:51
Auto copy the Alpine code from Tailwind UI's copy button
// ==UserScript==
// @name Add AlpineJs to Tailwind UI
// @namespace http://tampermonkey.net/
// @version 3.0
// @description Add Alpine JS code to Tailwind Ui copy/paste
// @author https://gist.github.com/KevinBatdorf/8bd5f808fff6a59e100dfa08a7431822
// @match https://tailwindui.com/components/*
// @grant none
// ==/UserScript==
@KevinBatdorf
KevinBatdorf / wordpress-add-keyboard-navigation-to-sub-menus.js
Last active July 22, 2020 16:00
Adds sub menu keyboard up/down navigation (only one level deep) using Alpine.js
Array.from(document.querySelectorAll('.menu-item-has-children')).forEach(menu => {
menu.setAttribute(
'x-data',
`{
usedKeyboard: false,
list: [],
start() {
this.list = this.$el.querySelectorAll("li")
}
}`
@KevinBatdorf
KevinBatdorf / wp-featherlight-metaslider-youtube.js
Created September 23, 2020 17:53
Add MetaSlider + Wp Featherlight Youtube compatability
window.jQuery(function($) {
$('div[class*=wp-featherlight] .youtube').each(function(index, video) {
window.addEventListener('load', function () {
setTimeout(function() {
$(video).data('lazyLoad', 0);
}, 1000);
});
$(video).wrap(
'<a data-featherlight-iframe-width="1920" '+
@KevinBatdorf
KevinBatdorf / truncate-helper-alpine.js
Last active November 15, 2020 06:53
Alpine JS Truncate helper
import { checkForAlpine } from './utils'
const AlpineTruncateMagicMethod = {
start() {
checkForAlpine()
Alpine.addMagicProperty('truncate', () => {
return (...parameters) => {
if (typeof parameters[0] !== 'string') return parameters[0]
@KevinBatdorf
KevinBatdorf / alpine-child-x-init.js
Last active January 22, 2021 19:11
AlpineJS Magic Helper to use x-init on child elements
// Demo; https://codepen.io/KevinBatdorf/pen/RwGEdpr?editors=1011
// Load in before you load Alpine
function AlpineAutoInitChildren() {
// Use: <div x-data x-init="$initChildren()">
Alpine.addMagicProperty('initChildren', ($el) => {
return () => {
// Grab all child x-init. Customize if you want to only run based on a specific condition
Array.from($el.querySelectorAll('[x-init]')).forEach(child => {
@KevinBatdorf
KevinBatdorf / add-easy-fancybox-videos-metaslider.php
Last active February 2, 2021 02:50
Add YouTube support to MetaSlider with Easy Fancybox
<?php
// Requires MS Lightbox
add_filter('metaslider_lightbox_supported_plugins', function ($attributes) {
return [
'Easy FancyBox' => [
'location' => 'easy-fancybox/easy-fancybox.php',
'settings_url' => 'options-media.php',
'rel' => 'lightbox',
]
];