Skip to content

Instantly share code, notes, and snippets.

@craveytrain
craveytrain / contact_form.html
Created July 15, 2010 02:17
Accessible Inline Form Labels
<form id="contact">
<ul>
<li>
<label for="name">Name</label>
<input type="text" id="name" name="name" value="" />
</li>
<li>
<label for="email">Email</label>
<input type="text" id="email" name="email" value="" />
</li>
@craveytrain
craveytrain / makinginputsbehave.css
Created July 26, 2010 19:19
Making Inputs Behave (Like a Block Level Element)
input {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
}
@craveytrain
craveytrain / jQ fns.js
Created October 1, 2010 03:56
Resilient Pub/Sub
;(function($){
var cache = {};
$.pub = function (topic, args) {
cache[topic] && $.each(cache[topic], function () {
try {
this.apply($, args || []);
} catch (e) {
if (console) console.warn(e);
}
@craveytrain
craveytrain / pubsub.js
Created October 1, 2010 15:45
Dumb Resilient Pub/Sub
var sub = function (e, callback) {
var handler;
if (document.addEventListener) {
handler = function (evt) {
callback();
};
document.addEventListener(e, handler, false);
} else if (document.attachEvent) {
handler = function (evt) {
if (evt.propertyName == e) {
@craveytrain
craveytrain / modal.html
Created November 15, 2010 23:09
Resilient Modals
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>modals</title>
<link rel="stylesheet" href="style.css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="modal.js"></script>
<noscript>
<style>
@craveytrain
craveytrain / gistFetch.html
Created December 9, 2010 23:33
Fetching the Gist
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Gist Fetch</title>
</head>
<body>
<h1>Separate Files</h1>
<h2>Contact_form.html</h2>
<a class="gistPlaceholder" href="https://gist.github.com/476405#file_contact_form.html">contact_form.html</a>
@craveytrain
craveytrain / index.jsp
Created June 13, 2011 21:27
ga key lookup
<html>
<body>
...
<script src="separate_js_file.js"></script>
<script>
var _gaq=[['_setAccount', gaKeys[<%=config_id %>][<%=inst %>]],['_trackPageview'],['_trackPageLoadTime']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
@craveytrain
craveytrain / client-withCredentials.js
Created June 16, 2011 02:20
Cross domain scripting with jQuery
$.ajaxPrefilter('json', function(options, orig, jqXHR) {
if (options.crossDomain && !$.support.cors) return 'jsonp'
});
$.ajax({
url: 'http://nodeserver:3000',
dataType: 'json',
success: callback,
xhrFields: {
withCredentials: true
@craveytrain
craveytrain / gist:1038308
Created June 21, 2011 16:55
namespacing callbacks
function exeCallback(callback, params) {
var context = window,
namespaces = callback.split('.'),
func = namespaces.pop();
for (var i = 0, l = namespaces.length; i < l; i++) {
context = context[namespaces[i]];
}
context[func].apply(context, params);
}
@craveytrain
craveytrain / ga_lookup_code.js
Created June 23, 2011 01:42 — forked from pierceray/ga_lookup_code.js
determining the GA code based on params or lack there of
//lookup object
var gaKeys = {
'tdshs_ems': {
'01': 'UA-234234-23',
'02': 'UA-234234-24'
},
'error' : 'UA-bad-code'
};
var configId = '<param>'.toLowerCase(); //error condition is 'error'