Skip to content

Instantly share code, notes, and snippets.

View danheberden's full-sized avatar

Dan Heberden danheberden

View GitHub Profile
document.write( '<script src="//code.jquery.com/jquery-' + version + '.js"><\/script>' );
var verMatch = /jqversion=([\w\.]+)/.exec( location.search ),
version = verMatch && verMatch[1];
if ( version ) {
document.write( '<script src="//code.jquery.com/jquery-' + version + '.js"><\/script>' );
} else {
document.write( '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"><\/script>' );
}
@danheberden
danheberden / snippet.htm
Created November 11, 2011 21:02
jQuery Include Snippet
<script>
(function(){
// Look for a jqversion query parameter and grab any following version.
// Limit to digits and letters to prevent any XSS attempts
var verMatch = /jqversion=([\w\.]+)/.exec( location.search ),
// our matched version, e.g., 1.6.4 or 1.7rc1
version = verMatch && verMatch[1],
src;
if ( version ) {
// version was specified, use jQuery's CDN to acccess non-mininfied betas and RCs
@danheberden
danheberden / gist:1169967
Created August 25, 2011 04:12
coffeescript jsfiddle parser
(function(){
var s = "script",
n = "\n",
d = document,
tag = d.getElementsByTagName( s );
console.log( s,n,d,tag);
(function parseCoffee() {
console.log( 'running' );
// check for a non-src'd script
var cloud = '',
users = {};
$('.js-comment-container').each(function() {
var c = $(this),
author = c.find('.author .author a').text(),
body = c.find('.content-body').text(),
words = body.split(' ').length;
users[ author ] = users[ author ] || 1;
@danheberden
danheberden / finddata.jquery.js
Created June 27, 2011 14:21
findData plugin - search by data-KEY=VALUE on and in current jQ collection
/*
* by Dan Heberden / 2011
* demo at http://jsfiddle.net/danheberden/VjKMY/
* made just for Elijah Manor
* e.g.
* $( 'div' ).findData( 'theDataKey', 'theValue' );
*
* will search in the divs and their children
*/
(function( $ ){
@danheberden
danheberden / gist:1048297
Created June 27, 2011 03:59
openX generated JS improvements
<script type='text/javascript'><!--//<![CDATA[
// wrap in an IIFE to not pollute the global name space - also allows 'document', etc, to be minified
(function( window, document ) {
document.MAX_used = document.MAX_used || ',';
// omitting http or https will use whatever is currently being used.
var m3_u = '//www.domain.com/openx/www/delivery/ajs.php?',
escape = window.escape,
// place the params into an array to be joined with the & later
params = [ 'zoneid=10',
'cb=' + Math.floor( Math.random() * +new Date() ),
@danheberden
danheberden / gist:1038635
Created June 21, 2011 19:18 — forked from ralphholzmann/gist:1038554
Challenge Accepted.
getEl = (function (doc) {
var getElementsByClassName = (function () {
return doc.getElementsByClassName ?
function (selector) {
return doc.getElementsByClassName(selector.split('.').pop());
} : function (selector) {
var parts = selector.split("."),
@danheberden
danheberden / gist:948429
Created April 29, 2011 15:02
making $.when() always report one arg
var getName = (function() {
var cache; // private cache
// gets assigned to getName
return function() {
// return the cache if it's valid or
return cache || $.ajax({
url: 'srv/echo',
@danheberden
danheberden / vendorPrefix.js
Created April 21, 2011 06:46 — forked from addyosmani/vendorPrefix.js
JS snippet for getting the current vendor prefix of a CSS(3) property
function getPrefix( prop ){
var vendorPrefixes = ['Moz','Webkit','Khtml','O','ms'],
style = document.createElement('div').style,
upper = prop.charAt(0).toUpperCase() + prop.slice(1),
pref, len = vendorPrefixes.length;
while( len-- ){
if((vendorPrefixes[len] + upper) in style){
pref = (vendorPrefixes[len]);
}
}