link jQuery源码结构分析
row data 619 rows code.
// jQuery JavaScript Library v1.7
(function(window, undefined) {
// Use the correct document accordingly with window argument (sandbox)
var document = window.document,
navigator = window.navigator,
location = window.location;
// Define a local copy of jQuery
var jQuery = (function() {
// Define a local copy of jQuery
/** 使用var定义了一系列变量,第一个就是jQuery。最后定义完了用;隔开。 */
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
},
/** 其他一些成员的定义... */
class2type = {}; // 使用的是之前的var jQuery的var关键字。
/**
* jQuery.fn,我们jQuery对象的方法的命名空间使用,
* 实际上是jQuery的原型jQuery.prototype
*/
jQuery.fn = jQuery.prototype = {
constructor: jQuery,
init: function(selector, context, rootjQuery) {
/** */
},
selector: "", /** Start with an empty selector */
jQuery: "1.7", /** The current version of jQuery being used */
length: 0, /** The default length of a jQuery object isi 0 */
size: function() {return this.length;}, /** The number of elements contained in the matched element set */
toArray: function() {/** */},
get: function(num) {/** */},
pushStack: function(elems, name, selector) {/** */},
each: function(callback, args) {return jQuery.each(this, callback, args)},
ready: function(fn) {/** */},
eq: function(i) {/** */},
first: function() {return this.eq(0);},
last: function() {return this.eq(-1);},
slice: function() {/** */},
map: function(callback) {/** */},
end: function() {/** */},
/** For internal use only, Behaves like an Array's method, not like a jQuery method. */
push: push,
sort: [].sort,
splice: [].splice
};
// Give the init function the jQuery prototype for later instantiation
/** 将jQuery.prototype赋值给jQuery.fn.init.prototype */
jQuery.fn.init.prototype = jQuery.fn;
jQuery.extend = jQuery.fn.extend = function() {/** */};
// Populate the class2type map
jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
});
/** 3个if代码块 */
// All jQuery objects should point back to these
/** window.document对象是jQuery对象的根,所有jQuery对象都应该指回window.document */
rootjQuery = jQuery(document);
return jQuery; // 这个自调用函数会执行一次,返回内部创建好的jQuery对象。
})();
var flagsCache = {}; // String to Object flags format cache
// Convert String-formatted flags into Object-formatted ones and store in cache
function createFlags( flags ) {/** */}
// Create a callback list
jQuery.Callbacks = function( flags ) {/** */}
var sliceDeferred = [].slice; // Static reference to slice
jQuery.extend({
Deferred: function(func) {/** */},
when: function(firstParam) {/** */} /** Deferred helper */
});
jQuery.support = (function() {/** */})(); // 赋值为自调用函数的返回值
jQuery.boxModel = jQuery.support.boxModel; // Keep track of boxModel
var rbrace = /^(?:\{.*\}|\[.*\])$/,
rmultiDash = /([A-Z])/g;
jQuery.extend({/** */});
function dataAttr(elem, key, data) {/** */}
function isEmptyDataObject(obj) {/** */} // checks a cache object for emptiness
function handleQueueMarkDefer(elem, type, src) {/** */}
jQuery.extend({/** */});
jQuery.fn.extend({/** */});
// 定义了多个正则表达式变量
// var xxx = regex;
jQuery.fn.extend({/** */});
jQuery.fn.extend({/** */});
// Add the tabIndex propHook to attrHooks for back-compat (different case is intentional)
jQuery.attrHooks.tabindex = jQuery.propHooks.tabIndex;
// Hook for boolean attributes
boolHook = {
get: function(elem, name) {/** */},
set: function(elem, value, name) {/** */}
};
// IE6/7 do not support getting/setting some attributes with get/setAttribute
if ( !getSetAttribute ) {
/** */
}
// Some attributes require a special call on IE
if ( !jQuery.support.hrefNormalized ) {
/** */
}
if ( !jQuery.support.style ) {
/** */
}
// Safari mis-reports the default selected property of an option
// Accessing the parent's selectedIndex property fixes it
if ( !jQuery.support.optSelected ) {
/** */
}
// IE6/7 call enctype encoding
if ( !jQuery.support.enctype ) {
jQuery.propFix.enctype = "encoding";
}
// Radios and checkboxes getter/setter
if ( !jQuery.support.checkOn ) {
/** */
}
jQuery.each(["radio", "checkbox"], function() {
/** */
});
// 又是一些正则表达式
/*
* Helper functions for managing events -- not part of the public interface.
* Props to Dean Edwards' addEvent library for many of the ideas.
*/
jQuery.event = {
/** 一些成员属性和成员方法 */
}
// Some plugins are using, but it's undocumented/deprecated and will be removed.
// The 1.7 special event interface should provide all the hooks needed now.
jQuery.event.handle = jQuery.event.dispatch;
jQuery.removeEvent = /** */;
jQuery.Event = function(src, props) {
/** */
}
function returnFalse() {return false;}
function returnTrue() {return true;}
// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
jQuery.Event.prototype = {
/** */
}
// Create mouseenter/leave events using mouseover/out and event-time checks
jQuery.each({
mouseenter: "mouseover",
mouseleave: "mouseout"
}, function(orig, fix) {
/** */
});
// IE submit delegation
if (! jQuery.support.submitBubbles) {
/** */
}
// IE change delegation and checkbox/radio fix
if ( !jQuery.support.changeBubbles ) {
/** */
}
// Create "bubbling" focus and blur events
if ( !jQuery.support.focusinBubbles ) {
/** */
}
jQuery.fn.extend({
on: function(types, selector, data, fn, /** INTERNAL */one) {/** */},
one: function(types, selector, data, fn) {/** */},
off: function(types, selector, fn) {/** */},
bind: function(types, data, fn) {/** */},
unbind: function(types, fn) {/** */},
live: function(types, data, fn) {/** */},
die: function(types, fn) {/** */},
delegate: function(selector, types, data, fn) {/** */},
undelegate: function(selector, types, fn) {/** */},
trigger: function(type, data) {/** */},
triggerHandler: function(type, data) {/** */},
toggle: function(fn) {/** */},
hover: function(fnOver, fnOut) {/** */}
});
jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
// Handle event binding
jQuery.fn[ name ] = function( data, fn ) {
if ( fn == null ) {
fn = data;
data = null;
}
return arguments.length > 0 ?
this.bind( name, data, fn ) :
this.trigger( name );
};
if ( jQuery.attrFn ) {
jQuery.attrFn[ name ] = true;
}
if ( rkeyEvent.test( name ) ) {
jQuery.event.fixHooks[ name ] = jQuery.event.keyHooks;
}
if ( rmouseEvent.test( name ) ) {
jQuery.event.fixHooks[ name ] = jQuery.event.mouseHooks;
}
});
/**
* Sizzle CSS Selector Engine, More info: http://sizzlejs.com
*/
(function() {
/** 1.5k 行代码 */
});
/** 又是一些正则表达式和一些变量的声明 */
jQuery.fn.extend({
find: function(selector) {/** */},
has: function(target) {/** */},
not: function(selector) {/** */},
filter: function(selector) {/** */},
is: function(selector) {/** */},
closest: function(selectors, context) {/** */},
index: function(elem) {/** */},
add: function(selector, context) {/** */},
andSelf: function() {/** */}
});
// A painfully simple check to see if an element is disconnected
// from a document (should be improved, where feasible).
function isDisconnected( node ) {
return !node || !node.parentNode || node.parentNode.nodeType === 11;
}
jQuery.each({
/** */
}, function(name, fn) {
/** */
});
jQuery.extend({
filter: function(expr, elems, not) {/** */},
dir: function(elem, diir, until) {/** */},
nth: function(cur, result, dir, elem) {/** */},
sibling: function(n, elem) {/** */}
});
// Implement the identical functionality for filter and not
function winnow(elements, qualifier, keep) {
/** */
}
function createSafeFragment(document) {
/** */
}
/** 又是一些正则表达式和变量的定义 */
// IE can't serialize and