Skip to content

Instantly share code, notes, and snippets.

View glynthomas's full-sized avatar

Glyn Thomas glynthomas

View GitHub Profile
@glynthomas
glynthomas / javascript-test-array
Created April 15, 2013 15:07
JavaScript testing for empty array, object keys
Javascript testing for empty (undefined) object or array
This is the problem, for JS object keys and for array's, not that I like really testing for undefined, I would rather set false or true and test for that, but ...;
var obj = { key: undefined };
obj["key"] != undefined // false, but the key exists!
and also;
if (urlobject[3] == 'undefined') {} // again does not work as expected
jQuery(function($) {
$('form[data-async]').live('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target'));
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
@glynthomas
glynthomas / gist:9055235
Last active August 29, 2015 13:56
HTML5 File API thumbnail : div
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>HTML5 Demo: FileReader API thumbnail : div</title>
<!-- <link rel="stylesheet" href="css/html5demos.css"> -->
<body>
<section id="wrapper">
@glynthomas
glynthomas / gist:9055599
Created February 17, 2014 17:54
HTML5 Demo: FileReader API thumbnail : canvas
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>HTML5 Demo: FileReader API thumbnail : canvas</title>
<!-- <link rel="stylesheet" href="css/html5demos.css"> -->
<body>
<section id="wrapper">
@glynthomas
glynthomas / gist:9103273
Created February 19, 2014 22:46
HTML5 File API thumbnail : EXIF orientation tag (lightweight fix)
<!DOCTYPE html>
<head>
<title>HTML5 Camera Fun</title>
</head>
<style type="text/css">
.crop-canvas {
bottom: -30px;
@glynthomas
glynthomas / gist:9118814
Created February 20, 2014 17:20
Cross Browser Add and Remove Event Listeners idea / demo
var addEvent, removeEvent;
if ( window.addEventListener ) {
addEvent = function(obj, type, fn ) {
obj.addEventListener(type, fn, false );
}
removeEvent = function(obj, type, fn ) {
obj.removeEventListener(type, fn, false );
}
} else if (document.attachEvent) {
addEvent = function(obj, type, fn ) {