Skip to content

Instantly share code, notes, and snippets.

View lucas-pelton's full-sized avatar

Lucas Pelton lucas-pelton

View GitHub Profile
@lucas-pelton
lucas-pelton / waitForObject.js
Created November 30, 2022 16:46
Wait for an object to be available in the DOM
var waitForJQuery = setInterval(function () {
if (typeof jQuery != 'undefined') {
//your code here
clearInterval(waitForJQuery);
}
}, 10);
@lucas-pelton
lucas-pelton / arrive.js
Created November 30, 2022 16:43
Wait for an element in the DOM
/*
* arrive.js
* v2.4.1
* https://github.com/uzairfarooq/arrive
* MIT licensed
*
* Copyright (c) 2014-2017 Uzair Farooq
*/
var Arrive = function (e, t, n) { "use strict"; function r(e, t, n) { l.addMethod(t, n, e.unbindEvent), l.addMethod(t, n, e.unbindEventWithSelectorOrCallback), l.addMethod(t, n, e.unbindEventWithSelectorAndCallback); } function i(e) { e.arrive = f.bindEvent, r(f, e, "unbindArrive"), e.leave = d.bindEvent, r(d, e, "unbindLeave"); } if (e.MutationObserver && "undefined" != typeof HTMLElement) { var o = 0, l = function () { var t = HTMLElement.prototype.matches || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.mozMatchesSelector || HTMLElement.prototype.msMatchesSelector; return { matchesSelector: function (e, n) { return e instanceof HTMLElement && t.call(e, n); }, addMethod: function (e, t, r) { var i = e[t]; e[t] = function () { return r.length == arguments.length ? r.apply(this, arguments) : "function" == typeof i ? i.appl
@lucas-pelton
lucas-pelton / resize-images.js
Created November 20, 2021 15:12
Size all selected images to similar visual gravity
/*********
*
* resize logos in custom galleries.
*
*/
window.addEventListener("load", function() {
var images = document.querySelectorAll(".custom-gallery img");
var adjustImageWidth = function (image) {
var widthBase = 250;
@lucas-pelton
lucas-pelton / get_original_images.php
Created March 19, 2020 19:23
Create array of uploaded images in WP Media Library
// https://wordpress.stackexchange.com/questions/243697/zip-all-original-images-from-media-gallery
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => - 1,
);
$query_images = new WP_Query( $query_images_args );
@lucas-pelton
lucas-pelton / main.js
Created October 20, 2019 14:10
CloudFlare worker promise race boilerplate
response = await Promise.race([
fetch('https://possibly.slow.io/' + options.token + '/get', {
method: 'POST',
body: JSON.stringify(data),
}),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), options.timeout)
),
])
@lucas-pelton
lucas-pelton / async.js
Created October 18, 2019 23:11
"Synchronous" fetch with async/await
const request = async () => {
const response = await fetch('https://api.com/values/1');
const json = await response.json();
console.log(json);
}
request();
// https://dev.to/johnpaulada/synchronous-fetch-with-asyncawait
@lucas-pelton
lucas-pelton / bash.sh
Created June 29, 2019 04:40
Cloudways npm path config
npm config set prefix "/home/master/bin/npm/lib/node_modules"
@lucas-pelton
lucas-pelton / custom-fonts.php
Created May 3, 2019 18:38 — forked from jamesdixon/custom-fonts.php
Wordpress Allow Custom Font Upload
<?php
// add to your theme's functions.php file
add_filter('upload_mimes', 'add_custom_upload_mimes');
function add_custom_upload_mimes($existing_mimes) {
$existing_mimes['otf'] = 'application/x-font-otf';
$existing_mimes['woff'] = 'application/x-font-woff';
$existing_mimes['ttf'] = 'application/x-font-ttf';
$existing_mimes['svg'] = 'image/svg+xml';
$existing_mimes['eot'] = 'application/vnd.ms-fontobject';
return $existing_mimes;
@lucas-pelton
lucas-pelton / stuck-footer.css
Created August 15, 2018 00:07
Stuck footer revealed on scroll
@lucas-pelton
lucas-pelton / front-end.js
Last active October 6, 2017 22:53
FullSlate front end API WP plugin
// http://jillix.github.io/jQuery-sidebar/
(function($){$.fn.sidebar=function(options){var self=this;if(self.length>1){return self.each(function(){$(this).sidebar(options)})}var width=self.outerWidth();var height=self.outerHeight();var settings=$.extend({speed:200,side:"left",isClosed:false,close:true},options);self.on("sidebar:open",function(ev,data){var properties={};properties[settings.side]=0;settings.isClosed=null;self.stop().animate(properties,$.extend({},settings,data).speed,function(){settings.isClosed=false;self.trigger("sidebar:opened")})});self.on("sidebar:close",function(ev,data){var properties={};if(settings.side==="left"||settings.side==="right"){properties[settings.side]=-self.outerWidth()}else{properties[settings.side]=-self.outerHeight()}settings.isClosed=null;self.stop().animate(properties,$.extend({},settings,data).speed,function(){settings.isClosed=true;self.trigger("sidebar:closed")})});self.on("sidebar:toggle",function(ev,data){if(settings.isClosed){self.trigger("sidebar:open",[data])}el