Skip to content

Instantly share code, notes, and snippets.

@Cheffheid
Cheffheid / modal.js
Created November 20, 2017 15:11
Modal / owl carousel codes
/**
* File modal.js
*
* Deal with multiple modals and their media.
*/
window.wdsModal = {};
( function( window, $, app ) {
let $modalToggle,
$focusableChildren,
@Cheffheid
Cheffheid / commit-msg
Last active March 27, 2017 20:08 — forked from wesbos/commit-msg
ESLint / PHPCS Git Pre Commit Hook
# Ruthlessly stolen from Wes Bos' ESLint pre commit hook, and expanded to also run PHPCS.
#!/bin/bash
jsfiles=$(git diff --cached --name-only | grep '\.jsx\?$')
# Only do something if we have JS files.
if [[ $jsfiles != "" ]] ; then
jsfailed=0
for jsfile in ${jsfiles}; do
git show :$jsfile | eslint $jsfile
@Cheffheid
Cheffheid / shortcode.php
Created February 14, 2017 14:50
Age shortcode for WordPress
function cheffism_age_function($atts) {
extract(shortcode_atts(array(
'date' => '12/31/1900', // DOB
'format' => 'dd/MM/YYYY' // Format, does not currently do anything
), $atts));
//explode the date to get month, day and year
$date = explode("/", $date);
//get age from date or birthdate
@Cheffheid
Cheffheid / google-sheets-get-coordinates.js
Last active September 14, 2016 13:23
Get map coordinates based on City, State cell data
/*
* Uses Google Code built in Maps Geocoder to obtain coordinates for a place in the US, for example: Tucson, AZ
* Usage: On a sheet, select "Tools" -> "Script editor" and paste below (modify output as necessary)
* Then set the value for a blank column to =getCoords(locationCell)
* ie. =getCoords(B2)
* Expected format: City, State
* Format example: Tucson, AZ
*/
function getCoords(value) {
@Cheffheid
Cheffheid / google-sheets-generate-html.js
Created August 17, 2016 17:50
Basic Google Sheets script for generating HTML based on row data
/*
* Generates a snippet of HTML code based on data in cells.
* Usage: On a sheet, select "Tools" -> "Script editor" and paste below (modify output as necessary)
* Then set the value for a blank column to =generateHTML(dateCell, titleCell, locationCell, linkCell)
* ie. =generateHTML(B2, C2, D2, E2)
*/
function generateHTML(date, title, location, link) {
var html = Utilities.formatString(
@Cheffheid
Cheffheid / es5-es6-classes.js
Created July 22, 2016 02:40
ES5/ES6 classes
// ES5 does technically not have classes, and so the closest approximation would be something like this:
function Animal( name ) {
this.name = name;
}
function Dog() {
Animal.call( this, "Dog" );
}
Dog.prototype = Object.create(Animal.prototype);
@Cheffheid
Cheffheid / closure-example.js
Created July 22, 2016 01:01
Closure Example
(function () {
var greeter = (function () {
var greeting = "Hey";
var name = "you";
function setName( newName ) {
name = newName;
}
function greet() {
@Cheffheid
Cheffheid / basic-closure.js
Created July 22, 2016 00:26
Basic Closure
function greeting( subject ) {
var message = "Hello %s!";
// hello() will have access to the message variable in the greeting() scope.
function hello() {
return message.replace("%s", subject);
}
return hello();
}
@Cheffheid
Cheffheid / gf-event-confirmation.jquery.js
Last active August 29, 2015 14:21
Simple Universal Analytics event trigger for Gravity Forms (No AJAX)
// Add this to the confirmation page or confirmation text box on forms where AJAX is disabled.
// It will fire as soon as the confirmation page is loaded.
(function($){
$(document).ready(function(){
// Send event with category 'Form', action 'Submit', label 'Contact Us', and value 100.
ga('send', 'event', 'Form', 'Submit', 'Contact Us', 100);
});
})(jQuery);
@Cheffheid
Cheffheid / gf-event-ajax.jquery.js
Last active July 1, 2022 12:11
Simple Universal Analytics event trigger for Gravity Forms (AJAX)
// Can be added on any page with a gravity form, it will hook into GF's own event that triggers when the confirmation is loaded (confirmed conversion).
(function($) {
$(document).bind("gform_confirmation_loaded", function(e, form_id) {
// Send event with category 'Form', action 'Submit', label 'Contact Us', and value 100.
ga('send', 'event', 'Form', 'Submit', 'Contact Us', 100);
});
})(jQuery);