Skip to content

Instantly share code, notes, and snippets.

// Uber-basic templating.. good? bad? ugly?
function interpolate( str, data ) {
data = data || window;
return !str
? ''
: str.replace( /{([^}]*)}/g, function(a,b){
return data[ b ] || '';
});
};
@cowboy
cowboy / widget-schema-idea.js
Created June 22, 2010 19:22
Widget schema idea
/*
Say you have widgets in the page, and each one has its own option defaults.
You embed these widgets in the page, but as your site grows, you may want
to change the defaults in a way that affects only new widgets, leaving the
existing widgets unmodified. How do you manage these "schema" updates?
Sample HTML:
<div class="widget" data-schema="1" data-type="that_widget" data-params="bar=5&amp;baz=6" style="width:200px;height:300px">
@cowboy
cowboy / jquery.ba-focus.js
Created June 23, 2010 14:47
:focus - get the currently focused element
// Public domain, really.
jQuery.expr[':'].focus = function( elem ) {
return elem === document.activeElement && ( elem.type || elem.href );
};
@cowboy
cowboy / jquery.ba-outerhtml.js
Created June 24, 2010 19:54
jQuery outerHTML plugin
/*!
* jQuery outerHTML - v0.3 - 06/25/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* Inspired by Brandon Aaron's outerHTML plugin.
* http://github.com/brandonaaron/jquery-outerhtml
$.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 );
});
});
}
@cowboy
cowboy / jquery.ba-ready.js
Created June 25, 2010 20:53
jQuery ready WIP 100% UNTESTED
/*!
* jQuery ready - v0.4pre - 06/28/2010
* http://benalman.com/projects/jquery-ready-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($,undefined){
@cowboy
cowboy / ba-block.js
Created June 30, 2010 15:06
Something simple for testing slow loading pages
// Block page loading, for testing ready events / etc.
function block( delay ) {
var html = '<script src="http://1.cuzillion.com/bin/resource.cgi?type=js&sleep='
+ delay + '&jsdelay=' + delay + '&t=' + +new Date + '"><\/script>';
document.write( html );
};
/*
@cowboy
cowboy / jquery.ba-isversion.js
Created July 1, 2010 17:36
Test jQuery version WIP UNTESTED
/*!
* jQuery isVersion - v0.1 - 07/02/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($){
@cowboy
cowboy / jquery.ba-fillbox.js
Created July 6, 2010 16:52
Fillbox plugin, to go along with Rey Bango's blog post
// Fillbox plugin, to go along with Rey Bango's blog post,
// "Generic Activity Indicator for Ajax Requests"
// http://blog.reybango.com/2010/07/06/generic-activity-indicator-for-ajax-requests/
(function($){
// Call as $('#foo').fillbox() to use default options or override as-needed
// like $('#bar').fillbox({ url: 'foo.php' }).
$.fn.fillbox = function( options ) {
// Console arguments testing
var apc = [].slice;
(function(){
console.log( apc.call(arguments) );
})( "false", 1, undefined, null, ["foo","bar","baz"], {a:1,b:2}, false );
(function(){
console.log.call( console, apc.call(arguments) );