Skip to content

Instantly share code, notes, and snippets.

Ben Alman cowboy

Block or report user

Report or block cowboy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:303386
var a = 1;
(function(){
var a = 2;
(function(parent){
var global = this;
View String.repeat.js
function repeat(s,n){return Array(n+1).join(s);}
// usage
repeat('x', 3); // returns "xxx"
View detect IE and version number through injected conditional comments.js
//EnhanceJS isIE test idea
//detect IE and version number through injected conditional comments (no UA detect, no need for cond. compilation / jscript check)
//version arg is for IE version (optional)
//comparison arg supports 'lte', 'gte', etc (optional)
var isIE = (function(){
var doc = document,
@cowboy
cowboy / gist:360138
Created Apr 8, 2010 — forked from remy/gist:360113
setInterval and setTimeout patterns
View gist:360138
// =========================
// SetInterval
// =========================
// While not truly accurate, setInterval is still fairly good, time-wise.
// Better for things like a "one second tick" but not great for expensive
// code executed at small intervals as iterations can "stack".
// (ECMAScript 5 strict mode compatible)
@cowboy
cowboy / gist:379255
Created Apr 26, 2010 — forked from remy/gist:378764
Just another way of doing it...
View gist:379255
// "Cheat" special event using this pattern:
// http://benalman.com/news/2010/03/jquery-special-events/#pattern
//
// Also see:
// http://benalman.com/news/2010/03/jquery-special-events/#add-and-remove-tripleclick-per-handler
(function($){
$.event.special.cheat = {
setup: function() {
@cowboy
cowboy / jquery.ba-bindandtrigger.js
Created Apr 30, 2010 — forked from westonruter/jquery.bindAndCall.js
Bind an event handler and fire it immediately
View jquery.ba-bindandtrigger.js
/*!
* bindAndTrigger - v0.1 - 04/30/2010
* http://benalman.com/
*
* http://jsfiddle.net/cowboy/fJnA2/
*/
(function($,undefined){
$.fn.bindAndTrigger = function( all, type, data, callback ) {
View mesighs.js
$.fn.format = function(opts){
var o = $.extend({}, defaults.format, opts), codez = formatCodes(o.locale);
return this.each(function(){
var me = $(this);
me[ me.is(":input") ? "val" : "text" ](function(i,v){
return formatNumber( v, o, codez );
});
});
}
View gist:473071
/*!
* jQuery.preloadImg
* description: cache images via $.preloadImg(['src','src']) or $('img').preloadImg()
* author: Cody Lindley
*/
(function($) {
// Internal cache of image src values.
var cache = {};
View jQuery.classList.js
/*
Usages:
$(selector).classList() //returns an array of classnames
$(selector).classList('newclass') //replaces the current element's classes
$(selector).classList(['new', 'class', 'names']) //replaces the current element's classes
*/
jQuery.fn.classList = function( classNames ) {
if ( jQuery.isArray( classNames ) ) {
// An array was passed, join it into a string.
You can’t perform that action at this time.