Skip to content

Instantly share code, notes, and snippets.

@lstanard
lstanard / ScrollTo
Last active August 11, 2022 16:12
Bind smooth scroll event to links
// Setup scrollto links
$('.scrollto').on('click', function(e) {
var targetElement = $('#' + $(this).attr('href').substring(1));
if (targetElement.length >= 1) {
var target = targetElement.offset().top,
scrollSpeed = function() { return Math.ceil( Math.abs( target - $w.scrollTop() ) / 1.5 ); };
$('html, body').animate({
scrollTop: target
}, scrollSpeed() );
}
@lstanard
lstanard / JS Pattern: jQuery plugin
Last active August 11, 2022 16:11
JavaScript Design Pattern: jQuery Plugin Template
(function($){
$.fn.pluginName = function(options) {
var settings = $.extend({
'option': 'value'
}, options||{} );
}
})(jQuery);
@lstanard
lstanard / jQuery lightweight plugin boilerplate
Created October 18, 2013 02:53
jQuery lightweight plugin boilerplate
/*!
* jQuery lightweight plugin boilerplate
* Original author: @ajpiano
* Further changes, comments: @addyosmani
* Licensed under the MIT license
*/
// the semi-colon before the function invocation is a safety
// net against concatenated scripts and/or other plugins
// that are not closed properly.

Keybase proof

I hereby claim:

  • I am lstanard on github.
  • I am jarls (https://keybase.io/jarls) on keybase.
  • I have a public key ASCPwZ-C35DgYlEbbj-7QX9ylqnp_JKxYDghjec4KBuozwo

To claim this, I am signing this object:

@lstanard
lstanard / PickAndRequireAll.ts
Last active October 1, 2020 22:08
TypeScript: Combination pick and make all propertites required
type PickAndRequireAll<T, K extends keyof T> = {
[P in K]-?: T[P];
};
@lstanard
lstanard / ReactFunctionComponent.jsx
Last active June 17, 2020 20:42
Sample of various patterns and standards for FWI function components (based on https://gist.github.com/markerikson/47fff93c92286db72b22bab5b02e2da3)
import React from "react";
import PropTypes from "prop-types";
const MyComponent = ({ prop1, prop2, className }) => {
let someMessage = "This is a message, it may change";
// If a value could change use `let` and if/else statements rather
// than a function that returns a value.
if (prop1) {
someMessage = "The message has changed based on some condition";
@lstanard
lstanard / jQuery resize listener
Created March 5, 2014 14:38
Resize listener to call functions based on window size
$(document).ready(function() {
var mobile,
w = $(window),
breakpoint = 640,
sw = document.documentElement.clientWidth,
sh = document.documentElement.clientHeight;
w.on('resize orientationchange', function() {
sw = document.documentElement.clientWidth;
@lstanard
lstanard / waitForFinalEvent()
Created March 18, 2014 14:06
Call window resize event only when finished
// Call window resize function only once finished
var waitForFinalEvent = (function () {
var timers = {};
return function (callback, ms, uniqueId) {
if (!uniqueId) {
uniqueId = "Don't call this twice without a uniqueId";
}
if (timers[uniqueId]) {
clearTimeout (timers[uniqueId]);
}
@lstanard
lstanard / simple-debug-log.php
Last active March 7, 2018 21:12
WordPress plugin to write debug_log to debug.log file
<?php
/*
Plugin Name: Simple Debug Log
*/
if ( ! function_exists('debug_log')) {
function debug_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
@lstanard
lstanard / acf-export-2018-01-18
Last active January 18, 2018 18:00
Catalyst WP Atom Organism Fields
[
{
"key": "group_5719a52cf2cb2",
"title": "Organisms",
"fields": [
{
"key": "field_5719a52e1711e",
"label": "Organism",
"name": "organism",
"type": "repeater",