Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update docs to use better priority instructions, update project to us…

…e r.js, require.js update to lastest master.
  • Loading branch information...
commit 1886efef867b9fa2980917a0ef2c54ab828cbd6b 1 parent 3dfe2bc
James Burke authored May 14, 2011
153  README.md
Source Rendered
@@ -20,71 +20,64 @@ First, an explanation on what to change in the sample project:
20 20
 
21 21
 ### app.html
22 22
 
23  
-Change the script tag to load just **require.js** ([download it](http://requirejs.org/docs/download.html#requirejs) from the RequireJS site) instead of require-jquery.js.
24  
-
25  
-### main.js
26  
-
27  
-Change main.js to use the [priority configuration option](http://requirejs.org/docs/api.html#config). This tells RequireJS to download jQuery before tracing any other script dependencies:
28  
-
29  
-    //Configure RequireJS
30  
-    require({
31  
-        //Load jQuery before any other scripts, since jQuery plugins normally
32  
-        //assume jQuery is already loaded in the page.
33  
-        priority: ['jquery']
34  
-    });
35  
-
36  
-    //Load scripts.
37  
-    require(['jquery', 'jquery.alpha', 'jquery.beta'], function($) {
38  
-        //the jquery.alpha.js and jquery.beta.js plugins have been loaded.
39  
-        $(function() {
40  
-            $('body').alpha().beta();
41  
-        });
42  
-    });
43  
-
  23
+* Change the script tag to load just **require.js** ([download it](http://requirejs.org/docs/download.html#requirejs) from the RequireJS site) instead of require-jquery.js
  24
+* Remove the data-main attribute
  25
+* Load the main.js file with a require() call in the HTML file.
  26
+* Specify a [priority configuration option](http://requirejs.org/docs/api.html#config). This tells RequireJS to download jQuery before tracing any other script dependencies:
  27
+
  28
+    <!DOCTYPE html>
  29
+    <html>
  30
+        <head>
  31
+            <title>jQuery+RequireJS Sample Page</title>
  32
+            <script src="scripts/require.js"></script>
  33
+            <script>
  34
+            require({
  35
+                baseUrl: 'scripts',
  36
+                priority: ['jquery']
  37
+            }, ['main']);
  38
+            </script>
  39
+        </head>
  40
+        <body>
  41
+            <h1>jQuery+RequireJS Sample Page</h1>
  42
+            <p>Look at source or inspect the DOM to see how it works.</p>
  43
+        </body>
  44
+    </html>
  45
+
  46
+The above example assumes that you downloaded jQuery and placed it in the project
  47
+as **webapp/scripts/jquery.js**. If you wanted to load jQuery from a CDN, like Google's you
  48
+could do this:
  49
+
  50
+    <!DOCTYPE html>
  51
+    <html>
  52
+        <head>
  53
+            <title>jQuery+RequireJS Sample Page</title>
  54
+            <script src="scripts/require.js"></script>
  55
+            <script>
  56
+            require({
  57
+                baseUrl: 'scripts',
  58
+                paths: {
  59
+                    jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min'
  60
+                },
  61
+                priority: ['jquery']
  62
+            }, ['main']);
  63
+            </script>
  64
+        </head>
  65
+        <body>
  66
+            <h1>jQuery+RequireJS Sample Page</h1>
  67
+            <p>Look at source or inspect the DOM to see how it works.</p>
  68
+        </body>
  69
+    </html>
  70
+
  71
+However, you will want to download a local copy of jQuery and place it in the
  72
+project at **webapp/scripts/jquery.js** so it can be used with the optimizer.
44 73
 
45 74
 ### Optimization Considerations
46 75
 
47  
-Since jQuery plugins do not explicitly specify jQuery as a script dependency via the RequireJS define() call, and they expect jQuery to already be in the page, there can be a problem when you try to use the RequireJS optimizer with the setup above.
48  
-
49  
-If you exclude jQuery from the optimized main.js file, then the plugins will be included in main.js, but they will try to use jQuery before the priority configuration has had a chance to load jQuery.
50  
-
51  
-There are two options to fix this:
52  
-
53  
-#### 1) Include jQuery in the optimized file.
54  
-
55  
-* Download the version of jQuery you are using, and put it in the **webapp/scripts** directory, and call it **jquery.js**. Then change the app.build.js file to the following:
56  
-
57  
-    ({
58  
-        appDir: "../",
59  
-        baseUrl: "scripts",
60  
-        dir: "../../webapp-build",
61  
-        //Comment out the optimize line if you want
62  
-        //the code minified by UglifyJS
63  
-        optimize: "none",
64  
-
65  
-        modules: [
66  
-            {
67  
-                name: "main"
68  
-            }
69  
-        ]
70  
-    })
71  
-
72  
-#### 2) wrap the jQuery plugins in a define call.
73  
-
74  
-Instead of including jQuery in the optimized main.js, you can modify the contents of each file that implicitly depends on jQuery with the following (assuming it does not already have a define() call in the file):
75  
-
76  
-    define(['jquery'], function (jQuery) {
77  
-        //Some plugins use jQuery, some may just use $,
78  
-        //so create an alias for $ just in case. You can
79  
-        //leave this out if the plugin clearly uses "jQuery"
80  
-        //instead of "$".
81  
-        var $ = jQuery;
82  
-
83  
-        //The rest of the file contents go here.
  76
+With jQuery loaded externally, before main.js is loaded, jQuery now needs to be
  77
+excluded from the built file the optimizer generates.
84 78
 
85  
-    });
86  
-
87  
-For the optimizer: create an empty file called **blank.js** and put it in the webapp/scripts directory. Then change app.build.js to the following:
  79
+Make sure you have a jquery.js in the **webapp/scripts** directory. Then change
  80
+the app.build.js file to the following:
88 81
 
89 82
     ({
90 83
         appDir: "../",
@@ -94,44 +87,12 @@ For the optimizer: create an empty file called **blank.js** and put it in the we
94 87
         //the code minified by UglifyJS
95 88
         optimize: "none",
96 89
 
97  
-        paths: {
98  
-            "jquery": "blank"
99  
-        },
100  
-
101 90
         modules: [
102 91
             {
103  
-                //If you have multiple pages in your app, you may
104  
-                //want jQuery cached separately from the optimized
105  
-                //main module. In that case, uncomment the exclude
106  
-                //directive below.
107  
-                exclude: ["jquery"],
108  
-                name: "main"
  92
+                name: "main",
  93
+                exclude: ["jquery"]
109 94
             }
110 95
         ]
111 96
     })
112 97
 
113  
-By wrapping each of the jQuery plugins that implicitly rely on jQuery in a define() call, you can be sure they will not execute until jQuery is loaded via the priority configuration.
114  
-
115  
-**NOTE**: If a plugin tries to define a global variable (does not attach the functionality to jQuery.fn), wrapping the code in a define() call may cause errors if the plugin expects you to call one of the global variables it creates.
116  
-
117  
-You can work around this problem by declaring the variable outside the define call. So, for example, if the plugin looks like this when it is wrapped:
118  
-
119  
-    define(['jquery'], function (jQuery) {
120  
-        var $ = jQuery;
121  
-
122  
-        //The plugin wanted to make globalFoo a global,
123  
-        //but this will not work with the define wrapping:
124  
-        var globalFoo = "something";
125  
-        ...
126  
-    });
127  
-
128  
-Put the var declaration outside the define function and remove the "var" from the internal assignment:
129  
-
130  
-    var globalFoo;
131  
-    define(['jquery'], function (jQuery) {
132  
-        var $ = jQuery;
133  
-
134  
-        //Just assign now, remove the declaration.
135  
-        globalFoo = "something";
136  
-        ...
137  
-    });
  98
+This will bundle all the scripts into the built main.js file, except for jQuery.
28  dist.sh
... ...
@@ -1,9 +1,5 @@
1 1
 #!/bin/sh
2 2
 
3  
-# Assumes RequireJS is in a sibling directory to this repo. Change this
4  
-# if it is in another directory.
5  
-REQUIREJS=../requirejs
6  
-
7 3
 DISTDIR=dist/jquery-require-sample
8 4
 
9 5
 # This script preps the jquery-require-sample for distribution.
@@ -11,33 +7,13 @@ DISTDIR=dist/jquery-require-sample
11 7
 # Make the dist directory
12 8
 rm -rf dist
13 9
 mkdir dist
14  
-mkdir dist/jquery-require-sample
15 10
 
16 11
 # Copy the sample files.
17  
-cp -r jquery-require-sample/webapp $DISTDIR/webapp
18  
-
19  
-# Copy over the build system for requirejs and basic require files, used by the build.
20  
-mkdir $DISTDIR/requirejs
21  
-mkdir $DISTDIR/requirejs/adapt
22  
-mkdir $DISTDIR/requirejs/build
23  
-cp -r $REQUIREJS/bin $DISTDIR/requirejs/bin
24  
-cp -r $REQUIREJS/build/jslib $DISTDIR/requirejs/build/jslib
25  
-cp -r $REQUIREJS/build/lib $DISTDIR/requirejs/build/lib
26  
-cp $REQUIREJS/build/example.build.js $DISTDIR/requirejs/build/example.build.js
27  
-cp $REQUIREJS/build/build.bat $DISTDIR/requirejs/build/build.bat
28  
-cp $REQUIREJS/build/build.js $DISTDIR/requirejs/build/build.js
29  
-cp $REQUIREJS/build/build.sh $DISTDIR/requirejs/build/build.sh
30  
-cp $REQUIREJS/build/buildj.bat $DISTDIR/requirejs/build/buildj.bat
31  
-cp $REQUIREJS/build/buildj.sh $DISTDIR/requirejs/build/buildj.sh
32  
-cp $REQUIREJS/adapt/node.js $DISTDIR/requirejs/adapt/node.js
33  
-cp $REQUIREJS/adapt/rhino.js $DISTDIR/requirejs/adapt/rhino.js
34  
-
35  
-cp $REQUIREJS/require.js $DISTDIR/requirejs
36  
-cp $REQUIREJS/LICENSE $DISTDIR/requirejs/LICENSE
  12
+cp -r jquery-require-sample $DISTDIR
37 13
 
38 14
 # Start the build.
39 15
 cd $DISTDIR/webapp/scripts
40  
-../../requirejs/build/build.sh app.build.js
  16
+node ../../r.js -o app.build.js
41 17
 cd ../../..
42 18
 
43 19
 # Mac weirdness
7,710  jquery-require-sample/r.js
7710 additions, 0 deletions not shown
114  jquery-require-sample/webapp/scripts/require-jquery.js
... ...
@@ -1,5 +1,5 @@
1 1
 /** vim: et:ts=4:sw=4:sts=4
2  
- * @license RequireJS 0.24.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
  2
+ * @license RequireJS 0.24.0+ Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
3 3
  * Available via the MIT or new BSD license.
4 4
  * see: http://github.com/jrburke/requirejs for details
5 5
  */
@@ -11,7 +11,7 @@
11 11
 var require, define;
12 12
 (function () {
13 13
     //Change this version number for each release.
14  
-    var version = "0.24.0",
  14
+    var version = "0.24.0+",
15 15
         commentRegExp = /(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg,
16 16
         cjsRequireRegExp = /require\(["']([^'"\s]+)["']\)/g,
17 17
         currDirRegExp = /^\.\//,
@@ -39,7 +39,8 @@ var require, define;
39 39
         isDone = false,
40 40
         useInteractive = false,
41 41
         req, cfg = {}, currentlyAddingScript, s, head, baseElement, scripts, script,
42  
-        src, subPath, mainScript, dataMain, i, scrollIntervalId, setReadyState, ctx;
  42
+        src, subPath, mainScript, dataMain, i, scrollIntervalId, setReadyState, ctx,
  43
+        jQueryCheck;
43 44
 
44 45
     function isFunction(it) {
45 46
         return ostring.call(it) === "[object Function]";
@@ -497,23 +498,28 @@ var require, define;
497 498
                     }
498 499
                 }
499 500
 
500  
-                ret = req.execCb(fullName, manager.callback, args);
  501
+                ret = req.execCb(fullName, manager.callback, args, defined[fullName]);
501 502
 
502 503
                 if (fullName) {
503  
-                    //If using exports and the function did not return a value,
504  
-                    //and the "module" object for this definition function did not
505  
-                    //define an exported value, then use the exports object.
506  
-                    if (manager.usingExports && ret === undefined && (!manager.cjsModule || !("exports" in manager.cjsModule))) {
  504
+                    //If exports is in play, favor that since it helps circular
  505
+                    //dependencies. If setting exports via "module" is in play,
  506
+                    //favor that but only if the value is different from default
  507
+                    //exports value.
  508
+                    if (manager.usingExports && manager.cjsModule &&
  509
+                        manager.cjsModule.exports !== defined[fullName]) {
  510
+                        ret = defined[fullName] = manager.cjsModule.exports;
  511
+                    } else if (fullName in defined) {
  512
+                        //This case is when usingExports is in play and
  513
+                        //module.exports/setExports was not used. It could also
  514
+                        //occur if the module was previously defined, but that
  515
+                        //should not happen, checks for specified and defined
  516
+                        //elsewhere should prevent that from happening. However,
  517
+                        //if it does for some reason, only the original definition
  518
+                        //will be used for integrity.
507 519
                         ret = defined[fullName];
508 520
                     } else {
509  
-                        if (manager.cjsModule && "exports" in manager.cjsModule) {
510  
-                            ret = defined[fullName] = manager.cjsModule.exports;
511  
-                        } else {
512  
-                            if (fullName in defined && !manager.usingExports) {
513  
-                                return req.onError(new Error(fullName + " has already been defined"));
514  
-                            }
515  
-                            defined[fullName] = ret;
516  
-                        }
  521
+                        //Use the return value from the function.
  522
+                        defined[fullName] = ret;
517 523
                     }
518 524
                 }
519 525
             } else if (fullName) {
@@ -580,8 +586,11 @@ var require, define;
580 586
 
581 587
             if (fullName) {
582 588
                 //If module already defined for context, or already loaded,
583  
-                //then leave.
584  
-                if (fullName in defined || loaded[fullName] === true) {
  589
+                //then leave. Also leave if jQuery is registering but it does
  590
+                //not match the desired version number in the config.
  591
+                if (fullName in defined || loaded[fullName] === true ||
  592
+                    (fullName === "jquery" && config.jQuery &&
  593
+                     config.jQuery !== callback().fn.jquery)) {
585 594
                     return;
586 595
                 }
587 596
 
@@ -589,10 +598,13 @@ var require, define;
589 598
                 //as part of a layer, where onScriptLoad is not fired
590 599
                 //for those cases. Do this after the inline define and
591 600
                 //dependency tracing is done.
592  
-                //Also check if auto-registry of jQuery needs to be skipped.
593 601
                 specified[fullName] = true;
594 602
                 loaded[fullName] = true;
595  
-                context.jQueryDef = (fullName === "jquery");
  603
+
  604
+                //If module is jQuery set up delaying its dom ready listeners.
  605
+                if (fullName === "jquery" && callback) {
  606
+                    jQueryCheck(callback());
  607
+                }
596 608
             }
597 609
 
598 610
             //Add the dependencies to the deps field, and register for callbacks
@@ -622,7 +634,8 @@ var require, define;
622 634
                         //CommonJS module spec 1.1
623 635
                         manager.cjsModule = cjsMod = manager.deps[depName] = {
624 636
                             id: name,
625  
-                            uri: name ? context.nameToUrl(name, null, relModuleMap) : undefined
  637
+                            uri: name ? context.nameToUrl(name, null, relModuleMap) : undefined,
  638
+                            exports: defined[fullName]
626 639
                         };
627 640
                         cjsMod.setExports = makeSetExports(cjsMod);
628 641
                     } else if (depName in defined && !(depName in waiting)) {
@@ -676,26 +689,37 @@ var require, define;
676 689
          * name of the global. If a jQuery is tracked for this context, then go
677 690
          * ahead and register it as a module too, if not already in process.
678 691
          */
679  
-        function jQueryCheck(jqCandidate) {
  692
+        jQueryCheck = function (jqCandidate) {
680 693
             if (!context.jQuery) {
681 694
                 var $ = jqCandidate || (typeof jQuery !== "undefined" ? jQuery : null);
682  
-                if ($ && "readyWait" in $) {
683  
-                    context.jQuery = $;
684  
-
685  
-                    //Manually create a "jquery" module entry if not one already
686  
-                    //or in process.
687  
-                    callDefMain(["jquery", [], function () {
688  
-                        return jQuery;
689  
-                    }]);
690  
-
691  
-                    //Increment jQuery readyWait if ncecessary.
692  
-                    if (context.scriptCount) {
693  
-                        $.readyWait += 1;
694  
-                        context.jQueryIncremented = true;
  695
+
  696
+                if ($) {
  697
+                    //If a specific version of jQuery is wanted, make sure to only
  698
+                    //use this jQuery if it matches.
  699
+                    if (config.jQuery && $.fn.jquery !== config.jQuery) {
  700
+                        return;
  701
+                    }
  702
+
  703
+                    if ("readyWait" in $) {
  704
+                        context.jQuery = $;
  705
+
  706
+                        //Manually create a "jquery" module entry if not one already
  707
+                        //or in process. Note this could trigger an attempt at
  708
+                        //a second jQuery registration, but does no harm since
  709
+                        //the first one wins, and it is the same value anyway.
  710
+                        callDefMain(["jquery", [], function () {
  711
+                            return jQuery;
  712
+                        }]);
  713
+
  714
+                        //Increment jQuery readyWait if ncecessary.
  715
+                        if (context.scriptCount) {
  716
+                            $.readyWait += 1;
  717
+                            context.jQueryIncremented = true;
  718
+                        }
695 719
                     }
696 720
                 }
697 721
             }
698  
-        }
  722
+        };
699 723
 
700 724
         function forceExec(manager, traced) {
701 725
             if (manager.isDone) {
@@ -1153,6 +1177,10 @@ var require, define;
1153 1177
                 //then resume the dependency processing.
1154 1178
                 if (!context.requireWait) {
1155 1179
                     while (!context.scriptCount && context.paused.length) {
  1180
+                        //For built layers, there can be some defined
  1181
+                        //modules waiting for intake into the context,
  1182
+                        //in particular module plugins. Take them.
  1183
+                        context.takeGlobalQueue();
1156 1184
                         resume();
1157 1185
                     }
1158 1186
                 }
@@ -1508,12 +1536,11 @@ var require, define;
1508 1536
                     });
1509 1537
 
1510 1538
                 //May be a CommonJS thing even without require calls, but still
1511  
-                //could use exports, and such, so always add those as dependencies.
1512  
-                //This is a bit wasteful for RequireJS modules that do not need
1513  
-                //an exports or module object, but erring on side of safety.
  1539
+                //could use exports, and module. Avoid doing exports and module
  1540
+                //work though if it just needs require.
1514 1541
                 //REQUIRES the function to expect the CommonJS variables in the
1515 1542
                 //order listed below.
1516  
-                deps = ["require", "exports", "module"].concat(deps);
  1543
+                deps = (callback.length === 1 ? ["require"] : ["require", "exports", "module"]).concat(deps);
1517 1544
             }
1518 1545
         }
1519 1546
 
@@ -1543,7 +1570,8 @@ var require, define;
1543 1570
 
1544 1571
     define.amd = {
1545 1572
         multiversion: true,
1546  
-        plugins: true
  1573
+        plugins: true,
  1574
+        jQuery: true
1547 1575
     };
1548 1576
 
1549 1577
     /**
@@ -1553,8 +1581,8 @@ var require, define;
1553 1581
      *
1554 1582
      * @private
1555 1583
      */
1556  
-    req.execCb = function (name, callback, args) {
1557  
-        return callback.apply(null, args);
  1584
+    req.execCb = function (name, callback, args, exports) {
  1585
+        return callback.apply(exports, args);
1558 1586
     };
1559 1587
 
1560 1588
     /**
1  parts/README.md
Source Rendered
@@ -5,3 +5,4 @@
5 5
 * Copy the appropriate version of jQuery and save it in this directory as
6 6
 "jquery.js".
7 7
 * Run update.sh.
  8
+
114  parts/require.js
... ...
@@ -1,5 +1,5 @@
1 1
 /** vim: et:ts=4:sw=4:sts=4
2  
- * @license RequireJS 0.24.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
  2
+ * @license RequireJS 0.24.0+ Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
3 3
  * Available via the MIT or new BSD license.
4 4
  * see: http://github.com/jrburke/requirejs for details
5 5
  */
@@ -11,7 +11,7 @@
11 11
 var require, define;
12 12
 (function () {
13 13
     //Change this version number for each release.
14  
-    var version = "0.24.0",
  14
+    var version = "0.24.0+",
15 15
         commentRegExp = /(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg,
16 16
         cjsRequireRegExp = /require\(["']([^'"\s]+)["']\)/g,
17 17
         currDirRegExp = /^\.\//,
@@ -39,7 +39,8 @@ var require, define;
39 39
         isDone = false,
40 40
         useInteractive = false,
41 41
         req, cfg = {}, currentlyAddingScript, s, head, baseElement, scripts, script,
42  
-        src, subPath, mainScript, dataMain, i, scrollIntervalId, setReadyState, ctx;
  42
+        src, subPath, mainScript, dataMain, i, scrollIntervalId, setReadyState, ctx,
  43
+        jQueryCheck;
43 44
 
44 45
     function isFunction(it) {
45 46
         return ostring.call(it) === "[object Function]";
@@ -497,23 +498,28 @@ var require, define;
497 498
                     }
498 499
                 }
499 500
 
500  
-                ret = req.execCb(fullName, manager.callback, args);
  501
+                ret = req.execCb(fullName, manager.callback, args, defined[fullName]);
501 502
 
502 503
                 if (fullName) {
503  
-                    //If using exports and the function did not return a value,
504  
-                    //and the "module" object for this definition function did not
505  
-                    //define an exported value, then use the exports object.
506  
-                    if (manager.usingExports && ret === undefined && (!manager.cjsModule || !("exports" in manager.cjsModule))) {
  504
+                    //If exports is in play, favor that since it helps circular
  505
+                    //dependencies. If setting exports via "module" is in play,
  506
+                    //favor that but only if the value is different from default
  507
+                    //exports value.
  508
+                    if (manager.usingExports && manager.cjsModule &&
  509
+                        manager.cjsModule.exports !== defined[fullName]) {
  510
+                        ret = defined[fullName] = manager.cjsModule.exports;
  511
+                    } else if (fullName in defined) {
  512
+                        //This case is when usingExports is in play and
  513
+                        //module.exports/setExports was not used. It could also
  514
+                        //occur if the module was previously defined, but that
  515
+                        //should not happen, checks for specified and defined
  516
+                        //elsewhere should prevent that from happening. However,
  517
+                        //if it does for some reason, only the original definition
  518
+                        //will be used for integrity.
507 519
                         ret = defined[fullName];
508 520
                     } else {
509  
-                        if (manager.cjsModule && "exports" in manager.cjsModule) {
510  
-                            ret = defined[fullName] = manager.cjsModule.exports;
511  
-                        } else {
512  
-                            if (fullName in defined && !manager.usingExports) {
513  
-                                return req.onError(new Error(fullName + " has already been defined"));
514  
-                            }
515  
-                            defined[fullName] = ret;
516  
-                        }
  521
+                        //Use the return value from the function.
  522
+                        defined[fullName] = ret;
517 523
                     }
518 524
                 }
519 525
             } else if (fullName) {
@@ -580,8 +586,11 @@ var require, define;
580 586
 
581 587
             if (fullName) {
582 588
                 //If module already defined for context, or already loaded,
583  
-                //then leave.
584  
-                if (fullName in defined || loaded[fullName] === true) {
  589
+                //then leave. Also leave if jQuery is registering but it does
  590
+                //not match the desired version number in the config.
  591
+                if (fullName in defined || loaded[fullName] === true ||
  592
+                    (fullName === "jquery" && config.jQuery &&
  593
+                     config.jQuery !== callback().fn.jquery)) {
585 594
                     return;
586 595
                 }
587 596
 
@@ -589,10 +598,13 @@ var require, define;
589 598
                 //as part of a layer, where onScriptLoad is not fired
590 599
                 //for those cases. Do this after the inline define and
591 600
                 //dependency tracing is done.
592  
-                //Also check if auto-registry of jQuery needs to be skipped.
593 601
                 specified[fullName] = true;
594 602
                 loaded[fullName] = true;
595  
-                context.jQueryDef = (fullName === "jquery");
  603
+
  604
+                //If module is jQuery set up delaying its dom ready listeners.
  605
+                if (fullName === "jquery" && callback) {
  606
+                    jQueryCheck(callback());
  607
+                }
596 608
             }
597 609
 
598 610
             //Add the dependencies to the deps field, and register for callbacks
@@ -622,7 +634,8 @@ var require, define;
622 634
                         //CommonJS module spec 1.1
623 635
                         manager.cjsModule = cjsMod = manager.deps[depName] = {
624 636
                             id: name,
625  
-                            uri: name ? context.nameToUrl(name, null, relModuleMap) : undefined
  637
+                            uri: name ? context.nameToUrl(name, null, relModuleMap) : undefined,
  638
+                            exports: defined[fullName]
626 639
                         };
627 640
                         cjsMod.setExports = makeSetExports(cjsMod);
628 641
                     } else if (depName in defined && !(depName in waiting)) {
@@ -676,26 +689,37 @@ var require, define;
676 689
          * name of the global. If a jQuery is tracked for this context, then go
677 690
          * ahead and register it as a module too, if not already in process.
678 691
          */
679  
-        function jQueryCheck(jqCandidate) {
  692
+        jQueryCheck = function (jqCandidate) {
680 693
             if (!context.jQuery) {
681 694
                 var $ = jqCandidate || (typeof jQuery !== "undefined" ? jQuery : null);
682  
-                if ($ && "readyWait" in $) {
683  
-                    context.jQuery = $;
684  
-
685  
-                    //Manually create a "jquery" module entry if not one already
686  
-                    //or in process.
687  
-                    callDefMain(["jquery", [], function () {
688  
-                        return jQuery;
689  
-                    }]);
690  
-
691  
-                    //Increment jQuery readyWait if ncecessary.
692  
-                    if (context.scriptCount) {
693  
-                        $.readyWait += 1;
694  
-                        context.jQueryIncremented = true;
  695
+
  696
+                if ($) {
  697
+                    //If a specific version of jQuery is wanted, make sure to only
  698
+                    //use this jQuery if it matches.
  699
+                    if (config.jQuery && $.fn.jquery !== config.jQuery) {
  700
+                        return;
  701
+                    }
  702
+
  703
+                    if ("readyWait" in $) {
  704
+                        context.jQuery = $;
  705
+
  706
+                        //Manually create a "jquery" module entry if not one already
  707
+                        //or in process. Note this could trigger an attempt at
  708
+                        //a second jQuery registration, but does no harm since
  709
+                        //the first one wins, and it is the same value anyway.
  710
+                        callDefMain(["jquery", [], function () {
  711
+                            return jQuery;
  712
+                        }]);
  713
+
  714
+                        //Increment jQuery readyWait if ncecessary.
  715
+                        if (context.scriptCount) {
  716
+                            $.readyWait += 1;
  717
+                            context.jQueryIncremented = true;
  718
+                        }
695 719
                     }
696 720
                 }
697 721
             }
698  
-        }
  722
+        };
699 723
 
700 724
         function forceExec(manager, traced) {
701 725
             if (manager.isDone) {
@@ -1153,6 +1177,10 @@ var require, define;
1153 1177
                 //then resume the dependency processing.
1154 1178
                 if (!context.requireWait) {
1155 1179
                     while (!context.scriptCount && context.paused.length) {
  1180
+                        //For built layers, there can be some defined
  1181
+                        //modules waiting for intake into the context,
  1182
+                        //in particular module plugins. Take them.
  1183
+                        context.takeGlobalQueue();
1156 1184
                         resume();
1157 1185
                     }
1158 1186
                 }
@@ -1508,12 +1536,11 @@ var require, define;
1508 1536
                     });
1509 1537
 
1510 1538
                 //May be a CommonJS thing even without require calls, but still
1511  
-                //could use exports, and such, so always add those as dependencies.
1512  
-                //This is a bit wasteful for RequireJS modules that do not need
1513  
-                //an exports or module object, but erring on side of safety.
  1539
+                //could use exports, and module. Avoid doing exports and module
  1540
+                //work though if it just needs require.
1514 1541
                 //REQUIRES the function to expect the CommonJS variables in the
1515 1542
                 //order listed below.
1516  
-                deps = ["require", "exports", "module"].concat(deps);
  1543
+                deps = (callback.length === 1 ? ["require"] : ["require", "exports", "module"]).concat(deps);
1517 1544
             }
1518 1545
         }
1519 1546
 
@@ -1543,7 +1570,8 @@ var require, define;
1543 1570
 
1544 1571
     define.amd = {
1545 1572
         multiversion: true,
1546  
-        plugins: true
  1573
+        plugins: true,
  1574
+        jQuery: true
1547 1575
     };
1548 1576
 
1549 1577
     /**
@@ -1553,8 +1581,8 @@ var require, define;
1553 1581
      *
1554 1582
      * @private
1555 1583
      */
1556  
-    req.execCb = function (name, callback, args) {
1557  
-        return callback.apply(null, args);
  1584
+    req.execCb = function (name, callback, args, exports) {
  1585
+        return callback.apply(exports, args);
1558 1586
     };
1559 1587
 
1560 1588
     /**

0 notes on commit 1886efe

Please sign in to comment.
Something went wrong with that request. Please try again.