Skip to content

Commit 3b53b75

Browse files
committed
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.
1 parent 2fe09ce commit 3b53b75

File tree

14 files changed

+153
-123
lines changed

14 files changed

+153
-123
lines changed

build/tasks/build.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ module.exports = function( grunt ) {
1818
out: "dist/jquery.js",
1919
// We have multiple minify steps
2020
optimize: "none",
21+
// Include dependencies loaded with require
22+
findNestedDependencies: true,
23+
// Avoid breaking semicolons inserted by r.js
2124
skipSemiColonInsertion: true,
2225
wrap: {
2326
startFile: "src/intro.js",
@@ -65,7 +68,7 @@ module.exports = function( grunt ) {
6568
// Remove CommonJS-style require calls
6669
// Keep an ending semicolon
6770
contents = contents
68-
.replace( /\w+ = require\(\s*(")[\w\.\/]+\1\s*\)([,;])/g,
71+
.replace( /(?:\s+\w+ = )?\s*require\(\s*(")[\w\.\/]+\1\s*\)([,;])/g,
6972
function( all, quote, commaSemicolon ) {
7073
return commaSemicolon === ";" ? ";" : "";
7174
});

src/attributes/attr.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ define([
22
"../core",
33
"../var/rnotwhite",
44
"../var/strundefined",
5+
"../core/access",
56
"./support",
67
"../selector"
7-
], function( jQuery, rnotwhite, strundefined, support ) {
8+
], function( jQuery, rnotwhite, strundefined, access, support ) {
89

910
var nodeHook, boolHook,
1011
attrHandle = jQuery.expr.attrHandle;
1112

1213
jQuery.fn.extend({
1314
attr: function( name, value ) {
14-
return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 );
15+
return access( this, jQuery.attr, name, value, arguments.length > 1 );
1516
},
1617

1718
removeAttr: function( name ) {

src/attributes/prop.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
define([
22
"../core",
3+
"../core/access",
34
"./support"
4-
], function( jQuery, support ) {
5+
], function( jQuery, access, support ) {
56

67
var rfocusable = /^(?:input|select|textarea|button)$/i;
78

89
jQuery.fn.extend({
910
prop: function( name, value ) {
10-
return jQuery.access( this, jQuery.prop, name, value, arguments.length > 1 );
11+
return access( this, jQuery.prop, name, value, arguments.length > 1 );
1112
},
1213

1314
removeProp: function( name ) {

src/core.js

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -592,59 +592,6 @@ jQuery.extend({
592592
return proxy;
593593
},
594594

595-
// Multifunctional method to get and set values of a collection
596-
// The value/s can optionally be executed if it's a function
597-
access: function( elems, fn, key, value, chainable, emptyGet, raw ) {
598-
var i = 0,
599-
length = elems.length,
600-
bulk = key == null;
601-
602-
// Sets many values
603-
if ( jQuery.type( key ) === "object" ) {
604-
chainable = true;
605-
for ( i in key ) {
606-
jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
607-
}
608-
609-
// Sets one value
610-
} else if ( value !== undefined ) {
611-
chainable = true;
612-
613-
if ( !jQuery.isFunction( value ) ) {
614-
raw = true;
615-
}
616-
617-
if ( bulk ) {
618-
// Bulk operations run against the entire set
619-
if ( raw ) {
620-
fn.call( elems, value );
621-
fn = null;
622-
623-
// ...except when executing function values
624-
} else {
625-
bulk = fn;
626-
fn = function( elem, key, value ) {
627-
return bulk.call( jQuery( elem ), value );
628-
};
629-
}
630-
}
631-
632-
if ( fn ) {
633-
for ( ; i < length; i++ ) {
634-
fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
635-
}
636-
}
637-
}
638-
639-
return chainable ?
640-
elems :
641-
642-
// Gets
643-
bulk ?
644-
fn.call( elems ) :
645-
length ? fn( elems[0], key ) : emptyGet;
646-
},
647-
648595
now: Date.now,
649596

650597
// jQuery.support is not used in Core but other projects attach their

src/core/access.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
define([
2+
"../core"
3+
], function( jQuery ) {
4+
// Multifunctional method to get and set values of a collection
5+
// The value/s can optionally be executed if it's a function
6+
var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
7+
var i = 0,
8+
length = elems.length,
9+
bulk = key == null;
10+
11+
// Sets many values
12+
if ( jQuery.type( key ) === "object" ) {
13+
chainable = true;
14+
for ( i in key ) {
15+
jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
16+
}
17+
18+
// Sets one value
19+
} else if ( value !== undefined ) {
20+
chainable = true;
21+
22+
if ( !jQuery.isFunction( value ) ) {
23+
raw = true;
24+
}
25+
26+
if ( bulk ) {
27+
// Bulk operations run against the entire set
28+
if ( raw ) {
29+
fn.call( elems, value );
30+
fn = null;
31+
32+
// ...except when executing function values
33+
} else {
34+
bulk = fn;
35+
fn = function( elem, key, value ) {
36+
return bulk.call( jQuery( elem ), value );
37+
};
38+
}
39+
}
40+
41+
if ( fn ) {
42+
for ( ; i < length; i++ ) {
43+
fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
44+
}
45+
}
46+
}
47+
48+
return chainable ?
49+
elems :
50+
51+
// Gets
52+
bulk ?
53+
fn.call( elems ) :
54+
length ? fn( elems[0], key ) : emptyGet;
55+
};
56+
57+
return access;
58+
});

src/css.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
define([
2-
"./core",
3-
"./var/pnum",
4-
"./css/var/cssExpand",
5-
"./css/var/isHidden",
6-
"./css/support",
7-
"./css/defaultDisplay",
8-
"./data/var/data_priv",
9-
"./css/swap",
10-
"./core/ready",
11-
"./selector", // contains
12-
// Optional
13-
"./offset"
14-
], function( jQuery, pnum, cssExpand, isHidden, support, defaultDisplay, data_priv ) {
1+
// Require more than a few needed variables
2+
// Keep in mind that a dependency array cannot be used with CommonJS+AMD syntax
3+
define(function( require ) {
4+
155
var
6+
jQuery = require( "./core" ),
7+
pnum = require( "./var/pnum" ),
8+
access = require( "./core/access" ),
9+
cssExpand = require( "./css/var/cssExpand" ),
10+
isHidden = require( "./css/var/isHidden" ),
11+
support = require( "./css/support" ),
12+
defaultDisplay = require( "./css/defaultDisplay" ),
13+
data_priv = require( "./data/var/data_priv" ),
14+
1615
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
1716
// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
1817
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
@@ -29,6 +28,13 @@ var
2928

3029
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
3130

31+
// Dependencies not needed as vars
32+
require( "./css/swap" );
33+
require( "./core/ready" );
34+
require( "./selector" ); // contains
35+
// Optional
36+
require( "./offset" );
37+
3238
// return a css property mapped to a potentially vendor prefixed property
3339
function vendorPropName( style, name ) {
3440

@@ -487,7 +493,7 @@ jQuery.each({
487493

488494
jQuery.fn.extend({
489495
css: function( name, value ) {
490-
return jQuery.access( this, function( elem, name, value ) {
496+
return access( this, function( elem, name, value ) {
491497
var styles, len,
492498
map = {},
493499
i = 0;

src/data.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
define([
22
"./core",
33
"./var/rnotwhite",
4+
"./core/access",
45
"./data/var/data_priv",
56
"./data/var/data_user"
6-
], function( jQuery, rnotwhite, data_priv, data_user ) {
7+
], function( jQuery, rnotwhite, access, data_priv, data_user ) {
78

89
/*
910
Implementation Summary
@@ -79,7 +80,7 @@ jQuery.fn.extend({
7980
});
8081
}
8182

82-
return jQuery.access( this, function( value ) {
83+
return access( this, function( value ) {
8384
var data,
8485
camelKey = jQuery.camelCase( key );
8586

src/dimensions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
define([
22
"./core",
3+
"./core/access",
34
"./css"
4-
], function( jQuery ) {
5+
], function( jQuery, access ) {
56
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
67
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
78
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 ) {
1011
var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
1112
extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
1213

13-
return jQuery.access( this, function( elem, type, value ) {
14+
return access( this, function( elem, type, value ) {
1415
var doc;
1516

1617
if ( jQuery.isWindow( elem ) ) {

src/effects.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
define([
2-
"./core",
3-
"./var/pnum",
4-
"./css/var/cssExpand",
5-
"./css/var/isHidden",
6-
"./effects/Tween",
7-
"./data/var/data_priv",
8-
"./queue",
9-
"./css",
10-
"./deferred",
11-
"./traversing"
12-
], function( jQuery, pnum, cssExpand, isHidden, Tween, data_priv ) {
13-
14-
var fxNow, timerId,
1+
define(function( require ) {
2+
3+
var
4+
jQuery = require( "./core" ),
5+
pnum = require( "./var/pnum" ),
6+
cssExpand = require( "./css/var/cssExpand" ),
7+
isHidden = require( "./css/var/isHidden" ),
8+
data_priv = require( "./data/var/data_priv" ),
9+
fxNow, timerId,
1510
rfxtypes = /^(?:toggle|show|hide)$/,
1611
rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
1712
rrun = /queueHooks$/,
@@ -67,6 +62,13 @@ var fxNow, timerId,
6762
}]
6863
};
6964

65+
// Dependencies not needed as vars
66+
require( "./effects/Tween" );
67+
require( "./queue" );
68+
require( "./css" );
69+
require( "./deferred" );
70+
require( "./traversing" );
71+
7072
// Animations created synchronously will run synchronously
7173
function createFxNow() {
7274
setTimeout(function() {

src/event.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
define([
2-
"./core",
3-
"./var/strundefined",
4-
"./var/rnotwhite",
5-
"./var/hasOwn",
6-
"./var/slice",
7-
"./event/support",
8-
"./data/var/data_priv",
9-
"./data/accepts",
10-
"./selector"
11-
], function( jQuery, strundefined, rnotwhite, hasOwn, slice, support, data_priv ) {
12-
13-
var rkeyEvent = /^key/,
1+
define(function( require ) {
2+
3+
var
4+
jQuery = require( "./core" ),
5+
strundefined = require( "./var/strundefined" ),
6+
rnotwhite = require( "./var/rnotwhite" ),
7+
hasOwn = require( "./var/hasOwn" ),
8+
slice = require( "./var/slice" ),
9+
support = require( "./event/support" ),
10+
data_priv = require( "./data/var/data_priv" ),
11+
rkeyEvent = /^key/,
1412
rmouseEvent = /^(?:mouse|contextmenu)|click/,
1513
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
1614
rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
1715

16+
// Dependencies not needed as vars
17+
require( "./data/accepts" );
18+
require( "./selector" );
19+
1820
function returnTrue() {
1921
return true;
2022
}

0 commit comments

Comments
 (0)