Skip to content

Instantly share code, notes, and snippets.

View danheberden's full-sized avatar

Dan Heberden danheberden

View GitHub Profile
@danheberden
danheberden / Window vs Body scrolling
Created January 13, 2011 16:32
Find what the hell to scroll
var $docEl = $( document.documentElement ),
$body = $( document.body ),
// if docEl has a scrollTop, well, that kinda answers our question
$scrollable = $docEl.scrollTop() ? $docEL :
$body.scrollTop( $body.scrollTop() + 1 ).scrollTop() ? $body : $docEl;
// its like we can already tell!
if ( windowST ) {
$scrollable = $docEl;
@danheberden
danheberden / gyazo.php
Created February 17, 2011 06:20 — forked from cowboy/gyazo.php
<?PHP
/*
* PHP upload for Gyazo - v1.2 - 02/16/2011
* http://benalman.com/news/2009/10/gyazo-on-your-own-server/
*
* Copyright (c) 2009 "Cowboy" Ben Alman
* Licensed under the MIT license
* http://benalman.com/about/license/
*/
@danheberden
danheberden / 4 Digit Time
Created March 6, 2011 01:15
Gets 4 digit time (hhmm) with optional time frame flooring (e.g. 0317 => 0315 )
/*
* Returns a 4 digit string of the time in hhmm format
* timeFrame will floor to the nearest multiple, e.g.
* fourDigitTime( 15, '', 2, 44 ); // returns "0230"
* hr and min will use the current time if not specified
* sep ( the separator between the hours and minutes ) defaults
* to an empty string ('')
*
* (c) Dan Heberden - danheberden.com
* https://gist.github.com/856911
// We override the animation for all of these color styles
jQuery.each("backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color outlineColor".split(" "), function(i,attr){
jQuery.fx.step[attr] = function(fx){
if ( !fx.colorInit ) {
fx.start = getColor( fx.elem, attr );
fx.end = getRGB( fx.end );
fx.colorInit = true;
}
var rgb = [];
/*
* .serializeObject (c) Dan Heberden
* danheberden.com
*
* Gives you a pretty object for your form bizniss
*/
(function($){
$.fn.serializeObject = function( trimKey ) {
if ( !this.length ) { return false; }
@danheberden
danheberden / Quewery 1.0
Created April 1, 2011 17:35
A selector engine
var Quewery = function( selector ) {
if( selector.match(/#[^\s]+$/) ) {
return [ document.getElementById( selector.substring(1) ) ];
} else {
return document.querySelectorAll( selector );
}
}
@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]);
}
}
@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 / 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: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() ),