Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
11 More Things I Learned from the jQuery Source
/*
.d .d 8b d8 dP"Yb 88""Yb 888888 888888 88 88 88 88b 88 dP""b8 .dP"Y8
.d88 .d88 88b d88 dP Yb 88__dP 88__ 88 88 88 88 88Yb88 dP `" `Ybo."
88 88 88YbdP88 Yb dP 88"Yb 88"" 88 888888 88 88 Y88 Yb "88 o.`Y8b
88 88 88 YY 88 YbodP 88 Yb 888888 88 88 88 88 88 Y8 YboodP 8bodP'
88 88 888888 db 88""Yb 88b 88 888888 8888b. 888888 88""Yb dP"Yb 8b d8
88 88 88__ dPYb 88__dP 88Yb88 88__ 8I Yb 88__ 88__dP dP Yb 88b d88
88 88 .o 88"" dP__Yb 88"Yb 88 Y88 88"" 8I dY 88"" 88"Yb Yb dP 88YbdP88
88 88ood8 888888 dP""""Yb 88 Yb 88 Y8 888888 8888Y" 88 88 Yb YbodP 88 YY 88
888888 88 88 888888 88888 dP"Yb 88 88 888888 88""Yb Yb dP .dP"Y8 dP"Yb 88 88 88""Yb dP""b8 888888
88 88 88 88__ 88 dP Yb 88 88 88__ 88__dP YbdP `Ybo." dP Yb 88 88 88__dP dP `" 88__
88 888888 88"" o. 88 Yb b dP Y8 8P 88"" 88"Yb 8P o.`Y8b Yb dP Y8 8P 88"Yb Yb 88""
88 88 88 888888 "bodP' `"YoYo `YbodP' 888888 88 Yb dP 8bodP' YbodP `YbodP' 88 Yb YboodP 888888
_ _____ _ _____ _ _
| | | __ \ | | |_ _| (_) | |
| |__ _ _ | |__) |__ _ _ _| | | | _ __ _ ___| |__
| '_ \| | | | | ___// _` | | | | | | | | '__| / __| '_ \
| |_) | |_| | | | | (_| | |_| | | _| |_| | | \__ \ | | |
|_.__/ \__, | |_| \__,_|\__,_|_| |_____|_| |_|___/_| |_|
__/ |
|___/
*/
____
_.' : `._
.-.'`. ; .'`.-.
__ / : ___\ ; /___ ; \ __
,'_ ""--.:__;".-.";: :".-.":__;.--"" _`,
:' `.t""--.. '<@.`;_ ',@>` ..--""j.' `;
`:-.._J '-.-'L__ `-- ' L_..-;'
"-.__ ; .-" "-. : __.-"
L ' /.------.\ ' J
"-. "--" .-"
__.l"-:_JL_;-";.__
.-j/'.; ;"""" / .'\"-.
.' /:`. "-.: .-" .'; `.
.-" / ; "-. "-..-" .-" : "-.
.+"-. : : "-.__.-" ;-._ \
; \ `.; ; : : "+. ;
: ; ; ; : ; : \:
; : ; : ;: ; :
: \ ; : ; : ; / ::
; ; : ; : ; : ;:
: : ; : ; : : ; : ;
;\ : ; : ; ; ; ;
: `."-; : ; : ; / ;
; -: ; : ; : .-" :
:\ \ : ; : \.-" :
;`. \ ; : ;.'_..-- / ;
: "-. "-: ; :/." .' :
\ \ : ;/ __ :
\ .-`.\ /t-"" ":-+. :
`. .-" `l __/ /`. : ; ; \ ;
\ .-" .-"-.-" .' .'j \ / ;/
\ / .-" /. .'.' ;_:' ;
:-""-.`./-.' / `.___.'
\ `t ._ / use the source, luke.
"-.t-._:'
var jQuery = (function() {
// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
},
bunchastuff();
// ...
return (window.jQuery = window.$ = jQuery);
})();
// pseudo module pattern
// https://github.com/phiggins42/has.js/blob/master/detect/dom.js#L140-143
<div data-omg="yay" data-awesum="true" data-hawtObj='{"best":"jQuery"}'></div>
$("div").data("omg") === "yay";
$("div").data("awesum") === true;
$("div").data("hawtObj").best === "jQuery";
// function dataAttr
if (data === "true"){
data = true;
} else if (data === "false"){
data = false;
} else if (data === "null"){
data = null;
} else if (!jQuery.isNaN(data)){
data = parseFloat(data);
} else if (rbrace.test(data)) {
data = jQuery.parseJSON(data);
} else {
data = data;
}
if ( name in elem || elem[ name ] !== undefined && notxml && !special ) {
const PEMDAS = 'Please Excuse My Dear Aunt Sally';
// https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence
// https://gist.github.com/527683/ef2abeb8e764d465ea430f440ebe4c534c8e3281
all = div.getElementsByTagName('i'); // live nodelist
document.querySelectorAll('i') // static nodelist
jQuery.cssHooks.opacity
// https://github.com/brandonaaron/jquery-cssHooks
// http://jsfiddle.net/paul/R4h4G/2/
//
$(elem).css('box-shadow','10px 10px 30px #bada55')
jQuery.fn
/*
888 d8b 888 888 d88P d8b
888 Y8P 888 888 d88P Y8P
888 888 888 d88P
88888b. 888 888888 888 888 888 d88P 8888 .d88888 .d8888b .d88b. 888 888 888d888 .d8888b .d88b.
888 "88b 888 888 888 888 888 d88P "888 d88" 888 88K d88""88b 888 888 888P" d88P" d8P Y8b
888 888 888 888 888 888 888 d88P 888 888 888 "Y8888b. 888 888 888 888 888 888 88888888
888 d88P 888 Y88b. d8b 888 Y88b 888 d88P 888 Y88b 888 X88 Y88..88P Y88b 888 888 Y88b. Y8b.
88888P" 888 "Y888 Y8P 888 "Y88888 d88P 888 "Y88888 88888P' "Y88P" "Y88888 888 "Y8888P "Y8888
888 888 888
Y8b d88P d88P 888
"Y88P" 888P" 888
http://bit.ly/jqsource
*/
__ 888 888 888 888
/ _) 888 888 888 888
.-^^^-/ / 888 888 888 888
_/ / 888888 88888b. 8888b. 88888b. 888 888 .d8888b 888
<__.|_|-|_| 888 888 "88b "88b 888 "88b 888 .88P 88K 888
888 888 888 .d888888 888 888 888888K "Y8888b. Y8P
Y88b. 888 888 888 888 888 888 888 "88b X88 "
"Y888 888 888 "Y888888 888 888 888 888 88888P' 888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment