Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / walk_dom.js
Created November 21, 2009 21:15
Iterations, anyone? AKA How I wrote a walk_dom method.
// Iterations, anyone? AKA
// How I wrote a walk_dom method.
//
// A JavaScript poem by
//
// "Cowboy" Ben Alman
// 11/21/2009
// A starting point.
@cowboy
cowboy / bbq-removestate.js
Created December 3, 2009 20:50
$.bbq.removeState .. until I can add it into the full release
// Going into jQuery BBQ soon!
// http://github.com/cowboy/jquery-bbq
(function($){
// Method: jQuery.bbq.removeState
//
// Remove one or more keys from the current browser history 'state', creating
// a new state, setting location.hash and triggering any bound
// <window.onhashchange> event callbacks (provided the new state is different
@cowboy
cowboy / ie_cc_body.xsl
Created December 14, 2009 16:33
IE conditional comment <body> tag in XSLT
<!--
IE conditional comment <body> tag in XSLT
5/28/2010 "Cowboy" Ben Alman
http://benalman.com
See:
http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
-->
<xsl:template name="html_body">
@cowboy
cowboy / Rails query string parsing examples
Created December 15, 2009 20:26
PHP / Rails query string parsing examples
For jQuery 1.4 $.param()
See http://benalman.com/news/2009/12/jquery-14-param-demystified/
==========
PHP 5.2.11
==========
# print_r( $_GET );
?a=1&a=2&a=3
@cowboy
cowboy / jquery-pseudo-as-method.js
Created December 24, 2009 18:05
Convert jQuery :pseudo selectors into $.fn.pseudo methods (if no conflicts)
(function($){
$.each( $.expr[":"], function(k){
$.fn[k] = $.fn[k] || function(v){
return this.pushStack( this.filter( ':' + k + '(' + v + ')' ), k );
};
});
}(jQuery);
(function($){
var private1,
myNS = $.myNS = {},
method2;
$.myNS.method1 = function(){
private2();
};
@cowboy
cowboy / jquery_plugin_org_1.js
Created January 8, 2010 20:52
View revisions from oldest -> newest
// Creating a plugin with $.myNS.public_method1() and $.myNS.public_method2() methods, a few different ways.
(function($){
var private_var,
myNS = $.myNS = {},
public_method2;
myNS.public_method1 = function(){
private_method();
function jquery_14_useragent_test( ua ) {
var ret = { browser: "" };
ua = ua.toLowerCase();
if ( /webkit/.test( ua ) ) {
ret = { browser: "webkit", version: /webkit[\/ ]([\w.]+)/ };
} else if ( /opera/.test( ua ) ) {
@cowboy
cowboy / jquery.ba-istype.js
Created January 18, 2010 14:28
The Miller Device - jQuery Plugin
// based on http://zaa.ch/1q
$.isType = function( obj, type ) {
var opt = Object.prototype.toString,
result = opt.call( obj ).slice( 8, -1 ).toLowerCase();
if ( type === 'null' || type === 'undefined' ) {
type = type === 'null' ? opt.call( null ) : opt.call( undefined );
type = type.slice( 8, -1 ).toLowerCase();
}
@cowboy
cowboy / event_handler_context.js
Created January 18, 2010 14:57
jQuery event handler context examples
var foo = {
context: 'obj',
func: function(){
console.log( this.context );
}
};
var bar = foo.func;
window.context = 'global';