Skip to content

Instantly share code, notes, and snippets.

@stugoo
stugoo / acf-encode.php
Created June 30, 2013 09:58
Encodes advance custom fields for JSON output
// Requires ACF & JSON-API
add_filter('json_api_encode', 'json_api_encode_acf');
function json_api_encode_acf($response)
{
if (isset($response['posts'])) {
foreach ($response['posts'] as $post) {
json_api_add_acf($post); // Add specs to each post
}
}
@stugoo
stugoo / u-d-l-r.js
Last active December 19, 2015 04:49
up down left right keycode events
document.addEventListener('keyup', function (e) {
var keyCode = e.keyCode || e.which,
arrow = { left: 37, up: 38, right: 39, down: 40 };
switch (keyCode) {
case arrow.left:
console.log(keyCode);
break;
case arrow.up:
@stugoo
stugoo / jquery-test.js
Last active December 19, 2015 15:09
Modernizr Test for jQuery 2.0
/* REQUIRES http://modernizr.com/download/#-addtest-json-script_defer-load */
(function(window, document, Modernizr, undefined) {
'use strict';
Modernizr.addTest('jQueryVersion', function() {
return (
Modernizr.json &&
Modernizr.scriptdefer &&
@stugoo
stugoo / play-to.js
Created July 21, 2013 14:48
Video-js player autoplay then pause at a certain time
var video = function() {
if( $('#video').length > 0 ){
videojs("video", {}, function(){
playvideo(this);
});
// extend prototype to check email address on string
String.prototype.checkEmail = function(){
var e=/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return e.test(this);
};
// usage
// "[email protected]".checkEmail(); (returns true/false);
@stugoo
stugoo / select-increment-15min-24hr-clock
Created August 19, 2013 11:38
so I never have to do it again.
<select>
<option value="00:00">00:00</option>
<option value="00:15">00:15</option>
<option value="00:30">00:30</option>
<option value="00:45">00:45</option>
<option value="01:00">01:00</option>
<option value="01:15">01:15</option>
<option value="01:30">01:30</option>
<option value="01:45">01:45</option>
<option value="02:00">02:00</option>
@stugoo
stugoo / hover.js
Created August 22, 2013 11:55
highlighting a table cell and all others behind it until the first item.
calendarTo.on('mouseover', 'td', function(){
var tds = calendarTo.find('td').not('.ui-datepicker-other-month');
fromTd = tds.filter('.ui-state-range:first');
thisTd = $(this);
startIndex = tds.index(fromTd);
@stugoo
stugoo / Preferences.sublime-settings
Created September 11, 2013 08:55
Sublime text config
{
"bold_folder_labels": true,
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
".DS_Store",
".gitkeep",
"dump.rdb",
".svn"
],
@stugoo
stugoo / modernizr-ios6-test.js
Created November 21, 2013 12:50
IOS 6 modernizer test, needed this for super edge case on iPad on landscape. :/
// i know, i know, browser sniffing :(
// adaptation of http://stackoverflow.com/questions/8348139/detect-ios-version-less-than-5-with-javascript
Modernizr.addTest('ios6', function() {
var ios6 = false,
v, ver = false;
if (/iP(hone|od|ad)/.test(navigator.platform)) {
v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/),
ver = parseInt(v[1], 10);
@stugoo
stugoo / Gruntfile.js
Created April 1, 2014 13:23
Grunt, scss and hbs for turning svgs into icons and pngs,
// requires
/*
* https://github.com/filamentgroup/grunticon
* https://www.npmjs.org/package/grunt-text-replace
*/
'use strict';
module.exports = function (grunt) {