]> source.dussan.org Git - jquery.git/commitdiff
Break jQuery.access out into its own module to separate it from core; Adjust CommonJS...
authorTimmy Willison <timmywillisn@gmail.com>
Mon, 9 Sep 2013 15:26:21 +0000 (11:26 -0400)
committerTimmy Willison <timmywillisn@gmail.com>
Mon, 9 Sep 2013 16:04:03 +0000 (12:04 -0400)
Conflicts:
src/core.js
src/css.js
src/data.js
src/effects.js
src/event.js
src/manipulation.js
src/traversing.js

14 files changed:
build/tasks/build.js
src/attributes/attr.js
src/attributes/prop.js
src/core.js
src/core/access.js [new file with mode: 0644]
src/css.js
src/data.js
src/dimensions.js
src/effects.js
src/event.js
src/manipulation.js
src/offset.js
src/traversing.js
src/wrap.js

index 93c47c0ff4a20ff5305e5aea207d1521885de42c..1714957fa88f6d25795787d103d56320ba70cf2a 100644 (file)
@@ -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 === ";" ? ";" : "";
                                        });
index 916f64093e3369d458cd1a8ca6729b7d9e1fe78f..47639c97ebe74803426b77a21d4d1e38d0acc2c1 100644 (file)
@@ -2,10 +2,11 @@ define([
        "../core",
        "../var/rnotwhite",
        "../var/strundefined",
+       "../core/access",
        "./support",
        "./val",
        "../selector"
-], function( jQuery, rnotwhite, strundefined, support ) {
+], function( jQuery, rnotwhite, strundefined, access, support ) {
 
 var nodeHook, boolHook,
        attrHandle = jQuery.expr.attrHandle,
@@ -15,7 +16,7 @@ var nodeHook, boolHook,
 
 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 ) {
index 0acd62a2c73e88568b0ca2fe5da922ab069690f2..817a1b6211d43219ff336d678e441ad99f8949b9 100644 (file)
@@ -1,14 +1,15 @@
 define([
        "../core",
+       "../core/access",
        "./support"
-], function( jQuery, support ) {
+], function( jQuery, access, support ) {
 
 var rfocusable = /^(?:input|select|textarea|button|object)$/i,
        rclickable = /^(?:a|area)$/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 ) {
index b1cca19424389bcef83e44b9023fcd1ce562de80..01b3d9a922af8e167f4877a0fe086717620206be 100644 (file)
@@ -606,59 +606,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: function() {
                return ( new Date() ).getTime();
        },
diff --git a/src/core/access.js b/src/core/access.js
new file mode 100644 (file)
index 0000000..7ad2fd3
--- /dev/null
@@ -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;
+});
index 7409b3fd1c03d7f0157ad7d49985324df5780a6f..b62f6711200470b5d3af064d16c47c44379fdb7a 100644 (file)
@@ -1,20 +1,21 @@
-define([
-       "./core",
-       "./var/pnum",
-       "./css/var/cssExpand",
-       "./css/var/isHidden",
-       "./css/defaultDisplay",
-       "./css/support",
-       "./css/swap",
-       "./selector", // contains
-       // Optional
-       "./offset"
-], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, support ) {
-
-var getStyles, curCSS,
+// 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" ),
+
+       getStyles, curCSS,
        ralpha = /alpha\([^)]*\)/i,
        ropacity = /opacity\s*=\s*([^)]*)/,
        rposition = /^(top|right|bottom|left)$/,
+
        // 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]).+)/,
@@ -31,6 +32,14 @@ var getStyles, curCSS,
 
        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
 // because jsdom on node.js will break without it.
 if ( window.getComputedStyle ) {
@@ -598,8 +607,8 @@ jQuery.each({
 
 jQuery.fn.extend({
        css: function( name, value ) {
-               return jQuery.access( this, function( elem, name, value ) {
-                       var len, styles,
+               return access( this, function( elem, name, value ) {
+                       var styles, len,
                                map = {},
                                i = 0;
 
index a2c725a5ad3fcb5aa4c56420123a8f8254dbb4ce..88cdafa8247f25637b11d92167109bf32fe824ea 100644 (file)
@@ -8,7 +8,6 @@ define([
 var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
        rmultiDash = /([A-Z])/g;
 
-
 function dataAttr( elem, key, data ) {
        // If nothing was found internally, try to fetch any
        // data from the HTML5 data-* attribute
index c7a7d18240d3588c44f606cda212e0642e3ccb3e..9dc9414a869d89f1b0790e79373948d60b56aaf0 100644 (file)
@@ -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 ) ) {
index 3817ba5d13f381772cc2f84861817921f6622a7a..4428fc9370d2c07b2b681048329e55f8ff601dbc 100644 (file)
@@ -1,18 +1,14 @@
-define([
-       "./core",
-       "./var/pnum",
-       "./css/var/cssExpand",
-       "./css/var/isHidden",
-       "./css/defaultDisplay",
-       "./effects/support",
-       "./effects/Tween",
-       "./queue",
-       "./css",
-       "./deferred",
-       "./traversing"
-], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, support) {
-
-var fxNow, timerId,
+define(function( require ) {
+
+var
+       jQuery = require( "./core" ),
+       pnum = require( "./var/pnum" ),
+       cssExpand = require( "./css/var/cssExpand" ),
+       isHidden = require( "./css/var/isHidden" ),
+       defaultDisplay = require( "./css/defaultDisplay" ),
+       support = require( "./css/support" ),
+
+       fxNow, timerId,
        rfxtypes = /^(?:toggle|show|hide)$/,
        rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
        rrun = /queueHooks$/,
@@ -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
 function createFxNow() {
        setTimeout(function() {
index ddd5c6f3695ed4f06cfe2579db99c02b6c7f7dc1..7523c1db7ab5b13a91529556b874b070d8a6dd3a 100644 (file)
@@ -1,20 +1,22 @@
-define([
-       "./core",
-       "./var/strundefined",
-       "./var/rnotwhite",
-       "./var/hasOwn",
-       "./var/slice",
-       "./event/support",
-       "./data/accepts",
-       "./selector"
-], function( jQuery, strundefined, rnotwhite, hasOwn, slice, support ) {
-
-var rformElems = /^(?:input|select|textarea)$/i,
+define(function( require ) {
+
+var
+       jQuery = require( "./core" ),
+       strundefined = require( "./var/strundefined" ),
+       rnotwhite = require( "./var/rnotwhite" ),
+       hasOwn = require( "./var/hasOwn" ),
+       slice = require( "./var/slice" ),
+       support = require( "./event/support" ),
+       rformElems = /^(?:input|select|textarea)$/i,
        rkeyEvent = /^key/,
        rmouseEvent = /^(?:mouse|contextmenu)|click/,
        rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
        rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
 
+// Dependencies not needed as vars
+require( "./data/accepts" );
+require( "./selector" );
+
 function returnTrue() {
        return true;
 }
index 55d9c5bbdc79a3e7dbbb9bb63d5b8aa4469c5eea..aefe4bc72f93213770531defd75192ad921abe31 100644 (file)
@@ -1,16 +1,12 @@
-define([
-       "./core",
-       "./var/concat",
-       "./var/push",
-       "./var/deletedIds",
-       "./var/strundefined",
-       "./manipulation/var/rcheckableType",
-       "./manipulation/support",
-       "./data/accepts",
-       "./selector",
-       "./traversing",
-       "./event"
-], function( jQuery, concat, push, deletedIds, strundefined, rcheckableType, support ){
+// Require more than a few needed variables
+// Keep in mind that a dependency array cannot be used with CommonJS+AMD syntax
+define(function( require ){
+
+// Dependencies not needed as variables
+require( "./data/accepts" );
+require( "./traversing" );
+require( "./selector" );
+require( "./event" );
 
 function createSafeFragment( document ) {
        var list = nodeNames.split( "|" ),
@@ -26,11 +22,22 @@ function createSafeFragment( document ) {
        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",
        rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g,
        rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"),
        rleadingWhitespace = /^\s+/,
+
        rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
        rtagName = /<([\w:]+)/,
        rtbody = /<tbody/i,
@@ -66,7 +73,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 ) );
@@ -164,8 +171,8 @@ jQuery.fn.extend({
        },
 
        html: function( value ) {
-               return jQuery.access( this, function( value ) {
-                       var elem = this[0] || {},
+               return access( this, function( value ) {
+                       var elem = this[ 0 ] || {},
                                i = 0,
                                l = this.length;
 
index 18a5dc0385ffcfaef16d6c8b62a7fd0c61d0c4c8..d69a451ca25fa9df5c6ca0723db61c98b7978422 100644 (file)
@@ -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;
 
@@ -160,7 +161,7 @@ jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( me
        var top = /Y/.test( 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 ) {
index 5f4d390e320477a6efa018a884def0874654e7ce..15581fe3ba9b085d54e9c16776c4d6dd3b723450 100644 (file)
@@ -2,6 +2,7 @@ define([
        "./core",
        "./selector"
 ], function( jQuery ) {
+
 var isSimple = /^.[^:#\[\.,]*$/,
        rparentsprev = /^(?:parents|prev(?:Until|All))/,
        rneedsContext = jQuery.expr.match.needsContext,
index 19e3175e293828c7777b80d80e8e66f8d824d9bd..1ec2771ce107187a56d8042a91351b603b2b590b 100644 (file)
@@ -2,6 +2,7 @@ define([
        "./core",
        "./traversing" // parent, contents
 ], function( jQuery ) {
+
 jQuery.fn.extend({
        wrapAll: function( html ) {
                if ( jQuery.isFunction( html ) ) {