Skip to content

Instantly share code, notes, and snippets.

// 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 / 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);
});
@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 / 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 / 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 / script.js
Created May 2, 2013 16:56
window resize listener used to sort out flex slider
var listItems = $('.project_list > li')
$(window).bind('resize',function() {
var ww = $(window).width();
listItems.each(function() {
$(this).width(ww);
});
});
@stugoo
stugoo / arc.svg
Last active December 16, 2015 06:58
SVG Arc drawing, pass in a CFG and allow it to draw an arc
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stugoo
stugoo / text-preview.js
Created April 16, 2013 10:50
Simple text input > preview
var textPreview = function (el) {
var self = this,
input,
output,
initialise = function() {
input = el.querySelector('input') || el.querySelector('textarea'),
target = el.getAttribute('data-textPreview-output-element'),
@stugoo
stugoo / inView.js
Created April 16, 2013 10:46
Detects if an element is in the viewport and then displays it
/*
requires :
underscore js
event subscriber
*/
inView = function (element) {
var self = this,
type,
@stugoo
stugoo / video-preview.js
Last active December 16, 2015 06:58
Video from URL Preview
/*
* Requires : underscore.js
uploader = file[type=text]
output = output element
E.G
uploader = document.getElementById("file_url"),
output = document.getElementById('preview_image'),
valid :