mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Break jQuery.access out into its own module to separate it from core; Adjust CommonJS+AMD build support to include non-var dependencies. Convert modules with more than a few dependencies to use CJS+AMD syntax.
This commit is contained in:
parent
2fe09ceaf9
commit
3b53b75160
@ -18,6 +18,9 @@ module.exports = function( grunt ) {
|
||||
out: "dist/jquery.js",
|
||||
// We have multiple minify steps
|
||||
optimize: "none",
|
||||
// Include dependencies loaded with require
|
||||
findNestedDependencies: true,
|
||||
// Avoid breaking semicolons inserted by r.js
|
||||
skipSemiColonInsertion: true,
|
||||
wrap: {
|
||||
startFile: "src/intro.js",
|
||||
@ -65,7 +68,7 @@ module.exports = function( grunt ) {
|
||||
// Remove CommonJS-style require calls
|
||||
// Keep an ending semicolon
|
||||
contents = contents
|
||||
.replace( /\w+ = require\(\s*(")[\w\.\/]+\1\s*\)([,;])/g,
|
||||
.replace( /(?:\s+\w+ = )?\s*require\(\s*(")[\w\.\/]+\1\s*\)([,;])/g,
|
||||
function( all, quote, commaSemicolon ) {
|
||||
return commaSemicolon === ";" ? ";" : "";
|
||||
});
|
||||
|
@ -2,16 +2,17 @@ define([
|
||||
"../core",
|
||||
"../var/rnotwhite",
|
||||
"../var/strundefined",
|
||||
"../core/access",
|
||||
"./support",
|
||||
"../selector"
|
||||
], function( jQuery, rnotwhite, strundefined, support ) {
|
||||
], function( jQuery, rnotwhite, strundefined, access, support ) {
|
||||
|
||||
var nodeHook, boolHook,
|
||||
attrHandle = jQuery.expr.attrHandle;
|
||||
|
||||
jQuery.fn.extend({
|
||||
attr: function( name, value ) {
|
||||
return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 );
|
||||
return access( this, jQuery.attr, name, value, arguments.length > 1 );
|
||||
},
|
||||
|
||||
removeAttr: function( name ) {
|
||||
|
@ -1,13 +1,14 @@
|
||||
define([
|
||||
"../core",
|
||||
"../core/access",
|
||||
"./support"
|
||||
], function( jQuery, support ) {
|
||||
], function( jQuery, access, support ) {
|
||||
|
||||
var rfocusable = /^(?:input|select|textarea|button)$/i;
|
||||
|
||||
jQuery.fn.extend({
|
||||
prop: function( name, value ) {
|
||||
return jQuery.access( this, jQuery.prop, name, value, arguments.length > 1 );
|
||||
return access( this, jQuery.prop, name, value, arguments.length > 1 );
|
||||
},
|
||||
|
||||
removeProp: function( name ) {
|
||||
|
53
src/core.js
53
src/core.js
@ -592,59 +592,6 @@ jQuery.extend({
|
||||
return proxy;
|
||||
},
|
||||
|
||||
// Multifunctional method to get and set values of a collection
|
||||
// The value/s can optionally be executed if it's a function
|
||||
access: function( elems, fn, key, value, chainable, emptyGet, raw ) {
|
||||
var i = 0,
|
||||
length = elems.length,
|
||||
bulk = key == null;
|
||||
|
||||
// Sets many values
|
||||
if ( jQuery.type( key ) === "object" ) {
|
||||
chainable = true;
|
||||
for ( i in key ) {
|
||||
jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
|
||||
}
|
||||
|
||||
// Sets one value
|
||||
} else if ( value !== undefined ) {
|
||||
chainable = true;
|
||||
|
||||
if ( !jQuery.isFunction( value ) ) {
|
||||
raw = true;
|
||||
}
|
||||
|
||||
if ( bulk ) {
|
||||
// Bulk operations run against the entire set
|
||||
if ( raw ) {
|
||||
fn.call( elems, value );
|
||||
fn = null;
|
||||
|
||||
// ...except when executing function values
|
||||
} else {
|
||||
bulk = fn;
|
||||
fn = function( elem, key, value ) {
|
||||
return bulk.call( jQuery( elem ), value );
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ( fn ) {
|
||||
for ( ; i < length; i++ ) {
|
||||
fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return chainable ?
|
||||
elems :
|
||||
|
||||
// Gets
|
||||
bulk ?
|
||||
fn.call( elems ) :
|
||||
length ? fn( elems[0], key ) : emptyGet;
|
||||
},
|
||||
|
||||
now: Date.now,
|
||||
|
||||
// jQuery.support is not used in Core but other projects attach their
|
||||
|
58
src/core/access.js
Normal file
58
src/core/access.js
Normal file
@ -0,0 +1,58 @@
|
||||
define([
|
||||
"../core"
|
||||
], function( jQuery ) {
|
||||
// Multifunctional method to get and set values of a collection
|
||||
// The value/s can optionally be executed if it's a function
|
||||
var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
|
||||
var i = 0,
|
||||
length = elems.length,
|
||||
bulk = key == null;
|
||||
|
||||
// Sets many values
|
||||
if ( jQuery.type( key ) === "object" ) {
|
||||
chainable = true;
|
||||
for ( i in key ) {
|
||||
jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
|
||||
}
|
||||
|
||||
// Sets one value
|
||||
} else if ( value !== undefined ) {
|
||||
chainable = true;
|
||||
|
||||
if ( !jQuery.isFunction( value ) ) {
|
||||
raw = true;
|
||||
}
|
||||
|
||||
if ( bulk ) {
|
||||
// Bulk operations run against the entire set
|
||||
if ( raw ) {
|
||||
fn.call( elems, value );
|
||||
fn = null;
|
||||
|
||||
// ...except when executing function values
|
||||
} else {
|
||||
bulk = fn;
|
||||
fn = function( elem, key, value ) {
|
||||
return bulk.call( jQuery( elem ), value );
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ( fn ) {
|
||||
for ( ; i < length; i++ ) {
|
||||
fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return chainable ?
|
||||
elems :
|
||||
|
||||
// Gets
|
||||
bulk ?
|
||||
fn.call( elems ) :
|
||||
length ? fn( elems[0], key ) : emptyGet;
|
||||
};
|
||||
|
||||
return access;
|
||||
});
|
36
src/css.js
36
src/css.js
@ -1,18 +1,17 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/pnum",
|
||||
"./css/var/cssExpand",
|
||||
"./css/var/isHidden",
|
||||
"./css/support",
|
||||
"./css/defaultDisplay",
|
||||
"./data/var/data_priv",
|
||||
"./css/swap",
|
||||
"./core/ready",
|
||||
"./selector", // contains
|
||||
// Optional
|
||||
"./offset"
|
||||
], function( jQuery, pnum, cssExpand, isHidden, support, defaultDisplay, data_priv ) {
|
||||
// Require more than a few needed variables
|
||||
// Keep in mind that a dependency array cannot be used with CommonJS+AMD syntax
|
||||
define(function( require ) {
|
||||
|
||||
var
|
||||
jQuery = require( "./core" ),
|
||||
pnum = require( "./var/pnum" ),
|
||||
access = require( "./core/access" ),
|
||||
cssExpand = require( "./css/var/cssExpand" ),
|
||||
isHidden = require( "./css/var/isHidden" ),
|
||||
support = require( "./css/support" ),
|
||||
defaultDisplay = require( "./css/defaultDisplay" ),
|
||||
data_priv = require( "./data/var/data_priv" ),
|
||||
|
||||
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
|
||||
// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
|
||||
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
|
||||
@ -29,6 +28,13 @@ var
|
||||
|
||||
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
|
||||
|
||||
// Dependencies not needed as vars
|
||||
require( "./css/swap" );
|
||||
require( "./core/ready" );
|
||||
require( "./selector" ); // contains
|
||||
// Optional
|
||||
require( "./offset" );
|
||||
|
||||
// return a css property mapped to a potentially vendor prefixed property
|
||||
function vendorPropName( style, name ) {
|
||||
|
||||
@ -487,7 +493,7 @@ jQuery.each({
|
||||
|
||||
jQuery.fn.extend({
|
||||
css: function( name, value ) {
|
||||
return jQuery.access( this, function( elem, name, value ) {
|
||||
return access( this, function( elem, name, value ) {
|
||||
var styles, len,
|
||||
map = {},
|
||||
i = 0;
|
||||
|
@ -1,9 +1,10 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/rnotwhite",
|
||||
"./core/access",
|
||||
"./data/var/data_priv",
|
||||
"./data/var/data_user"
|
||||
], function( jQuery, rnotwhite, data_priv, data_user ) {
|
||||
], function( jQuery, rnotwhite, access, data_priv, data_user ) {
|
||||
|
||||
/*
|
||||
Implementation Summary
|
||||
@ -79,7 +80,7 @@ jQuery.fn.extend({
|
||||
});
|
||||
}
|
||||
|
||||
return jQuery.access( this, function( value ) {
|
||||
return access( this, function( value ) {
|
||||
var data,
|
||||
camelKey = jQuery.camelCase( key );
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
define([
|
||||
"./core",
|
||||
"./core/access",
|
||||
"./css"
|
||||
], function( jQuery ) {
|
||||
], function( jQuery, access ) {
|
||||
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
|
||||
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
|
||||
jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
|
||||
@ -10,7 +11,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
|
||||
var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
|
||||
extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
|
||||
|
||||
return jQuery.access( this, function( elem, type, value ) {
|
||||
return access( this, function( elem, type, value ) {
|
||||
var doc;
|
||||
|
||||
if ( jQuery.isWindow( elem ) ) {
|
||||
|
28
src/effects.js
vendored
28
src/effects.js
vendored
@ -1,17 +1,12 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/pnum",
|
||||
"./css/var/cssExpand",
|
||||
"./css/var/isHidden",
|
||||
"./effects/Tween",
|
||||
"./data/var/data_priv",
|
||||
"./queue",
|
||||
"./css",
|
||||
"./deferred",
|
||||
"./traversing"
|
||||
], function( jQuery, pnum, cssExpand, isHidden, Tween, data_priv ) {
|
||||
define(function( require ) {
|
||||
|
||||
var fxNow, timerId,
|
||||
var
|
||||
jQuery = require( "./core" ),
|
||||
pnum = require( "./var/pnum" ),
|
||||
cssExpand = require( "./css/var/cssExpand" ),
|
||||
isHidden = require( "./css/var/isHidden" ),
|
||||
data_priv = require( "./data/var/data_priv" ),
|
||||
fxNow, timerId,
|
||||
rfxtypes = /^(?:toggle|show|hide)$/,
|
||||
rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
|
||||
rrun = /queueHooks$/,
|
||||
@ -67,6 +62,13 @@ var fxNow, timerId,
|
||||
}]
|
||||
};
|
||||
|
||||
// Dependencies not needed as vars
|
||||
require( "./effects/Tween" );
|
||||
require( "./queue" );
|
||||
require( "./css" );
|
||||
require( "./deferred" );
|
||||
require( "./traversing" );
|
||||
|
||||
// Animations created synchronously will run synchronously
|
||||
function createFxNow() {
|
||||
setTimeout(function() {
|
||||
|
26
src/event.js
26
src/event.js
@ -1,20 +1,22 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/strundefined",
|
||||
"./var/rnotwhite",
|
||||
"./var/hasOwn",
|
||||
"./var/slice",
|
||||
"./event/support",
|
||||
"./data/var/data_priv",
|
||||
"./data/accepts",
|
||||
"./selector"
|
||||
], function( jQuery, strundefined, rnotwhite, hasOwn, slice, support, data_priv ) {
|
||||
define(function( require ) {
|
||||
|
||||
var rkeyEvent = /^key/,
|
||||
var
|
||||
jQuery = require( "./core" ),
|
||||
strundefined = require( "./var/strundefined" ),
|
||||
rnotwhite = require( "./var/rnotwhite" ),
|
||||
hasOwn = require( "./var/hasOwn" ),
|
||||
slice = require( "./var/slice" ),
|
||||
support = require( "./event/support" ),
|
||||
data_priv = require( "./data/var/data_priv" ),
|
||||
rkeyEvent = /^key/,
|
||||
rmouseEvent = /^(?:mouse|contextmenu)|click/,
|
||||
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
|
||||
rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
|
||||
|
||||
// Dependencies not needed as vars
|
||||
require( "./data/accepts" );
|
||||
require( "./selector" );
|
||||
|
||||
function returnTrue() {
|
||||
return true;
|
||||
}
|
||||
|
@ -1,18 +1,23 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/concat",
|
||||
"./var/push",
|
||||
"./manipulation/var/rcheckableType",
|
||||
"./manipulation/support",
|
||||
"./data/var/data_priv",
|
||||
"./data/var/data_user",
|
||||
"./data/accepts",
|
||||
"./selector",
|
||||
"./traversing",
|
||||
"./event"
|
||||
], function( jQuery, concat, push, rcheckableType, support, data_priv, data_user ){
|
||||
// Require more than a few needed variables
|
||||
// Keep in mind that a dependency array cannot be used with CommonJS+AMD syntax
|
||||
define(function( require ){
|
||||
|
||||
var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
|
||||
// Dependencies not needed as variables
|
||||
require( "./data/accepts" );
|
||||
require( "./traversing" );
|
||||
require( "./selector" );
|
||||
require( "./event" );
|
||||
|
||||
var
|
||||
jQuery = require( "./core" ),
|
||||
concat = require( "./var/concat" ),
|
||||
push = require( "./var/push" ),
|
||||
access = require( "./core/access" ),
|
||||
rcheckableType = require( "./manipulation/var/rcheckableType" ),
|
||||
support = require( "./manipulation/support" ),
|
||||
data_priv = require( "./data/var/data_priv" ),
|
||||
data_user = require( "./data/var/data_user" ),
|
||||
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
|
||||
rtagName = /<([\w:]+)/,
|
||||
rhtml = /<|&#?\w+;/,
|
||||
rnoInnerhtml = /<(?:script|style|link)/i,
|
||||
@ -44,7 +49,7 @@ wrapMap.th = wrapMap.td;
|
||||
|
||||
jQuery.fn.extend({
|
||||
text: function( value ) {
|
||||
return jQuery.access( this, function( value ) {
|
||||
return access( this, function( value ) {
|
||||
return value === undefined ?
|
||||
jQuery.text( this ) :
|
||||
this.empty().append( ( this[ 0 ] && this[ 0 ].ownerDocument || document ).createTextNode( value ) );
|
||||
@ -134,7 +139,7 @@ jQuery.fn.extend({
|
||||
},
|
||||
|
||||
html: function( value ) {
|
||||
return jQuery.access( this, function( value ) {
|
||||
return access( this, function( value ) {
|
||||
var elem = this[ 0 ] || {},
|
||||
i = 0,
|
||||
l = this.length;
|
||||
|
@ -1,9 +1,10 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/strundefined",
|
||||
"./core/access",
|
||||
"./css",
|
||||
"./selector" // contains
|
||||
], function( jQuery, strundefined ) {
|
||||
], function( jQuery, strundefined, access ) {
|
||||
|
||||
var docElem = window.document.documentElement;
|
||||
|
||||
@ -158,7 +159,7 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me
|
||||
var top = "pageYOffset" === prop;
|
||||
|
||||
jQuery.fn[ method ] = function( val ) {
|
||||
return jQuery.access( this, function( elem, method, val ) {
|
||||
return access( this, function( elem, method, val ) {
|
||||
var win = getWindow( elem );
|
||||
|
||||
if ( val === undefined ) {
|
||||
|
@ -3,6 +3,7 @@ define([
|
||||
"./var/indexOf",
|
||||
"./selector"
|
||||
], function( jQuery, indexOf ) {
|
||||
|
||||
var isSimple = /^.[^:#\[\.,]*$/,
|
||||
rparentsprev = /^(?:parents|prev(?:Until|All))/,
|
||||
rneedsContext = jQuery.expr.match.needsContext,
|
||||
|
@ -2,6 +2,7 @@ define([
|
||||
"./core",
|
||||
"./traversing" // parent, contents
|
||||
], function( jQuery ) {
|
||||
|
||||
jQuery.fn.extend({
|
||||
wrapAll: function( html ) {
|
||||
var wrap;
|
||||
|
Loading…
Reference in New Issue
Block a user