forked from jquery/jquery
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows jQuery to integrate with the require() provided by RequireJS, …
…if it is available. Exposes jQuery as a module that can be required and makes sure jQuery ready callbacks are not fired if scripts are still being loaded by require(). Includes unit tests.
- Loading branch information
Showing
19 changed files
with
1,782 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require.def("dimple", | ||
{ | ||
color: "dimple-blue" | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require.def("dos", | ||
["tres"], | ||
function(tres) { | ||
return { | ||
name: "dos", | ||
doSomething: function() { | ||
return { | ||
tresName: tres.name | ||
}; | ||
} | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use strict"; | ||
/*global require: false */ | ||
require.def("epsilon", | ||
{ | ||
name: "epsilon" | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require.def("func", | ||
function () { | ||
return function () { | ||
return "You called a function"; | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require.def("funcFour", | ||
["require", "funcThree"], | ||
function (require) { | ||
var four = function (arg) { | ||
return "FOUR called with " + arg; | ||
}; | ||
|
||
four.suffix = function () { | ||
return require("funcThree").suffix(); | ||
}; | ||
|
||
return four; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require.def("funcOne", | ||
["require", "funcTwo"], | ||
function (require) { | ||
var one = function (name) { | ||
this.name = name; | ||
}; | ||
|
||
one.prototype.getName = function () { | ||
var inst = new (require("funcTwo"))("-NESTED"); | ||
return this.name + inst.name; | ||
}; | ||
|
||
return one; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require.def("funcThree", | ||
["funcFour"], | ||
function (four) { | ||
var three = function (arg) { | ||
return arg + "-" + require("funcFour").suffix(); | ||
}; | ||
|
||
three.suffix = function () { | ||
return "THREE_SUFFIX"; | ||
}; | ||
|
||
return three; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require.def("funcTwo", | ||
["funcOne"], | ||
function () { | ||
var two = function (name) { | ||
this.name = name; | ||
this.one = new (require("funcOne"))("ONE"); | ||
}; | ||
|
||
two.prototype.oneName = function () { | ||
return this.one.getName(); | ||
}; | ||
|
||
return two; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//Example layer file. | ||
|
||
"use strict"; | ||
/*global require: false */ | ||
|
||
require.pause(); | ||
|
||
require.def("alpha", | ||
["beta", "gamma"], | ||
function (beta, gamma) { | ||
return { | ||
name: "alpha", | ||
betaName: beta.name | ||
}; | ||
} | ||
); | ||
|
||
require.def("beta", | ||
["gamma"], | ||
function (gamma) { | ||
return { | ||
name: "beta", | ||
gammaName: gamma.name | ||
}; | ||
} | ||
); | ||
|
||
require.def("gamma", | ||
["epsilon"], | ||
function (epsilon) { | ||
return { | ||
name: "gamma", | ||
epsilonName: epsilon.name | ||
}; | ||
} | ||
); | ||
|
||
require.resume(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require.def("one", | ||
["require", "two"], | ||
function(require) { | ||
var one = { | ||
size: "large", | ||
doSomething: function() { | ||
return require("two"); | ||
} | ||
}; | ||
|
||
return one; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require.def("simple", | ||
function() { | ||
return { | ||
color: "blue" | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require.def("tres", | ||
function() { | ||
return { | ||
name: "tres" | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require.def("two", | ||
["one"], | ||
function(one) { | ||
return { | ||
size: "small", | ||
color: "redtwo", | ||
doSomething: function() { | ||
return require("one").doSomething(); | ||
} | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require.def("uno", | ||
["dos", "tres"], | ||
function(dos, tres) { | ||
return { | ||
name: "uno", | ||
doSomething: function() { | ||
return { | ||
dosName: dos.name, | ||
tresName: tres.name | ||
}; | ||
} | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
<title>jQuery+RequireJS Test Suite</title> | ||
<link rel="Stylesheet" media="screen" href="../qunit/qunit/qunit.css" /> | ||
<link rel="Stylesheet" media="screen" href="../data/testsuite.css" /> | ||
|
||
<script src="../data/testinit.js"></script> | ||
|
||
<script src="require.js"></script> | ||
<script src="../../dist/jquery.js"></script> | ||
|
||
<script src="../qunit/qunit/qunit.js"></script> | ||
<script src="data/testrunner.js"></script> | ||
|
||
<script src="tests.js"></script> | ||
</head> | ||
|
||
<body id="body"> | ||
<h1 id="qunit-header">jQuery+RequireJS Test Suite</h1> | ||
<h2 id="qunit-banner"></h2> | ||
<div id="qunit-testrunner-toolbar"></div> | ||
<h2 id="qunit-userAgent"></h2> | ||
<ol id="qunit-tests"></ol> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>requireready test</title> | ||
|
||
<script src='../dist/jquery.js' type='text/javascript'></script> | ||
<script type="text/javascript"> | ||
require({ | ||
baseUrl: "./data/require/" | ||
}, | ||
["require", "simple", "dimple", "func"], | ||
function(require, simple, dimple, func) { | ||
console.log('Color is "blue" ? ' + simple.color); | ||
console.log('Color is "dimple-blue" ? ' + dimple.color); | ||
console.log('Function return is "You called a function" ? ' + func()); | ||
} | ||
); | ||
|
||
jQuery(function() { | ||
console.log('Color is "dimple-blue" after ready ? ' + require("dimple").color); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<h1>requireready test</h1> | ||
<p>Tests interaction between require() and jQuery.ready() to make sure | ||
jQuery.ready() does not fire its callbacks before the modules finish loading.</p> | ||
|
||
<p>There should be 4 console log calls.</p> | ||
</body> | ||
</html> |
Oops, something went wrong.