Skip to content

Instantly share code, notes, and snippets.

View acusti's full-sized avatar
Black Lives Matter

Andrew Patton acusti

Black Lives Matter
View GitHub Profile
@wpsmith
wpsmith / gs-change-registered-cpt-init.php
Last active January 20, 2017 16:08
PHP: Register Custom Post Type
<?php
add_action( 'init', 'gs_books_label_rename', 999 );
/**
* Modify registered post type menu label
*
*/
function gs_books_label_rename() {
global $wp_post_types;
$wp_post_types['gs_books']->labels->menu_name = __( 'Books', 'gs_books' );
@ismyrnow
ismyrnow / google-analytics-amd.js
Last active March 14, 2022 21:32
Google Analytics AMD Module
define(function (require) {
var module;
// Setup temporary Google Analytics objects.
window.GoogleAnalyticsObject = "ga";
window.ga = function () { (window.ga.q = window.ga.q || []).push(arguments); };
window.ga.l = 1 * new Date();
// Immediately add a pageview event to the queue.
@pmeenan
pmeenan / user-timing-rum.js
Last active January 18, 2024 23:46
Support routine for adding W3C user timing events to a site. Includes some basic polyfill support for browsers that don't support user timing or navigation timing (though the start time for non-navigation timing support could be improved with IE < 9 to use IE's custom start event).
// Support routines for automatically reporting user timing for common analytics platforms
// Currently supports Google Analytics, Boomerang and SOASTA mPulse
// In the case of boomerang, you will need to map the event names you want reported
// to timer names (for mPulse these need to be custom0, custom1, etc) using a global variable:
// rumMapping = {'aft': 'custom0'};
(function() {
var wtt = function(n, t, b) {
t = Math.round(t);
if (t >= 0 && t < 3600000) {
// Google Analytics
@creationix
creationix / run.js
Last active November 27, 2017 16:06
A tiny generator helper for consuming callback code directly
function run(generator) {
var iterator = generator(resume);
var data = null, yielded = false;
iterator.next();
yielded = true;
check();
function check() {
while (data && yielded) {
@acusti
acusti / dropdown-touch.js
Last active July 11, 2017 18:00
Plain vanilla JS with no dependencies to add touch device support for drop down menus (nested unordered list style). CSS selectors to display nested `<ul>` should look like: `body.no-touch ul.menu > li:hover > ul, ul.menu > li.tapped > ul { display: block; }`
(function(doc) {
// Add touch device support for dropdown menu
if (('addEventListener' in doc) && ('querySelectorAll' in doc) && (('ontouchstart' in window) || ('onmsgesturechange' in window))) {
var menu_item_selector = '.the-menu > div > ul > li',
menu_items = doc.querySelectorAll(menu_item_selector),
touchStart;
// Set up touch start handler
touchStart = function() {
if (this.className.indexOf(' tapped') > -1) {
@StephenBrown
StephenBrown / jsperf-bookmarklet.js
Last active March 25, 2020 18:54 — forked from stoyan/jsperf-bookmarklet.js
Bookmarklet for one click webpagetest. Dulles, Chrome, DSL, captures video, tcpdump, and a repeat view.
(function(){
var key = localStorage.wpt_key;
if (!key) {
var prompt = window.__proto__.prompt;
key = prompt('Your WebPagetest API key, please?');
if (!key) {
return gameOver();
}
localStorage.wpt_key = key;
@cowboy
cowboy / bocoup-training-more-efficient-event-handlers.js
Created February 12, 2013 21:38
Bocoup training: More Efficient jQuery Event Handlers
// Straightforward + simple.
$("button").on("click", function(event) {
event.preventDefault();
var button = $(this);
var numberElem = button.find(".number");
var number = Number(numberElem.text()) - 1;
numberElem.text(number);
if (number === 0) {
button.prop("disabled", true);
button.off("click");
@jonathantneal
jonathantneal / eventListener.js
Created June 4, 2012 16:27
Event Listener polyfill
// addEventListener polyfill IE6+
!window.addEventListener && (function (window, document) {
function Event(e, element) {
var instance = this;
for (property in e) {
instance[property] = e[property];
}
instance.currentTarget = element;
document.body.addEventListener('error', function(event) {
if ( event.target.nodeName.toLowerCase() == 'img' ) {
// an image on the page failed to load
}
}, true);
@necolas
necolas / README.md
Last active March 28, 2024 20:34
Experimenting with component-based HTML/CSS naming and patterns

NOTE I now use the conventions detailed in the SUIT framework

Template Components

Used to provide structural templates.

Pattern

t-template-name