Created
January 25, 2010 19:32
-
-
Save paulirish/286150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://jquery14.com/day-12/jquery-1-4-hawtness-5-with-paul-irish | |
/*d8b .d88888b. d888 d8888 | |
Y8P d88P" "Y88b d8888 d8P888 | |
888 888 888 d8P 888 | |
8888 888 888 888 888 .d88b. 888d888 888 888 888 d8P 888 | |
"888 888 888 888 888 d8P Y8b 888P" 888 888 888 d88 888 | |
888 888 Y8b 888 888 888 88888888 888 888 888 888 8888888888 | |
888 Y88b.Y8b88P Y88b 888 Y8b. 888 Y88b 888 888 d8b 888 | |
888 "Y888888" "Y88888 "Y8888 888 "Y88888 8888888 Y8P 888 | |
888 Y8b 888 | |
d88P Y8b d88P | |
888P" "Y88P" | |
888 888 888 | |
888 888 888 | |
888 888 888 | |
8888888888 8888b. 888 888 888 888888 88888b. .d88b. .d8888b .d8888b | |
888 888 "88b 888 888 888 888 888 "88b d8P Y8b 88K 88K | |
888 888 .d888888 888 888 888 888 888 888 88888888 "Y8888b. "Y8888b. | |
888 888 888 888 Y88b 888 d88P Y88b. 888 888 Y8b. X88 X88 | |
888 888 "Y888888 "Y8888888P" "Y888 888 888 "Y8888 88888P' 88888P' | |
#5: utilities | |
db d8b db d888888b d888888b db db | |
88 I8I 88 `88' `~~88~~' 88 88 | |
88 I8I 88 88 88 88ooo88 | |
Y8 I8I 88 88 88 88~~~88 | |
`8b d8'8b d8' .88. 88 88 88 | |
`8b8' `8d8' Y888888P YP YP YP | |
d8888b. .d8b. db db db d888888b d8888b. d888888b .d8888. db db | |
88 `8D d8' `8b 88 88 88 `88' 88 `8D `88' 88' YP 88 88 | |
88oodD' 88ooo88 88 88 88 88 88oobY' 88 `8bo. 88ooo88 | |
88~~~ 88~~~88 88 88 88 88 88`8b 88 `Y8b. 88~~~88 | |
88 88 88 88b d88 88booo. .88. 88 `88. .88. db 8D 88 88 | |
88 YP YP ~Y8888P' Y88888P Y888888P 88 YD Y888888P `8888Y' YP YP | |
*/ | |
// new element creation | |
jQuery("<div/>", { | |
id: "foo", | |
rel : "something", // thx Mark Rajcok for the catch | |
css: { | |
height: "50px", | |
width: "50px", | |
color: "blue", | |
backgroundColor: "#ccc" | |
}, | |
click: function() { | |
$(this).css("backgroundColor", "red"); | |
} | |
}).appendTo("body"); | |
/* | |
.o8 . oooo | |
"888 .o8 `888 | |
.oooo888 .ooooo. .o888oo .oooo. .ooooo. 888 .oo. | |
d88' `888 d88' `88b 888 `P )88b d88' `"Y8 888P"Y88b | |
888 888 888ooo888 888 .oP"888 888 888 888 | |
888 888 888 .o 888 . d8( 888 888 .o8 888 888 | |
`Y8bod88P" `Y8bod8P' "888" `Y888""8o `Y8bod8P' o888o o888o | |
*/ | |
// fixed the missing $. good catch, dabear | |
var $table = $('#mytable').detach(); | |
$table.dostuffto(); | |
$table.appendTo('.tablewrap'); | |
/* | |
.o8 . | |
"888 .o8 | |
.oooo888 .oooo. .o888oo .oooo. | |
d88' `888 `P )88b 888 `P )88b | |
888 888 .oP"888 888 .oP"888 | |
888 888 d8( 888 888 . d8( 888 | |
`Y8bod88P" `Y888""8o "888" `Y888""8o | |
*/ | |
$('#bigchief') | |
.data('age',7) | |
.data('interests',['lollipops','ice cream','italian ice']) | |
.data(); // previously something like 12324789549 | |
// now an obj: { 'age' : 12, 'interests' : ['lollipops'] } | |
// isPlainObject() | |
jQuery.isPlainObject({}) // true | |
jQuery.isPlainObject("test") // false | |
jQuery.isPlainObject({ foo: 'bar'}) // true | |
// isEmptyObject() | |
jQuery.isEmptyObject({}) // true | |
jQuery.isPlainObject({ empty: "test"}) // false | |
/* | |
. oooo .oooooo. oooo | |
.o8 `888 d8P' `Y8b `888 | |
.o888oo .ooooo. .oooooooo .oooooooo 888 .ooooo. 888 888 .oooo. .oooo.o .oooo.o | |
888 d88' `88b 888' `88b 888' `88b 888 d88' `88b 888 888 `P )88b d88( "8 d88( "8 | |
888 888 888 888 888 888 888 888 888ooo888 888 888 .oP"888 `"Y88b. `"Y88b. | |
888 . 888 888 `88bod8P' `88bod8P' 888 888 .o `88b ooo 888 d8( 888 o. )88b o. )88b | |
"888" `Y8bod8P' `8oooooo. `8oooooo. o888o `Y8bod8P' `Y8bood8P' o888o `Y888""8o 8""888P' 8""888P' | |
d" YD d" YD | |
"Y88888P' "Y88888P' | |
*/ | |
<div class="tumble">Some text.</div> | |
$(div).toggleClass('bounce spin') | |
<div class="tumble bounce spin">Some text.</div> | |
$(div).toggleClass('bounce jump', isConditional ? false : true) | |
<div class="tumble spin">Some text.</div> | |
/* | |
o8o .o8 | |
`"' "888 | |
oooo ooo. .oo. .oooo888 .ooooo. oooo ooo | |
`888 `888P"Y88b d88' `888 d88' `88b `88b..8P' | |
888 888 888 888 888 888ooo888 Y888' | |
888 888 888 888 888 888 .o .o8"'88b | |
o888o o888o o888o `Y8bod88P" `Y8bod8P' o88' 888o | |
*/ | |
// get index of .current vs its siblings -- old <= 1.3.2 method | |
$('li').index('li.current') // 3 | |
// get the index of the first <li class="index"> in relation to its siblings: | |
$("li.current").index() // 3 | |
// get the index of the <h3 id="more-info"> in relation to all <h3> elements: | |
$("h3#more-info").index("h3") | |
/* | |
. o8o | |
.o8 `"' | |
.ooooo. .ooooo. ooo. .oo. .o888oo .oooo. oooo ooo. .oo. .oooo.o | |
d88' `"Y8 d88' `88b `888P"Y88b 888 `P )88b `888 `888P"Y88b d88( "8 | |
888 888 888 888 888 888 .oP"888 888 888 888 `"Y88b. | |
888 .o8 888 888 888 888 888 . d8( 888 888 888 888 o. )88b | |
`Y8bod8P' `Y8bod8P' o888o o888o "888" `Y888""8o o888o o888o o888o 8""888P' | |
*/ | |
jQuery.contains(document.documentElement, document.body); // true | |
jQuery.contains(document.body, document.documentElement); // false | |
/* | |
ooo. .oo. .ooooo. .ooooo. oo.ooooo. | |
`888P"Y88b d88' `88b d88' `88b 888' `88b | |
888 888 888 888 888 888 888 888 | |
888 888 888 888 888 888 888 888 | |
o888o o888o `Y8bod8P' `Y8bod8P' 888bod8P' | |
888 | |
o888o | |
*/ | |
$.fn.myPlugin(callback){ | |
// do great stuff! | |
return this.animate({height:'+=20px'},500, callback || jQuery.noop ); | |
} | |
.d88b. 88888b. .d88b. 88888b.d88b. .d88b. 888d888 .d88b. | |
d88""88b 888 "88b d8P Y8b 888 "888 "88b d88""88b 888P" d8P Y8b | |
888 888 888 888 88888888 888 888 888 888 888 888 88888888 | |
Y88..88P 888 888 Y8b. 888 888 888 Y88..88P 888 Y8b. | |
"Y88P" 888 888 "Y8888 888 888 888 "Y88P" 888 "Y8888 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment