Commit 2063d6c1 authored by Timmy Willison's avatar Timmy Willison

Break jQuery.access out into its own module to separate it from core; Adjust...

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
parent fb599f63
...@@ -18,6 +18,9 @@ module.exports = function( grunt ) { ...@@ -18,6 +18,9 @@ module.exports = function( grunt ) {
out: "dist/jquery.js", out: "dist/jquery.js",
// We have multiple minify steps // We have multiple minify steps
optimize: "none", optimize: "none",
// Include dependencies loaded with require
findNestedDependencies: true,
// Avoid breaking semicolons inserted by r.js
skipSemiColonInsertion: true, skipSemiColonInsertion: true,
wrap: { wrap: {
startFile: "src/intro.js", startFile: "src/intro.js",
...@@ -65,7 +68,7 @@ module.exports = function( grunt ) { ...@@ -65,7 +68,7 @@ module.exports = function( grunt ) {
// Remove CommonJS-style require calls // Remove CommonJS-style require calls
// Keep an ending semicolon // Keep an ending semicolon
contents = contents contents = contents
.replace( /\w+ = require\(\s*(")[\w\.\/]+\1\s*\)([,;])/g, .replace( /(?:\s+\w+ = )?\s*require\(\s*(")[\w\.\/]+\1\s*\)([,;])/g,
function( all, quote, commaSemicolon ) { function( all, quote, commaSemicolon ) {
return commaSemicolon === ";" ? ";" : ""; return commaSemicolon === ";" ? ";" : "";
}); });
......
...@@ -2,10 +2,11 @@ define([ ...@@ -2,10 +2,11 @@ define([
"../core", "../core",
"../var/rnotwhite", "../var/rnotwhite",
"../var/strundefined", "../var/strundefined",
"../core/access",
"./support", "./support",
"./val", "./val",
"../selector" "../selector"
], function( jQuery, rnotwhite, strundefined, support ) { ], function( jQuery, rnotwhite, strundefined, access, support ) {
var nodeHook, boolHook, var nodeHook, boolHook,
attrHandle = jQuery.expr.attrHandle, attrHandle = jQuery.expr.attrHandle,
...@@ -15,7 +16,7 @@ var nodeHook, boolHook, ...@@ -15,7 +16,7 @@ var nodeHook, boolHook,
jQuery.fn.extend({ jQuery.fn.extend({
attr: function( name, value ) { 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 ) { removeAttr: function( name ) {
......
define([ define([
"../core", "../core",
"../core/access",
"./support" "./support"
], function( jQuery, support ) { ], function( jQuery, access, support ) {
var rfocusable = /^(?:input|select|textarea|button|object)$/i, var rfocusable = /^(?:input|select|textarea|button|object)$/i,
rclickable = /^(?:a|area)$/i; rclickable = /^(?:a|area)$/i;
jQuery.fn.extend({ jQuery.fn.extend({
prop: function( name, value ) { 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 ) { removeProp: function( name ) {
......
...@@ -606,59 +606,6 @@ jQuery.extend({ ...@@ -606,59 +606,6 @@ jQuery.extend({
return proxy; 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: function() { now: function() {
return ( new Date() ).getTime(); return ( new Date() ).getTime();
}, },
......
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;
});
define([ // Require more than a few needed variables
"./core", // Keep in mind that a dependency array cannot be used with CommonJS+AMD syntax
"./var/pnum", define(function( require ) {
"./css/var/cssExpand",
"./css/var/isHidden", var
"./css/defaultDisplay", jQuery = require( "./core" ),
"./css/support", pnum = require( "./var/pnum" ),
"./css/swap", access = require( "./core/access" ),
"./selector", // contains cssExpand = require( "./css/var/cssExpand" ),
// Optional isHidden = require( "./css/var/isHidden" ),
"./offset" support = require( "./css/support" ),
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, support ) { defaultDisplay = require( "./css/defaultDisplay" ),
var getStyles, curCSS, getStyles, curCSS,
ralpha = /alpha\([^)]*\)/i, ralpha = /alpha\([^)]*\)/i,
ropacity = /opacity\s*=\s*([^)]*)/, ropacity = /opacity\s*=\s*([^)]*)/,
rposition = /^(top|right|bottom|left)$/, rposition = /^(top|right|bottom|left)$/,
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption" // 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 // see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
rdisplayswap = /^(none|table(?!-c[ea]).+)/, rdisplayswap = /^(none|table(?!-c[ea]).+)/,
...@@ -31,6 +32,14 @@ var getStyles, curCSS, ...@@ -31,6 +32,14 @@ var getStyles, curCSS,
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ]; cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
// Dependencies not needed as vars
require( "./css/swap" );
require( "./core/ready" );
require( "./selector" ); // contains
// Optional
require( "./offset" );
// NOTE: we've included the "window" in window.getComputedStyle // NOTE: we've included the "window" in window.getComputedStyle
// because jsdom on node.js will break without it. // because jsdom on node.js will break without it.
if ( window.getComputedStyle ) { if ( window.getComputedStyle ) {
...@@ -598,8 +607,8 @@ jQuery.each({ ...@@ -598,8 +607,8 @@ jQuery.each({
jQuery.fn.extend({ jQuery.fn.extend({
css: function( name, value ) { css: function( name, value ) {
return jQuery.access( this, function( elem, name, value ) { return access( this, function( elem, name, value ) {
var len, styles, var styles, len,
map = {}, map = {},
i = 0; i = 0;
......
...@@ -8,7 +8,6 @@ define([ ...@@ -8,7 +8,6 @@ define([
var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/, var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
rmultiDash = /([A-Z])/g; rmultiDash = /([A-Z])/g;
function dataAttr( elem, key, data ) { function dataAttr( elem, key, data ) {
// If nothing was found internally, try to fetch any // If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute // data from the HTML5 data-* attribute
......
define([ define([
"./core", "./core",
"./core/access",
"./css" "./css"
], function( jQuery ) { ], function( jQuery, access ) {
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) { 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 ) { ...@@ -10,7 +11,7 @@ jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ), var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" ); 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; var doc;
if ( jQuery.isWindow( elem ) ) { if ( jQuery.isWindow( elem ) ) {
......
define([ define(function( require ) {
"./core",
"./var/pnum", var
"./css/var/cssExpand", jQuery = require( "./core" ),
"./css/var/isHidden", pnum = require( "./var/pnum" ),
"./css/defaultDisplay", cssExpand = require( "./css/var/cssExpand" ),
"./effects/support", isHidden = require( "./css/var/isHidden" ),
"./effects/Tween", defaultDisplay = require( "./css/defaultDisplay" ),
"./queue", support = require( "./css/support" ),
"./css",
"./deferred", fxNow, timerId,
"./traversing"
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, support) {
var fxNow, timerId,
rfxtypes = /^(?:toggle|show|hide)$/, rfxtypes = /^(?:toggle|show|hide)$/,
rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ), rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
rrun = /queueHooks$/, rrun = /queueHooks$/,
...@@ -68,6 +64,13 @@ var fxNow, timerId, ...@@ -68,6 +64,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 // Animations created synchronously will run synchronously
function createFxNow() { function createFxNow() {
setTimeout(function() { setTimeout(function() {
......
define([ define(function( require ) {
"./core",
"./var/strundefined", var
"./var/rnotwhite", jQuery = require( "./core" ),
"./var/hasOwn", strundefined = require( "./var/strundefined" ),
"./var/slice", rnotwhite = require( "./var/rnotwhite" ),
"./event/support", hasOwn = require( "./var/hasOwn" ),
"./data/accepts", slice = require( "./var/slice" ),
"./selector" support = require( "./event/support" ),
], function( jQuery, strundefined, rnotwhite, hasOwn, slice, support ) { rformElems = /^(?:input|select|textarea)$/i,
var rformElems = /^(?:input|select|textarea)$/i,
rkeyEvent = /^key/, rkeyEvent = /^key/,
rmouseEvent = /^(?:mouse|contextmenu)|click/, rmouseEvent = /^(?:mouse|contextmenu)|click/,
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
rtypenamespace = /^([^.]*)(?:\.(.+)|)$/; rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
// Dependencies not needed as vars
require( "./data/accepts" );
require( "./selector" );
function returnTrue() { function returnTrue() {
return true; return true;
} }
......
define([ // Require more than a few needed variables
"./core", // Keep in mind that a dependency array cannot be used with CommonJS+AMD syntax
"./var/concat", define(function( require ){
"./var/push",
"./var/deletedIds", // Dependencies not needed as variables
"./var/strundefined", require( "./data/accepts" );
"./manipulation/var/rcheckableType", require( "./traversing" );
"./manipulation/support", require( "./selector" );
"./data/accepts", require( "./event" );
"./selector",
"./traversing",
"./event"
], function( jQuery, concat, push, deletedIds, strundefined, rcheckableType, support ){
function createSafeFragment( document ) { function createSafeFragment( document ) {
var list = nodeNames.split( "|" ), var list = nodeNames.split( "|" ),
...@@ -26,11 +22,22 @@ function createSafeFragment( document ) { ...@@ -26,11 +22,22 @@ function createSafeFragment( document ) {
return safeFrag; return safeFrag;
} }
var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" + var
jQuery = require( "./core" ),
strundefined = require( "./var/strundefined" ),
concat = require( "./var/concat" ),
push = require( "./var/push" ),
deletedIds = require( "./var/deletedIds" ),
access = require( "./core/access" ),
rcheckableType = require( "./manipulation/var/rcheckableType" ),
support = require( "./manipulation/support" ),
nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" +
"header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",
rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g, rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g,
rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"), rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"),
rleadingWhitespace = /^\s+/, rleadingWhitespace = /^\s+/,
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
rtagName = /<([\w:]+)/, rtagName = /<([\w:]+)/,
rtbody = /<tbody/i, rtbody = /<tbody/i,
...@@ -66,7 +73,7 @@ wrapMap.th = wrapMap.td; ...@@ -66,7 +73,7 @@ wrapMap.th = wrapMap.td;
jQuery.fn.extend({ jQuery.fn.extend({
text: function( value ) { text: function( value ) {
return jQuery.access( this, function( value ) { return access( this, function( value ) {
return value === undefined ? return value === undefined ?
jQuery.text( this ) : jQuery.text( this ) :
this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) ); this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) );
...@@ -164,8 +171,8 @@ jQuery.fn.extend({ ...@@ -164,8 +171,8 @@ jQuery.fn.extend({
}, },
html: function( value ) { html: function( value ) {
return jQuery.access( this, function( value ) { return access( this, function( value ) {
var elem = this[0] || {}, var elem = this[ 0 ] || {},
i = 0, i = 0,
l = this.length; l = this.length;
......
define([ define([
"./core", "./core",
"./var/strundefined", "./var/strundefined",
"./core/access",
"./css", "./css",
"./selector" // contains "./selector" // contains
], function( jQuery, strundefined ) { ], function( jQuery, strundefined, access ) {
var docElem = window.document.documentElement; var docElem = window.document.documentElement;
...@@ -160,7 +161,7 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me ...@@ -160,7 +161,7 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me
var top = /Y/.test( prop ); var top = /Y/.test( prop );
jQuery.fn[ method ] = function( val ) { jQuery.fn[ method ] = function( val ) {
return jQuery.access( this, function( elem, method, val ) { return access( this, function( elem, method, val ) {
var win = getWindow( elem ); var win = getWindow( elem );
if ( val === undefined ) { if ( val === undefined ) {
......
...@@ -2,6 +2,7 @@ define([ ...@@ -2,6 +2,7 @@ define([
"./core", "./core",
"./selector" "./selector"
], function( jQuery ) { ], function( jQuery ) {
var isSimple = /^.[^:#\[\.,]*$/, var isSimple = /^.[^:#\[\.,]*$/,
rparentsprev = /^(?:parents|prev(?:Until|All))/, rparentsprev = /^(?:parents|prev(?:Until|All))/,
rneedsContext = jQuery.expr.match.needsContext, rneedsContext = jQuery.expr.match.needsContext,
......
...@@ -2,6 +2,7 @@ define([ ...@@ -2,6 +2,7 @@ define([
"./core", "./core",
"./traversing" // parent, contents "./traversing" // parent, contents
], function( jQuery ) { ], function( jQuery ) {
jQuery.fn.extend({ jQuery.fn.extend({
wrapAll: function( html ) { wrapAll: function( html ) {
if ( jQuery.isFunction( html ) ) { if ( jQuery.isFunction( html ) ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment