Skip to content

Commit 2063d6c

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.
Conflicts: src/core.js src/css.js src/data.js src/effects.js src/event.js src/manipulation.js src/traversing.js
1 parent fb599f6 commit 2063d6c

File tree

14 files changed

+157
-123
lines changed

14 files changed

+157
-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,10 +2,11 @@ define([
22
"../core",
33
"../var/rnotwhite",
44
"../var/strundefined",
5+
"../core/access",
56
"./support",
67
"./val",
78
"../selector"
8-
], function( jQuery, rnotwhite, strundefined, support ) {
9+
], function( jQuery, rnotwhite, strundefined, access, support ) {
910

1011
var nodeHook, boolHook,
1112
attrHandle = jQuery.expr.attrHandle,
@@ -15,7 +16,7 @@ var nodeHook, boolHook,
1516

1617
jQuery.fn.extend({
1718
attr: function( name, value ) {
18-
return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 );
19+
return access( this, jQuery.attr, name, value, arguments.length > 1 );
1920
},
2021

2122
removeAttr: function( name ) {

src/attributes/prop.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
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|object)$/i,
78
rclickable = /^(?:a|area)$/i;
89

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

1415
removeProp: function( name ) {

src/core.js

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -606,59 +606,6 @@ jQuery.extend({
606606
return proxy;
607607
},
608608

609-
// Multifunctional method to get and set values of a collection
610-
// The value/s can optionally be executed if it's a function
611-
access: function( elems, fn, key, value, chainable, emptyGet, raw ) {
612-
var i = 0,
613-
length = elems.length,
614-
bulk = key == null;
615-
616-
// Sets many values
617-
if ( jQuery.type( key ) === "object" ) {
618-
chainable = true;
619-
for ( i in key ) {
620-
jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
621-
}
622-
623-
// Sets one value
624-
} else if ( value !== undefined ) {
625-
chainable = true;
626-
627-
if ( !jQuery.isFunction( value ) ) {
628-
raw = true;
629-
}
630-
631-
if ( bulk ) {
632-
// Bulk operations run against the entire set
633-
if ( raw ) {
634-
fn.call( elems, value );
635-
fn = null;
636-
637-
// ...except when executing function values
638-
} else {
639-
bulk = fn;
640-
fn = function( elem, key, value ) {
641-
return bulk.call( jQuery( elem ), value );
642-
};
643-
}
644-
}
645-
646-
if ( fn ) {
647-
for ( ; i < length; i++ ) {
648-
fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
649-
}
650-
}
651-
}
652-
653-
return chainable ?
654-
elems :
655-
656-
// Gets
657-
bulk ?
658-
fn.call( elems ) :
659-
length ? fn( elems[0], key ) : emptyGet;
660-
},
661-
662609
now: function() {
663610
return ( new Date() ).getTime();
664611
},

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: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
define([
2-
"./core",
3-
"./var/pnum",
4-
"./css/var/cssExpand",
5-
"./css/var/isHidden",
6-
"./css/defaultDisplay",
7-
"./css/support",
8-
"./css/swap",
9-
"./selector", // contains
10-
// Optional
11-
"./offset"
12-
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, support ) {
13-
14-
var getStyles, curCSS,
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+
5+
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+
14+
getStyles, curCSS,
1515
ralpha = /alpha\([^)]*\)/i,
1616
ropacity = /opacity\s*=\s*([^)]*)/,
1717
rposition = /^(top|right|bottom|left)$/,
18+
1819
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
1920
// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
2021
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
@@ -31,6 +32,14 @@ var getStyles, curCSS,
3132

3233
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
3334

35+
// Dependencies not needed as vars
36+
require( "./css/swap" );
37+
require( "./core/ready" );
38+
require( "./selector" ); // contains
39+
// Optional
40+
require( "./offset" );
41+
42+
3443
// NOTE: we've included the "window" in window.getComputedStyle
3544
// because jsdom on node.js will break without it.
3645
if ( window.getComputedStyle ) {
@@ -598,8 +607,8 @@ jQuery.each({
598607

599608
jQuery.fn.extend({
600609
css: function( name, value ) {
601-
return jQuery.access( this, function( elem, name, value ) {
602-
var len, styles,
610+
return access( this, function( elem, name, value ) {
611+
var styles, len,
603612
map = {},
604613
i = 0;
605614

src/data.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ define([
88
var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
99
rmultiDash = /([A-Z])/g;
1010

11-
1211
function dataAttr( elem, key, data ) {
1312
// If nothing was found internally, try to fetch any
1413
// data from the HTML5 data-* attribute

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: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
define([
2-
"./core",
3-
"./var/pnum",
4-
"./css/var/cssExpand",
5-
"./css/var/isHidden",
6-
"./css/defaultDisplay",
7-
"./effects/support",
8-
"./effects/Tween",
9-
"./queue",
10-
"./css",
11-
"./deferred",
12-
"./traversing"
13-
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, support) {
14-
15-
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+
defaultDisplay = require( "./css/defaultDisplay" ),
9+
support = require( "./css/support" ),
10+
11+
fxNow, timerId,
1612
rfxtypes = /^(?:toggle|show|hide)$/,
1713
rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
1814
rrun = /queueHooks$/,
@@ -68,6 +64,13 @@ var fxNow, timerId,
6864
}]
6965
};
7066

67+
// Dependencies not needed as vars
68+
require( "./effects/Tween" );
69+
require( "./queue" );
70+
require( "./css" );
71+
require( "./deferred" );
72+
require( "./traversing" );
73+
7174
// Animations created synchronously will run synchronously
7275
function createFxNow() {
7376
setTimeout(function() {

src/event.js

Lines changed: 14 additions & 12 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/accepts",
9-
"./selector"
10-
], function( jQuery, strundefined, rnotwhite, hasOwn, slice, support ) {
11-
12-
var rformElems = /^(?:input|select|textarea)$/i,
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+
rformElems = /^(?:input|select|textarea)$/i,
1311
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)