Skip to content

Instantly share code, notes, and snippets.

@zerosignalproductions
zerosignalproductions / phone-regex.js
Last active August 29, 2015 13:56
Validate a phone number allowing for the format 1-(XXX)-XXX-XXXX, but not 1XX-XXX-XXX or XXX-555-XXXX.
//https://www.debuggex.com/r/H3Wz2nlxZUJcs7sV/3
/^(\+?1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-??(?!5{3})[2-9]\d{2}-?\d{4}$/
@zerosignalproductions
zerosignalproductions / gist:9766252
Created March 25, 2014 16:55
DOM-based Routing from Wordpress Roots theme
/* ========================================================================
* DOM-based Routing
* Based on http://goo.gl/EUTi53 by Paul Irish
*
* Only fires on body classes that match. If a body class contains a dash,
* replace the dash with an underscore when adding it to the object below.
*
* .noConflict()
* The routing is enclosed within an anonymous function so that you can
* always reference jQuery with $, even when in .noConflict() mode.
@zerosignalproductions
zerosignalproductions / estimated-reading-time.php
Created March 31, 2014 18:12
Estimated Reading time in PHP
<?php
$mycontent = $post->post_content; // wordpress users only
$word = str_word_count(strip_tags($mycontent));
$readingRate = 200;
$m = floor($word / readingRate);
$s = floor($word % readingRate / (readingRate / 60));
$est = $m . ' minute' . ($m == 1 ? '' : 's') . ', ' . $s . ' second' . ($s == 1 ? '' : 's');
?>
<p>Estimated reading time: <?php echo $est; ?></p>
function Set_Cookie( name, value, expires, path, domain, secure ) {
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );
/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
var rtime = new Date(1, 1, 2000, 12,00,00);
var timeout = false;
var delta = 200;
$(window).resize(function() {
rtime = new Date();
if (timeout === false) {
timeout = true;
setTimeout(resizeend, delta);
}
});
@zerosignalproductions
zerosignalproductions / requestAnimationFrame.js
Created July 23, 2013 14:52
Add requestionAnimationFrame/cancelAnimationFrame support for all browsers. Source: https://gist.github.com/paulirish/1579671/#comment-846392
(function(window) {
'use strict';
var lastTime = 0,
vendors = ['moz', 'webkit', 'o', 'ms'],
x;
// Remove vendor prefixing if prefixed and break early if not
for (x = 0; x < vendors.length && !window.requestAnimationFrame; x += 1) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
@zerosignalproductions
zerosignalproductions / detectVendorPrefix.js
Created July 23, 2013 15:44
Detect the vendor prefix and return it as an object. Source: http://davidwalsh.name/vendor-prefix
var prefix = (function () {
var styles = window.getComputedStyle(document.documentElement, ''),
pre = (Array.prototype.slice
.call(styles)
.join('')
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o'])
)[1],
dom = ('WebKit|Moz|MS|O').match(new RegExp('(' + pre + ')', 'i'))[1];
return {
dom: dom,
@zerosignalproductions
zerosignalproductions / tracking.js
Last active December 26, 2015 19:09
DoubleClick / SiteCatalyst Tracking
/**
* Adds DoubleClick or SiteCatalyst to any element using supplied
* selectors. If no selectors are given, function defaults to
* data-dctracking and data-tracking.
*
* @param {string or array} selectors elements to set tracking
*/
function setupTracking(selectors) {
//Can pass in selectors as string or array
@zerosignalproductions
zerosignalproductions / jquery-animation.js
Last active January 4, 2016 21:09
New animation function to auto switch between CSS and JS animation depending on browser support
// Updated: 01/28/2014
// Changes:
// Removed all non animation specific code
// Updated to allow passing in of positioning
var cssAnimation = (function($) {
var speed = 250,
easing = 'linear',
cssTransition = 'cubic-bezier(0.39, 0.575, 0.565, 1)',
done = false,
@zerosignalproductions
zerosignalproductions / swipe-support.js
Created January 28, 2014 23:32
Add swipe support to websites. Not very generic at the moment.
(function($, window) {
var self = $('html'),
dragDelta = 500;
friction = 0.35;
mouseDown = false,
touchDelta = 0;
startSwipe = 0,
isDragging = false;
//Assume no touch on load