├── tests ├── anon │ ├── message.txt │ ├── green.js │ ├── yellow.js │ ├── blue.js │ ├── red.js │ ├── sub │ │ └── b.js │ ├── c.js │ ├── a.js │ ├── magenta.js │ ├── anonSimple.html │ └── anon-tests.js ├── layers │ ├── helloWorld.txt │ ├── epsilon.js │ ├── layer1.js │ ├── allplugins-text.html │ └── layers.html ├── relative │ ├── foo │ │ ├── bar │ │ │ ├── message.txt │ │ │ ├── two.js │ │ │ └── one.js │ │ └── three.js │ ├── relative.html │ └── relative-tests.js ├── text │ ├── resources │ │ ├── local.html │ │ └── sample.html │ ├── subwidget2.html │ ├── widget.html │ ├── local.js │ ├── subwidget.js │ ├── subwidget.html │ ├── widget.js │ ├── textOnly.html │ └── text.html ├── browsertests │ ├── onerror │ │ ├── ok.js │ │ ├── parseError.js │ │ ├── scriptError.js │ │ └── index.html │ ├── scriptload │ │ ├── one.js │ │ ├── six.js │ │ ├── eight.js │ │ ├── five.js │ │ ├── nine.js │ │ ├── seven.js │ │ ├── three.js │ │ ├── two.js │ │ └── index.html │ ├── appendbeforeload │ │ ├── two.js │ │ ├── one.dphpd │ │ └── test.html │ ├── async │ │ ├── two.js │ │ ├── one.php │ │ └── async.php │ ├── docwritenested │ │ ├── two.js │ │ ├── one.js │ │ └── index.html │ ├── scriptloadinteractive │ │ ├── eight.js │ │ ├── five.js │ │ ├── nine.js │ │ ├── one.js │ │ ├── seven.js │ │ ├── six.js │ │ ├── three.js │ │ └── two.js │ ├── common.js │ └── functionToString.html ├── plugins │ ├── a.js │ ├── c.js │ ├── prime │ │ ├── a.js │ │ ├── c.js │ │ ├── b.js │ │ └── earth.js │ ├── b.js │ ├── earth.js │ ├── sync.html │ ├── sync-tests.js │ ├── index.js │ └── indexBuilder.js ├── order │ ├── one.js │ ├── three.js │ ├── bar.js │ ├── foo.js │ └── order.html ├── urlfetch │ ├── one.js │ ├── two.js │ ├── three.js │ └── urlfetch.html ├── version1 │ ├── gamma.js │ ├── beta.js │ ├── omega.js │ └── alpha.js ├── version2 │ ├── epsilon.js │ ├── alpha.js │ ├── beta.js │ └── omega.js ├── jsonp │ ├── lamp.js │ ├── twitter.html │ └── jsonp.html ├── packages │ ├── funky │ │ ├── lib │ │ │ └── monkey.js │ │ └── index.js │ ├── dojox │ │ ├── door.js │ │ └── window │ │ │ ├── pane.js │ │ │ └── window.js │ ├── foo │ │ └── lib │ │ │ ├── second.js │ │ │ └── main.js │ ├── pkgs │ │ ├── alpha │ │ │ └── lib │ │ │ │ ├── main.js │ │ │ │ └── replace.js │ │ ├── beta │ │ │ └── 0.2 │ │ │ │ └── scripts │ │ │ │ ├── util.js │ │ │ │ └── beta.js │ │ └── dojox │ │ │ ├── table │ │ │ ├── legs.js │ │ │ └── table.js │ │ │ └── chair │ │ │ └── lib │ │ │ ├── legs.js │ │ │ └── main.js │ ├── baz │ │ └── lib │ │ │ ├── helper.js │ │ │ └── index.js │ ├── bar │ │ └── 0.4 │ │ │ └── scripts │ │ │ └── main.js │ ├── replace.js │ ├── packages.html │ └── packages-tests.js ├── i18n │ ├── nls │ │ ├── en-us-surfer │ │ │ └── colors.js │ │ ├── fr │ │ │ └── colors.js │ │ └── colors.js │ ├── commonA.js │ ├── commonB.js │ ├── testModule.js │ ├── common.html │ └── i18n.html ├── uniques │ ├── three.js │ ├── one.js │ ├── two.js │ └── uniques.html ├── jquery │ ├── scripts │ │ ├── app.js │ │ ├── jquery.alpha.js │ │ ├── jquery.beta.js │ │ ├── dynamicApp.js │ │ ├── jquery.gamma.js │ │ ├── jquery.epsilon.js │ │ └── jquery-MIT-LICENSE.txt │ ├── jquery.html │ ├── jqueryDynamic.html │ └── jqueryDynamic2.html ├── afterloadreadystate.js ├── dimple.js ├── doh │ ├── runner.sh │ ├── small_logo.png │ ├── _sounds │ │ ├── doh.wav │ │ ├── dohaaa.wav │ │ ├── woohoo.wav │ │ └── LICENSE │ ├── _rhinoRunner.js │ ├── README │ └── _nodeRunner.js ├── priority │ ├── epsilon.js │ ├── flower.js │ ├── leaf.js │ ├── priorityWithDeps │ │ ├── script │ │ │ └── req │ │ │ │ ├── begin.js │ │ │ │ ├── config.js │ │ │ │ ├── utils │ │ │ │ └── utils.js │ │ │ │ ├── app.js │ │ │ │ └── bootstrap.js │ │ └── priorityWithDeps.html │ ├── tree.js │ ├── two.js │ ├── one.js │ ├── priority.html │ ├── three.js │ ├── priority.js │ ├── priorityOrder.html │ └── prioritySingleCall.html ├── foo ├── bar ├── map.js ├── tres.js ├── simple.js ├── commonjs │ └── tests │ │ └── modules │ │ └── 1.0 │ │ ├── hasOwnProperty │ │ ├── determinism │ │ ├── submodule │ │ │ ├── b.js │ │ │ └── a.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── absolute │ │ ├── b.js │ │ ├── submodule │ │ │ └── a.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── monkeys │ │ ├── a.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── transitive │ │ ├── a.js │ │ ├── b.js │ │ ├── c.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── relative │ │ ├── submodule │ │ │ ├── b.js │ │ │ └── a.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── nested │ │ ├── a │ │ │ └── b │ │ │ │ └── c │ │ │ │ └── d.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── cyclic │ │ ├── a.js │ │ ├── b.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── system.js │ │ ├── exactExports │ │ ├── a.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── method │ │ ├── a.js │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── missing │ │ ├── program.js │ │ ├── program.html │ │ └── test.js │ │ ├── test.js │ │ └── all.html ├── exports │ ├── assign2.js │ ├── assign.js │ ├── vanilla.js │ ├── funcSet.js │ ├── exports.html │ └── exports-tests.js ├── func.js ├── paths │ ├── first.js │ │ ├── first.js │ │ └── second.js │ └── paths.html ├── dos.js ├── one.js ├── two.js ├── index.html ├── uno.js ├── funcFour.js ├── funcThree.js ├── workers.js ├── dataMain.js ├── funcTwo.js ├── funcOne.js ├── dataMain.html ├── baseUrl.html ├── circular.html ├── depoverlap.html ├── simple-tests.js ├── circular-tests.js ├── simple-nohead.html ├── depoverlap.js ├── simple.html ├── config.html ├── README.md ├── workers.html ├── all-server.js ├── simple-badbase.html ├── multiversion.html └── all.js ├── bin ├── x.bat ├── xdebug.bat ├── x ├── xj.bat ├── xjdebug.bat ├── xdebug ├── xjdebug └── xj ├── adapt ├── tests │ ├── node │ │ ├── tests │ │ │ ├── foo.js │ │ │ ├── alpha │ │ │ │ ├── foo.js │ │ │ │ └── hello.html │ │ │ └── server.js │ │ ├── index.js │ │ └── canvasTest.js │ ├── sub │ │ └── betaSub.js │ ├── alpha.js │ ├── beta.js │ └── all.js ├── dist.js ├── rhino.js └── node.js ├── dist ├── fonts │ ├── Inconsolata.ttf │ └── PT-Sans │ │ ├── PT_Sans.ttf │ │ ├── PT_Sans_Bold.ttf │ │ ├── PT_Sans_Caption.ttf │ │ ├── PT_Sans_Italic.ttf │ │ ├── PT_Sans_Narrow.ttf │ │ ├── PT_Sans_Bold_Italic.ttf │ │ ├── PT_Sans_Caption_Bold.ttf │ │ ├── PT_Sans_Narrow_Bold.ttf │ │ └── Paratype PT Sans Free Font License.txt ├── ie.css ├── post.html ├── init.js ├── README.md ├── Markdown-License.text └── dist-build.sh ├── docs ├── design │ └── packages.md ├── jquery-require-sample │ ├── webapp │ │ ├── scripts │ │ │ ├── jquery.alpha.js │ │ │ ├── jquery.beta.js │ │ │ ├── main.js │ │ │ ├── app.build.js │ │ │ └── jquery-MIT-LICENSE.txt │ │ └── app.html │ └── dist.sh ├── faq.html ├── dojo.html ├── history.html ├── contributing.html └── node.html ├── package.json ├── testBaseUrl.js ├── .gitignore ├── index.html ├── README.md └── LICENSE /tests/anon/message.txt: -------------------------------------------------------------------------------- 1 | hello world -------------------------------------------------------------------------------- /tests/layers/helloWorld.txt: -------------------------------------------------------------------------------- 1 | hello world -------------------------------------------------------------------------------- /tests/relative/foo/bar/message.txt: -------------------------------------------------------------------------------- 1 | hello world -------------------------------------------------------------------------------- /tests/text/resources/local.html: -------------------------------------------------------------------------------- 1 |

Local

-------------------------------------------------------------------------------- /tests/browsertests/onerror/ok.js: -------------------------------------------------------------------------------- 1 | log("ok has executed"); -------------------------------------------------------------------------------- /tests/plugins/a.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'a' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/plugins/c.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: "c" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/text/subwidget2.html: -------------------------------------------------------------------------------- 1 | This! is template2 -------------------------------------------------------------------------------- /bin/x.bat: -------------------------------------------------------------------------------- 1 | set MYDIR=%~dp0 2 | node %MYDIR%x.js %MYDIR% %* 3 | -------------------------------------------------------------------------------- /tests/browsertests/scriptload/one.js: -------------------------------------------------------------------------------- 1 | log("one.js script"); 2 | -------------------------------------------------------------------------------- /tests/browsertests/scriptload/six.js: -------------------------------------------------------------------------------- 1 | log("six.js script"); 2 | -------------------------------------------------------------------------------- /tests/order/one.js: -------------------------------------------------------------------------------- 1 | var one = { 2 | name: "one" 3 | }; 4 | -------------------------------------------------------------------------------- /tests/anon/green.js: -------------------------------------------------------------------------------- 1 | require.def({ 2 | name: "green" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/browsertests/appendbeforeload/two.js: -------------------------------------------------------------------------------- 1 | console.log("TWO"); 2 | -------------------------------------------------------------------------------- /tests/browsertests/async/two.js: -------------------------------------------------------------------------------- 1 | window.log("two.js script"); 2 | -------------------------------------------------------------------------------- /tests/browsertests/scriptload/eight.js: -------------------------------------------------------------------------------- 1 | log("eight.js script"); 2 | -------------------------------------------------------------------------------- /tests/browsertests/scriptload/five.js: -------------------------------------------------------------------------------- 1 | log("five.js script"); 2 | -------------------------------------------------------------------------------- /tests/browsertests/scriptload/nine.js: -------------------------------------------------------------------------------- 1 | log("nine.js script"); 2 | -------------------------------------------------------------------------------- /tests/browsertests/scriptload/seven.js: -------------------------------------------------------------------------------- 1 | log("seven.js script"); 2 | -------------------------------------------------------------------------------- /tests/browsertests/scriptload/three.js: -------------------------------------------------------------------------------- 1 | log("three.js script"); 2 | -------------------------------------------------------------------------------- /tests/plugins/prime/a.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'aPrime' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/plugins/prime/c.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: "cPrime" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/urlfetch/one.js: -------------------------------------------------------------------------------- 1 | var one = { 2 | name: "one" 3 | }; 4 | -------------------------------------------------------------------------------- /tests/version1/gamma.js: -------------------------------------------------------------------------------- 1 | gamma = { 2 | color: "green" 3 | } 4 | -------------------------------------------------------------------------------- /tests/version2/epsilon.js: -------------------------------------------------------------------------------- 1 | epsilon = { 2 | color: "red" 3 | } 4 | -------------------------------------------------------------------------------- /adapt/tests/node/tests/foo.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'foo' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/jsonp/lamp.js: -------------------------------------------------------------------------------- 1 | define("lamp", { 2 | color: "blue" 3 | }); 4 | -------------------------------------------------------------------------------- /adapt/tests/sub/betaSub.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'betaSubName' 3 | }); 4 | -------------------------------------------------------------------------------- /bin/xdebug.bat: -------------------------------------------------------------------------------- 1 | set MYDIR=%~dp0 2 | node --debug-brk %MYDIR%x.js %MYDIR% %* 3 | -------------------------------------------------------------------------------- /tests/packages/funky/lib/monkey.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'monkey' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/anon/yellow.js: -------------------------------------------------------------------------------- 1 | require.def("yellow", { 2 | name: "yellow" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/browsertests/docwritenested/two.js: -------------------------------------------------------------------------------- 1 | two = { 2 | name: "two" 3 | }; 4 | -------------------------------------------------------------------------------- /tests/i18n/nls/en-us-surfer/colors.js: -------------------------------------------------------------------------------- 1 | define({ 2 | red: "red, dude" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/packages/dojox/door.js: -------------------------------------------------------------------------------- 1 | require.def({ 2 | name: 'dojox/door' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/packages/foo/lib/second.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'foo/second' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/packages/pkgs/alpha/lib/main.js: -------------------------------------------------------------------------------- 1 | require.def({ 2 | name: 'alpha' 3 | }); -------------------------------------------------------------------------------- /tests/uniques/three.js: -------------------------------------------------------------------------------- 1 | require.def("three", { 2 | name: "three" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/jquery/scripts/app.js: -------------------------------------------------------------------------------- 1 | define(["jquery.alpha", "jquery.beta"], function() {}); 2 | -------------------------------------------------------------------------------- /tests/packages/baz/lib/helper.js: -------------------------------------------------------------------------------- 1 | require.def({ 2 | name: "baz/helper" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/relative/foo/three.js: -------------------------------------------------------------------------------- 1 | require.def("foo/three", { 2 | name: "three" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/jquery/scripts/jquery.alpha.js: -------------------------------------------------------------------------------- 1 | $.fn.alpha = function() { 2 | return "alpha"; 3 | }; -------------------------------------------------------------------------------- /tests/packages/pkgs/alpha/lib/replace.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'alpha/replace' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/packages/pkgs/beta/0.2/scripts/util.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'beta/util' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/packages/pkgs/dojox/table/legs.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'dojox/table/legs' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/relative/foo/bar/two.js: -------------------------------------------------------------------------------- 1 | require.def("foo/bar/two", { 2 | name: "two" 3 | }); 4 | -------------------------------------------------------------------------------- /tests/afterloadreadystate.js: -------------------------------------------------------------------------------- 1 | doh.is("complete", document.readyState); 2 | d.callback(true); 3 | -------------------------------------------------------------------------------- /tests/browsertests/onerror/parseError.js: -------------------------------------------------------------------------------- 1 | 2 | funktion = foo() { 3 | return 'funky'; 4 | } 5 | -------------------------------------------------------------------------------- /tests/dimple.js: -------------------------------------------------------------------------------- 1 | define("dimple", 2 | { 3 | color: "dimple-blue" 4 | } 5 | ); 6 | -------------------------------------------------------------------------------- /tests/doh/runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | java -jar ../../build/lib/rhino/js.jar runner.js "$@" 4 | -------------------------------------------------------------------------------- /tests/i18n/nls/fr/colors.js: -------------------------------------------------------------------------------- 1 | require.def({ 2 | red: "rouge", 3 | blue: "bleu" 4 | }); 5 | -------------------------------------------------------------------------------- /tests/jquery/scripts/jquery.beta.js: -------------------------------------------------------------------------------- 1 | $.fn.beta = function() { 2 | return "beta"; 3 | }; 4 | -------------------------------------------------------------------------------- /tests/packages/dojox/window/pane.js: -------------------------------------------------------------------------------- 1 | require.def({ 2 | name: 'dojox/window/pane' 3 | }); 4 | -------------------------------------------------------------------------------- /adapt/tests/alpha.js: -------------------------------------------------------------------------------- 1 | define(function(require, exports) { 2 | exports.name = 'alpha'; 3 | }); 4 | -------------------------------------------------------------------------------- /tests/anon/blue.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | return { 3 | name: "blue" 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/browsertests/appendbeforeload/one.dphpd: -------------------------------------------------------------------------------- 1 | 4 | 5 | console.log("ONE"); -------------------------------------------------------------------------------- /tests/browsertests/async/one.php: -------------------------------------------------------------------------------- 1 | 4 | 5 | window.log("one.php script"); 6 | -------------------------------------------------------------------------------- /tests/doh/small_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/tests/doh/small_logo.png -------------------------------------------------------------------------------- /tests/packages/bar/0.4/scripts/main.js: -------------------------------------------------------------------------------- 1 | define({ 2 | name: 'bar', 3 | version: '0.4' 4 | }); 5 | -------------------------------------------------------------------------------- /tests/packages/pkgs/dojox/chair/lib/legs.js: -------------------------------------------------------------------------------- 1 | require.def({ 2 | name: 'dojox/chair/legs' 3 | }); 4 | -------------------------------------------------------------------------------- /tests/plugins/b.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | return { 3 | name: "b" 4 | }; 5 | }); 6 | -------------------------------------------------------------------------------- /tests/priority/epsilon.js: -------------------------------------------------------------------------------- 1 | define("epsilon", 2 | { 3 | name: "epsilon" 4 | } 5 | ); 6 | -------------------------------------------------------------------------------- /tests/text/widget.html: -------------------------------------------------------------------------------- 1 |

This is a widget!

I am in a widget

-------------------------------------------------------------------------------- /dist/fonts/Inconsolata.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/Inconsolata.ttf -------------------------------------------------------------------------------- /tests/browsertests/onerror/scriptError.js: -------------------------------------------------------------------------------- 1 | 2 | if (true) { 3 | throw "scriptError throwing"; 4 | } 5 | -------------------------------------------------------------------------------- /tests/doh/_sounds/doh.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/tests/doh/_sounds/doh.wav -------------------------------------------------------------------------------- /tests/i18n/commonA.js: -------------------------------------------------------------------------------- 1 | define(['i18n!nls/colors'], function (colors) { 2 | return colors.red; 3 | }); 4 | -------------------------------------------------------------------------------- /tests/i18n/commonB.js: -------------------------------------------------------------------------------- 1 | define(['i18n!nls/colors'], function (colors) { 2 | return colors.blue; 3 | }); 4 | -------------------------------------------------------------------------------- /tests/layers/epsilon.js: -------------------------------------------------------------------------------- 1 | require.def("epsilon", 2 | { 3 | name: "epsilon" 4 | } 5 | ); 6 | -------------------------------------------------------------------------------- /tests/packages/pkgs/beta/0.2/scripts/beta.js: -------------------------------------------------------------------------------- 1 | require.def(function () { 2 | return 'beta'; 3 | }); 4 | -------------------------------------------------------------------------------- /tests/anon/red.js: -------------------------------------------------------------------------------- 1 | require.def("red", function () { 2 | return { 3 | name: "red" 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/doh/_sounds/dohaaa.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/tests/doh/_sounds/dohaaa.wav -------------------------------------------------------------------------------- /tests/doh/_sounds/woohoo.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/tests/doh/_sounds/woohoo.wav -------------------------------------------------------------------------------- /tests/plugins/prime/b.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | return { 3 | name: "bPrime" 4 | }; 5 | }); 6 | -------------------------------------------------------------------------------- /tests/priority/flower.js: -------------------------------------------------------------------------------- 1 | define(function () { 2 | return { 3 | name: "flower" 4 | }; 5 | }); 6 | -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/PT_Sans.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/PT-Sans/PT_Sans.ttf -------------------------------------------------------------------------------- /tests/foo: -------------------------------------------------------------------------------- 1 | //A test for loading a file with a protocol URL via require() 2 | 3 | var foo = { 4 | name: "foo" 5 | }; -------------------------------------------------------------------------------- /tests/bar: -------------------------------------------------------------------------------- 1 | //A test for loading a file with a protocol-less URL via require() 2 | 3 | var bar = { 4 | name: "bar" 5 | }; -------------------------------------------------------------------------------- /tests/map.js: -------------------------------------------------------------------------------- 1 | require.def("map", 2 | function() { 3 | return { 4 | name: "map" 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /tests/priority/leaf.js: -------------------------------------------------------------------------------- 1 | var globalLeafName = "leaf"; 2 | 3 | require.def("leaf", { 4 | name: globalLeafName 5 | }); 6 | -------------------------------------------------------------------------------- /tests/tres.js: -------------------------------------------------------------------------------- 1 | require.def("tres", 2 | function() { 3 | return { 4 | name: "tres" 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/PT_Sans_Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/PT-Sans/PT_Sans_Bold.ttf -------------------------------------------------------------------------------- /tests/browsertests/scriptloadinteractive/eight.js: -------------------------------------------------------------------------------- 1 | def(function () { 2 | return { 3 | name: 'eight' 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/browsertests/scriptloadinteractive/five.js: -------------------------------------------------------------------------------- 1 | def(function () { 2 | return { 3 | name: 'five' 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/browsertests/scriptloadinteractive/nine.js: -------------------------------------------------------------------------------- 1 | def(function () { 2 | return { 3 | name: 'nine' 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/browsertests/scriptloadinteractive/one.js: -------------------------------------------------------------------------------- 1 | def(function () { 2 | return { 3 | name: 'one' 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/browsertests/scriptloadinteractive/seven.js: -------------------------------------------------------------------------------- 1 | def(function () { 2 | return { 3 | name: 'seven' 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/browsertests/scriptloadinteractive/six.js: -------------------------------------------------------------------------------- 1 | def(function () { 2 | return { 3 | name: 'six' 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/browsertests/scriptloadinteractive/three.js: -------------------------------------------------------------------------------- 1 | def(function () { 2 | return { 3 | name: 'three' 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/browsertests/scriptloadinteractive/two.js: -------------------------------------------------------------------------------- 1 | def(function () { 2 | return { 3 | name: 'two' 4 | }; 5 | }); -------------------------------------------------------------------------------- /tests/simple.js: -------------------------------------------------------------------------------- 1 | require.def("simple", 2 | function() { 3 | return { 4 | color: "blue" 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /tests/version1/beta.js: -------------------------------------------------------------------------------- 1 | define("beta", 2 | function() { 3 | return { 4 | version: 1 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /tests/version1/omega.js: -------------------------------------------------------------------------------- 1 | define("omega", 2 | function() { 3 | return { 4 | version: 1 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /tests/version2/alpha.js: -------------------------------------------------------------------------------- 1 | define("alpha", 2 | function() { 3 | return { 4 | version: 2 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /tests/version2/beta.js: -------------------------------------------------------------------------------- 1 | define("beta", 2 | function() { 3 | return { 4 | version: 2 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/PT_Sans_Caption.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/PT-Sans/PT_Sans_Caption.ttf -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/PT_Sans_Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/PT-Sans/PT_Sans_Italic.ttf -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/PT_Sans_Narrow.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/PT-Sans/PT_Sans_Narrow.ttf -------------------------------------------------------------------------------- /tests/anon/sub/b.js: -------------------------------------------------------------------------------- 1 | define(function(require, exports, module) { 2 | exports.f = function () { return "sub/b" }; 3 | }); 4 | -------------------------------------------------------------------------------- /tests/version1/alpha.js: -------------------------------------------------------------------------------- 1 | require.def("alpha", 2 | function() { 3 | return { 4 | version: 1 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /tests/version2/omega.js: -------------------------------------------------------------------------------- 1 | require.def("omega", 2 | function() { 3 | return { 4 | version: 2 5 | }; 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /dist/ie.css: -------------------------------------------------------------------------------- 1 | 2 | body .sect { 3 | display: none; 4 | } 5 | 6 | 7 | #content ul.index { 8 | list-style: none; 9 | } 10 | -------------------------------------------------------------------------------- /docs/design/packages.md: -------------------------------------------------------------------------------- 1 | # Packages 2 | 3 | Moved to [pkg project](http://github.com/jrburke/pkg/blob/master/docs/design/packages.md) 4 | -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/PT_Sans_Bold_Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/PT-Sans/PT_Sans_Bold_Italic.ttf -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/PT_Sans_Caption_Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/PT-Sans/PT_Sans_Caption_Bold.ttf -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/PT_Sans_Narrow_Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kriszyp/requirejs/master/dist/fonts/PT-Sans/PT_Sans_Narrow_Bold.ttf -------------------------------------------------------------------------------- /docs/jquery-require-sample/webapp/scripts/jquery.alpha.js: -------------------------------------------------------------------------------- 1 | $.fn.alpha = function() { 2 | return this.append("

Alpha is Go!

"); 3 | }; -------------------------------------------------------------------------------- /docs/jquery-require-sample/webapp/scripts/jquery.beta.js: -------------------------------------------------------------------------------- 1 | $.fn.beta = function() { 2 | return this.append("

Beta is Go!

"); 3 | }; 4 | -------------------------------------------------------------------------------- /tests/order/three.js: -------------------------------------------------------------------------------- 1 | //three assumes two has already been loaded 2 | var three = { 3 | name: "three", 4 | twoName: two.name 5 | }; 6 | -------------------------------------------------------------------------------- /tests/order/bar.js: -------------------------------------------------------------------------------- 1 | var bar = 0; 2 | define(function () { 3 | bar += 1; 4 | return function () { 5 | bar += 2; 6 | } 7 | }); 8 | -------------------------------------------------------------------------------- /tests/order/foo.js: -------------------------------------------------------------------------------- 1 | //Just a test file to to use in order build process. 2 | define(["require", "order!one.js", "order!two", "order!three.js"]); 3 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/hasOwnProperty/toString.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module"], function(require, exports, module) { 2 | 3 | }); 4 | -------------------------------------------------------------------------------- /tests/packages/replace.js: -------------------------------------------------------------------------------- 1 | //Tests overriding a package path with a more specific mapping. 2 | require.def({ 3 | name: 'fake/alpha/replace' 4 | }); 5 | -------------------------------------------------------------------------------- /tests/text/local.js: -------------------------------------------------------------------------------- 1 | define(['text!./resources/local.html'], function (localHtml) { 2 | return { 3 | localHtml: localHtml 4 | } 5 | }); 6 | -------------------------------------------------------------------------------- /tests/browsertests/docwritenested/one.js: -------------------------------------------------------------------------------- 1 | loadScript("two.js"); 2 | 3 | one = { 4 | name: "one" 5 | }; 6 | 7 | console.log("Two's name is: " + two.name); 8 | -------------------------------------------------------------------------------- /tests/browsertests/scriptload/two.js: -------------------------------------------------------------------------------- 1 | log("two.js script"); 2 | setTimeout(function () { 3 | log("two.js timeout -- should occur after two.js load"); 4 | }, 13); -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/hasOwnProperty/hasOwnProperty.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module"], function(require, exports, module) { 2 | 3 | }); 4 | -------------------------------------------------------------------------------- /adapt/tests/beta.js: -------------------------------------------------------------------------------- 1 | define(['./sub/betaSub'], function (betaSub) { 2 | return { 3 | name: 'beta', 4 | subName: betaSub.name 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /bin/x: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # A command line tool to run some RequireJS scripts via Node 4 | 5 | MYDIR=`cd \`dirname "$0"\`; pwd` 6 | node $MYDIR/x.js $MYDIR "$@" 7 | -------------------------------------------------------------------------------- /tests/anon/c.js: -------------------------------------------------------------------------------- 1 | require.def(function (require) { 2 | var a = require('a'); 3 | return { 4 | name: 'c', 5 | aName: a.name 6 | }; 7 | }); 8 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/determinism/submodule/b.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module"], function(require, exports, module) { 2 | 3 | 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /tests/i18n/testModule.js: -------------------------------------------------------------------------------- 1 | //A sample module to use in the i18n build test. 2 | require.def(["i18n!nls/colors"], function (colors) { 3 | var red = colors.red; 4 | }); -------------------------------------------------------------------------------- /tests/packages/foo/lib/main.js: -------------------------------------------------------------------------------- 1 | define(function (require, exports) { 2 | exports.name = 'foo'; 3 | exports.alphaName = require('alpha').name; 4 | }); 5 | -------------------------------------------------------------------------------- /tests/exports/assign2.js: -------------------------------------------------------------------------------- 1 | require.def(["module", "exports", "require"], 2 | function (module, exports, require) { 3 | module.exports = "assign2"; 4 | }); 5 | -------------------------------------------------------------------------------- /tests/func.js: -------------------------------------------------------------------------------- 1 | require.def("func", 2 | function () { 3 | return function () { 4 | return "You called a function"; 5 | } 6 | } 7 | ); 8 | -------------------------------------------------------------------------------- /adapt/tests/node/tests/alpha/foo.js: -------------------------------------------------------------------------------- 1 | define(function (require) { 2 | var foo = require('../foo'); 3 | return { 4 | name: 'ALPHA' + foo.name 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/absolute/b.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module"], function(require, exports, module) { 2 | exports.foo = function() {}; 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /tests/packages/funky/index.js: -------------------------------------------------------------------------------- 1 | define(['./lib/monkey'], function (monkey) { 2 | return { 3 | name: 'funky', 4 | monkeyName: monkey.name 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/anon/a.js: -------------------------------------------------------------------------------- 1 | define(function (require, module, exports) { 2 | var b = require("sub/b"); 3 | return { 4 | name: "a", 5 | bName: b.f() 6 | }; 7 | }); 8 | -------------------------------------------------------------------------------- /bin/xj.bat: -------------------------------------------------------------------------------- 1 | set MYDIR=%~dp0 2 | java -classpath %MYDIR%..\build\lib\rhino\js.jar;%MYDIR%..\build\lib\closure\compiler.jar org.mozilla.javascript.tools.shell.Main %MYDIR%x.js %MYDIR% %* 3 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/monkeys/a.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "program"], function(require, exports, module) { 2 | require('program').monkey = 10; 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/transitive/a.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "b"], function(require, exports, module) { 2 | exports.foo = require('b').foo; 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/transitive/b.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "c"], function(require, exports, module) { 2 | exports.foo = require('c').foo; 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /tests/packages/dojox/window/window.js: -------------------------------------------------------------------------------- 1 | require.def(['./pane'], function (pane) { 2 | return { 3 | name: 'dojox/window', 4 | paneName: pane.name 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /tests/packages/pkgs/dojox/chair/lib/main.js: -------------------------------------------------------------------------------- 1 | define(['./legs'], function (legs) { 2 | return { 3 | name: 'dojox/chair', 4 | legsName: legs.name 5 | } 6 | }); 7 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/relative/submodule/b.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module"], function(require, exports, module) { 2 | exports.foo = function () { 3 | }; 4 | 5 | }); 6 | -------------------------------------------------------------------------------- /tests/paths/first.js/first.js: -------------------------------------------------------------------------------- 1 | globalCounter += 1; 2 | 3 | define(['./second'], function (second) { 4 | globalCounter += 1; 5 | return { 6 | load: second 7 | }; 8 | }); 9 | -------------------------------------------------------------------------------- /bin/xjdebug.bat: -------------------------------------------------------------------------------- 1 | set MYDIR=%~dp0 2 | java -classpath %MYDIR%..\build\lib\rhino\js.jar;%MYDIR%..\build\lib\closure\compiler.jar org.mozilla.javascript.tools.debugger.Main %MYDIR%x.js %MYDIR% %* 3 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/relative/submodule/a.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "./b"], function(require, exports, module) { 2 | exports.foo = require('./b').foo; 3 | 4 | }); 5 | -------------------------------------------------------------------------------- /tests/exports/assign.js: -------------------------------------------------------------------------------- 1 | require.def("assign", 2 | ["require", "exports", "module"], 3 | function (require, exports, module) { 4 | module.exports = "assign"; 5 | }); 6 | -------------------------------------------------------------------------------- /tests/exports/vanilla.js: -------------------------------------------------------------------------------- 1 | require.def("vanilla", 2 | ["require", "exports", "module"], 3 | function (require, exports, module) { 4 | exports.name = "vanilla"; 5 | }); 6 | -------------------------------------------------------------------------------- /tests/packages/pkgs/dojox/table/table.js: -------------------------------------------------------------------------------- 1 | require.def(['dojox/chair'], function (chair) { 2 | return { 3 | name: 'dojox/table', 4 | chairName: chair.name 5 | }; 6 | }); 7 | -------------------------------------------------------------------------------- /adapt/tests/node/tests/alpha/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World 5 | 6 | 7 |

Hello World

8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/nested/a/b/c/d.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module"], function(require, exports, module) { 2 | exports.foo = function () { 3 | return 1; 4 | }; 5 | 6 | }); 7 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/transitive/c.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module"], function(require, exports, module) { 2 | exports.foo = function () { 3 | return 1; 4 | }; 5 | 6 | }); 7 | -------------------------------------------------------------------------------- /tests/exports/funcSet.js: -------------------------------------------------------------------------------- 1 | require.def("funcSet", 2 | ["require", "exports", "module"], 3 | function (require, exports, module) { 4 | module.setExports("funcSet"); 5 | }); 6 | -------------------------------------------------------------------------------- /tests/uniques/one.js: -------------------------------------------------------------------------------- 1 | define(function (require) { 2 | return { 3 | name: "one", 4 | threeName: require("three").name, 5 | threeName2: require("three").name 6 | }; 7 | }); 8 | 9 | -------------------------------------------------------------------------------- /bin/xdebug: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # A command line tool to run some scripts used in the RequireJS project, in 4 | # debug mode. 5 | 6 | MYDIR=`cd \`dirname "$0"\`; pwd` 7 | node --debug-brk $MYDIR/x.js $MYDIR "$@" 8 | -------------------------------------------------------------------------------- /tests/i18n/nls/colors.js: -------------------------------------------------------------------------------- 1 | require.def({ 2 | "root": { 3 | red: "red", 4 | blue: "blue", 5 | green: "green" 6 | }, 7 | "en-us-surfer": true, 8 | "fr": true 9 | }); 10 | -------------------------------------------------------------------------------- /bin/xjdebug: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | MYDIR=`cd \`dirname "$0"\`; pwd` 4 | java -classpath $MYDIR/../build/lib/rhino/js.jar:$MYDIR/../build/lib/closure/compiler.jar org.mozilla.javascript.tools.debugger.Main $MYDIR/x.js $MYDIR "$@" 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "require", 3 | "version": "0.15.0", 4 | "author": { 5 | "name":"James Burke" 6 | }, 7 | "directories": { 8 | "lib": "require" 9 | }, 10 | "main": "./require.js" 11 | } -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/absolute/submodule/a.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "b"], function(require, exports, module) { 2 | exports.foo = function () { 3 | return require('b'); 4 | }; 5 | 6 | }); 7 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/cyclic/a.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "b"], function(require, exports, module) { 2 | exports.a = function () { 3 | return b; 4 | }; 5 | var b = require('b'); 6 | 7 | }); 8 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/cyclic/b.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "a"], function(require, exports, module) { 2 | var a = require('a'); 3 | exports.b = function () { 4 | return a; 5 | }; 6 | 7 | }); 8 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/system.js: -------------------------------------------------------------------------------- 1 | define({ 2 | stdio: { 3 | //Funky list args to appease Safari 4 | print: function (a, b) { 5 | console.log(a, b); 6 | } 7 | } 8 | }); 9 | -------------------------------------------------------------------------------- /tests/urlfetch/two.js: -------------------------------------------------------------------------------- 1 | require.def("one", { 2 | name: "one" 3 | }); 4 | 5 | require.def("two", ["one"], function (one) { 6 | return { 7 | name: "two", 8 | oneName: "one" 9 | }; 10 | }); 11 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/exactExports/a.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "program"], function(require, exports, module) { 2 | exports.program = function () { 3 | return require('program'); 4 | }; 5 | 6 | }); 7 | -------------------------------------------------------------------------------- /tests/urlfetch/three.js: -------------------------------------------------------------------------------- 1 | require.def("three", { 2 | name: "three" 3 | }); 4 | 5 | define("four", ["three"], function (three) { 6 | return { 7 | name: "four", 8 | threeName: "three" 9 | }; 10 | }); 11 | -------------------------------------------------------------------------------- /tests/paths/first.js/second.js: -------------------------------------------------------------------------------- 1 | define(['./first'], function () { 2 | return function (id, parentRequire, loaded) { 3 | loaded({ 4 | name: 'first', 5 | secondName: 'second' 6 | }); 7 | }; 8 | }); 9 | -------------------------------------------------------------------------------- /tests/priority/priorityWithDeps/script/req/begin.js: -------------------------------------------------------------------------------- 1 | require.def('req/begin', function() { 2 | window.ip = { 3 | begin: 'begin', 4 | controllers: {}, 5 | models: {}, 6 | views: {}, 7 | utils: {}, 8 | config: {} 9 | }; 10 | }); 11 | -------------------------------------------------------------------------------- /tests/priority/priorityWithDeps/script/req/config.js: -------------------------------------------------------------------------------- 1 | require.def('req/config', [ 2 | 'req/begin' 3 | ], function() { 4 | var config = { 5 | test: 'Hello require', 6 | state: 'alpha' 7 | }; 8 | return ip.config = config; 9 | }); 10 | -------------------------------------------------------------------------------- /tests/uniques/two.js: -------------------------------------------------------------------------------- 1 | require.def("two", ["one", "three", "one"], function (one, three, one2) { 2 | return { 3 | name: "two", 4 | oneName: one.name, 5 | oneName2: one2.name, 6 | threeName: three.name 7 | }; 8 | }); 9 | -------------------------------------------------------------------------------- /testBaseUrl.js: -------------------------------------------------------------------------------- 1 | define([], function() { 2 | doh.register( 3 | "testBaseUrl", 4 | [ 5 | function testBaseUrl(t){ 6 | t.is(true, true); 7 | } 8 | ] 9 | ); 10 | doh.run(); 11 | }); -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/determinism/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","submodule/a"], function(require, exports, module) { 2 | var test = require('test'); 3 | require('submodule/a'); 4 | test.print('DONE', 'info'); 5 | 6 | }); 7 | -------------------------------------------------------------------------------- /tests/dos.js: -------------------------------------------------------------------------------- 1 | define("dos", 2 | ["tres"], 3 | function(tres) { 4 | return { 5 | name: "dos", 6 | doSomething: function() { 7 | return { 8 | tresName: tres.name 9 | }; 10 | } 11 | }; 12 | } 13 | ); 14 | -------------------------------------------------------------------------------- /tests/packages/baz/lib/index.js: -------------------------------------------------------------------------------- 1 | define(['bar', 'foo', './helper'], function (bar, foo, helper) { 2 | return { 3 | name: 'baz', 4 | barDepVersion: bar.version, 5 | fooName: foo.name, 6 | helperName: helper.name 7 | }; 8 | }); 9 | -------------------------------------------------------------------------------- /docs/jquery-require-sample/webapp/scripts/main.js: -------------------------------------------------------------------------------- 1 | require(["jquery", "jquery.alpha", "jquery.beta"], function($) { 2 | //the jquery.alpha.js and jquery.beta.js plugins have been loaded. 3 | $(function() { 4 | $('body').alpha().beta(); 5 | }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/one.js: -------------------------------------------------------------------------------- 1 | define("one", 2 | ["require", "two"], 3 | function(require) { 4 | var one = { 5 | size: "large", 6 | doSomething: function() { 7 | return require("two"); 8 | } 9 | }; 10 | 11 | return one; 12 | } 13 | ); 14 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/transitive/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","a"], function(require, exports, module) { 2 | var test = require('test'); 3 | test.assert(require('a').foo() == 1, 'transitive'); 4 | test.print('DONE', 'info'); 5 | 6 | }); 7 | -------------------------------------------------------------------------------- /tests/text/resources/sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | sample.html 5 | 6 | 7 | Hello World! 8 | 9 | -------------------------------------------------------------------------------- /tests/two.js: -------------------------------------------------------------------------------- 1 | define("two", 2 | ["require", "one"], 3 | function(require, one) { 4 | return { 5 | size: "small", 6 | color: "redtwo", 7 | doSomething: function() { 8 | return require("one").doSomething(); 9 | } 10 | }; 11 | } 12 | ); 13 | -------------------------------------------------------------------------------- /bin/xj: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # A command line tool to run some RequireJS scripts via Java/Rhino 4 | 5 | MYDIR=`cd \`dirname "$0"\`; pwd` 6 | java -classpath $MYDIR/../build/lib/rhino/js.jar:$MYDIR/../build/lib/closure/compiler.jar org.mozilla.javascript.tools.shell.Main $MYDIR/x.js $MYDIR "$@" 7 | -------------------------------------------------------------------------------- /tests/text/subwidget.js: -------------------------------------------------------------------------------- 1 | require.def("subwidget", 2 | ["text!subwidget.html!strip", "text!subwidget2.html"], 3 | function(template, template2) { 4 | return { 5 | name: "subwidget", 6 | template: template, 7 | template2: template2 8 | }; 9 | } 10 | ); 11 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/nested/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","a/b/c/d"], function(require, exports, module) { 2 | var test = require('test'); 3 | test.assert(require('a/b/c/d').foo() == 1, 'nested module identifier'); 4 | test.print('DONE', 'info'); 5 | 6 | }); 7 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Tests 5 | 6 | 7 |

require.js: Tests

8 |
    9 |
  1. All Automated Tests 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/monkeys/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "a","test"], function(require, exports, module) { 2 | var a = require('a'); 3 | var test = require('test'); 4 | test.assert(exports.monkey == 10, 'monkeys permitted'); 5 | test.print('DONE', 'info'); 6 | 7 | }); 8 | -------------------------------------------------------------------------------- /tests/priority/priorityWithDeps/script/req/utils/utils.js: -------------------------------------------------------------------------------- 1 | require.def('req/utils/utils', [ 2 | 'req/begin', 3 | 'req/config' 4 | ], function() { 5 | var utils = { 6 | test: function() { 7 | return ('utils ' + ip.config.test); 8 | } 9 | }; 10 | return ip.utils = utils; 11 | }); 12 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/exactExports/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","a"], function(require, exports, module) { 2 | var test = require('test'); 3 | var a = require('a'); 4 | test.assert(a.program() === exports, 'exact exports'); 5 | test.print('DONE', 'info'); 6 | 7 | }); 8 | -------------------------------------------------------------------------------- /tests/text/subwidget.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | sample.html 5 | 6 | 7 |

This is a subwidget

8 | 9 | -------------------------------------------------------------------------------- /tests/priority/priorityWithDeps/script/req/app.js: -------------------------------------------------------------------------------- 1 | require.def('Carousel', function () { 2 | return function Carousel(service) { 3 | this.service = service; 4 | this.someType = 'Carousel'; 5 | }; 6 | }); 7 | 8 | require.def('app', ['Carousel'], function () { 9 | 10 | }); 11 | -------------------------------------------------------------------------------- /tests/uno.js: -------------------------------------------------------------------------------- 1 | require.def("uno", 2 | ["dos", "tres"], 3 | function(dos, tres) { 4 | return { 5 | name: "uno", 6 | doSomething: function() { 7 | return { 8 | dosName: dos.name, 9 | tresName: tres.name 10 | }; 11 | } 12 | }; 13 | } 14 | ); 15 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/hasOwnProperty/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "hasOwnProperty","toString","test"], function(require, exports, module) { 2 | var hasOwnProperty = require('hasOwnProperty'); 3 | var toString = require('toString'); 4 | var test = require('test'); 5 | test.print('DONE', 'info'); 6 | 7 | }); 8 | -------------------------------------------------------------------------------- /tests/text/widget.js: -------------------------------------------------------------------------------- 1 | define("widget", 2 | ["subwidget", "text!widget.html"], 3 | function(subwidget, template) { 4 | return { 5 | subWidgetName: subwidget.name, 6 | subWidgetTemplate: subwidget.template, 7 | subWidgetTemplate2: subwidget.template2, 8 | template: template 9 | }; 10 | } 11 | ); 12 | -------------------------------------------------------------------------------- /tests/relative/foo/bar/one.js: -------------------------------------------------------------------------------- 1 | define("foo/bar/one", 2 | ["require", "./two", "../three", "text!./message.txt"], 3 | function (require, two, three, message) { 4 | return { 5 | name: "one", 6 | twoName: two.name, 7 | threeName: three.name, 8 | message: message 9 | }; 10 | }); 11 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/absolute/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","submodule/a","b"], function(require, exports, module) { 2 | var test = require('test'); 3 | var a = require('submodule/a'); 4 | var b = require('b'); 5 | test.assert(a.foo().foo === b.foo, 'require works with absolute identifiers'); 6 | test.print('DONE', 'info'); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /tests/priority/tree.js: -------------------------------------------------------------------------------- 1 | require.def("bark", function () { 2 | return { 3 | name: "bark" 4 | }; 5 | }); 6 | 7 | var globalLeafNameForTree = globalLeafName; 8 | 9 | define("tree", ["leaf", "bark"], function () { 10 | return { 11 | name: "tree", 12 | leafName: globalLeafNameForTree, 13 | barkName: bark.name 14 | }; 15 | }); 16 | -------------------------------------------------------------------------------- /tests/funcFour.js: -------------------------------------------------------------------------------- 1 | define("funcFour", 2 | ["require", "funcThree"], 3 | function (require) { 4 | var four = function (arg) { 5 | return "FOUR called with " + arg; 6 | }; 7 | 8 | four.suffix = function () { 9 | return require("funcThree").suffix(); 10 | }; 11 | 12 | return four; 13 | } 14 | ); 15 | -------------------------------------------------------------------------------- /tests/funcThree.js: -------------------------------------------------------------------------------- 1 | require.def("funcThree", 2 | ["funcFour"], 3 | function (four) { 4 | var three = function (arg) { 5 | return arg + "-" + require("funcFour").suffix(); 6 | }; 7 | 8 | three.suffix = function () { 9 | return "THREE_SUFFIX"; 10 | }; 11 | 12 | return three; 13 | } 14 | ); 15 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/relative/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","submodule/a","submodule/b"], function(require, exports, module) { 2 | var test = require('test'); 3 | var a = require('submodule/a'); 4 | var b = require('submodule/b'); 5 | test.assert(a.foo == b.foo, 'a and b share foo through a relative require'); 6 | test.print('DONE', 'info'); 7 | 8 | }); 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | adapt/r.js 3 | build/convert/build/ 4 | build/convert/node/r.js 5 | build/convert/dojorequire/ 6 | build/convert/dojo-build/ 7 | build/tests/builds/ 8 | build/tests/priority/webapp-build 9 | build/jquery/dist/ 10 | build/require/build/ 11 | docs/jquery-require-sample/webapp-build/ 12 | docs/jquery-require-sample/dist 13 | dist/dist-site/ 14 | dist/dist-build/ 15 | 16 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/method/a.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module"], function(require, exports, module) { 2 | exports.foo = function () { 3 | return this; 4 | }; 5 | exports.set = function (x) { 6 | this.x = x; 7 | }; 8 | exports.get = function () { 9 | return this.x; 10 | }; 11 | exports.getClosed = function () { 12 | return exports.x; 13 | }; 14 | 15 | }); 16 | -------------------------------------------------------------------------------- /tests/workers.js: -------------------------------------------------------------------------------- 1 | importScripts('../require.js'); 2 | 3 | require({ 4 | baseUrl: "./" 5 | }, 6 | ["require", "simple", "anon/blue", "func", "anon/green"], 7 | function(require, simple, blue, func, green) { 8 | postMessage(simple.color); 9 | postMessage(green.name); 10 | postMessage(func()); 11 | postMessage(blue.name); 12 | } 13 | ); 14 | -------------------------------------------------------------------------------- /tests/plugins/earth.js: -------------------------------------------------------------------------------- 1 | define(function (require) { 2 | return { 3 | getA: function () { 4 | return require("./index!0?./a:./b:./c"); 5 | }, 6 | getC: function () { 7 | return require("./index!2?./a:./b:./c"); 8 | }, 9 | getB: function () { 10 | return require("./index!1?./a:./b:./c"); 11 | } 12 | }; 13 | }); 14 | -------------------------------------------------------------------------------- /tests/dataMain.js: -------------------------------------------------------------------------------- 1 | require({ 2 | baseUrl: "./" 3 | }, 4 | ["require", "simple"], 5 | function(require, simple) { 6 | doh.register( 7 | "dataMain", 8 | [ 9 | function dataMain(t){ 10 | t.is("blue", simple.color); 11 | } 12 | ] 13 | ); 14 | doh.run(); 15 | } 16 | ); 17 | -------------------------------------------------------------------------------- /tests/doh/_sounds/LICENSE: -------------------------------------------------------------------------------- 1 | License Disclaimer: 2 | 3 | All contents of this directory are Copyright (c) the Dojo Foundation, with the 4 | following exceptions: 5 | ------------------------------------------------------------------------------- 6 | 7 | woohoo.wav, doh.wav, dohaaa.wav: 8 | * Copyright original authors. 9 | Copied from: 10 | http://simpson-homer.com/homer-simpson-soundboard.html 11 | -------------------------------------------------------------------------------- /tests/plugins/prime/earth.js: -------------------------------------------------------------------------------- 1 | define(function (require) { 2 | return { 3 | getA: function () { 4 | return require("../index!0?./a:./b:./c"); 5 | }, 6 | getC: function () { 7 | return require("../index!2?./a:./b:./c"); 8 | }, 9 | getB: function () { 10 | return require("../index!1?./a:./b:./c"); 11 | } 12 | }; 13 | }); 14 | -------------------------------------------------------------------------------- /tests/funcTwo.js: -------------------------------------------------------------------------------- 1 | define("funcTwo", 2 | ["require", "funcOne"], 3 | function (require) { 4 | var two = function (name) { 5 | this.name = name; 6 | this.one = new (require("funcOne"))("ONE"); 7 | }; 8 | 9 | two.prototype.oneName = function () { 10 | return this.one.getName(); 11 | }; 12 | 13 | return two; 14 | } 15 | ); 16 | -------------------------------------------------------------------------------- /dist/post.html: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /adapt/tests/node/index.js: -------------------------------------------------------------------------------- 1 | //The traditional nodejs http example 2 | 3 | require(['sys', 'http'], function (sys, http) { 4 | http.createServer(function (req, res) { 5 | setTimeout(function () { 6 | res.writeHead(200, {'Content-Type': 'text/plain'}); 7 | res.end('Hello World\n'); 8 | }, 2000); 9 | }).listen(8000); 10 | sys.puts('Server running at http://127.0.0.1:8000/'); 11 | }); 12 | -------------------------------------------------------------------------------- /tests/funcOne.js: -------------------------------------------------------------------------------- 1 | require.def("funcOne", 2 | ["require", "funcTwo"], 3 | function (require) { 4 | var one = function (name) { 5 | this.name = name; 6 | }; 7 | 8 | one.prototype.getName = function () { 9 | var inst = new (require("funcTwo"))("-NESTED"); 10 | return this.name + inst.name; 11 | }; 12 | 13 | return one; 14 | } 15 | ); 16 | -------------------------------------------------------------------------------- /docs/faq.html: -------------------------------------------------------------------------------- 1 |
2 |

RequireJS FAQs (Frequently Asked Questions)

3 | 4 | 8 |
-------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/cyclic/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","a","b"], function(require, exports, module) { 2 | var test = require('test'); 3 | var a = require('a'); 4 | var b = require('b'); 5 | 6 | test.assert(a.a, 'a exists'); 7 | test.assert(b.b, 'b exists') 8 | test.assert(a.a().b === b.b, 'a gets b'); 9 | test.assert(b.b().a === a.a, 'b gets a'); 10 | 11 | test.print('DONE', 'info'); 12 | 13 | }); 14 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/determinism/submodule/a.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","test","a"], function(require, exports, module) { 2 | var test = require('test'); 3 | var pass = false; 4 | var test = require('test'); 5 | try { 6 | require('a'); 7 | } catch (exception) { 8 | pass = true; 9 | } 10 | test.assert(pass, 'require does not fall back to relative modules when absolutes are not available.') 11 | 12 | }); 13 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/missing/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","bogus"], function(require, exports, module) { 2 | var test = require('test'); 3 | try { 4 | require('bogus'); 5 | test.print('FAIL require throws error when module missing', 'fail'); 6 | } catch (exception) { 7 | test.print('PASS require throws error when module missing', 'pass'); 8 | } 9 | test.print('DONE', 'info'); 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /tests/priority/two.js: -------------------------------------------------------------------------------- 1 | //Example layer file. 2 | 3 | require.def("gamma", 4 | ["theta", "epsilon"], 5 | function (theta, epsilon) { 6 | return { 7 | name: "gamma", 8 | thetaName: theta.name, 9 | epsilonName: epsilon.name 10 | }; 11 | } 12 | ); 13 | 14 | require.def("theta", 15 | function () { 16 | return { 17 | name: "theta" 18 | }; 19 | } 20 | ); 21 | -------------------------------------------------------------------------------- /tests/priority/one.js: -------------------------------------------------------------------------------- 1 | //Example layer file. 2 | 3 | require.def("alpha", 4 | ["beta", "gamma"], 5 | function (beta, gamma) { 6 | return { 7 | name: "alpha", 8 | betaName: beta.name 9 | }; 10 | } 11 | ); 12 | 13 | require.def("beta", 14 | ["gamma"], 15 | function (gamma) { 16 | return { 17 | name: "beta", 18 | gammaName: gamma.name 19 | }; 20 | } 21 | ); 22 | -------------------------------------------------------------------------------- /tests/doh/_rhinoRunner.js: -------------------------------------------------------------------------------- 1 | if(this["dojo"]){ 2 | dojo.provide("doh._rhinoRunner"); 3 | } 4 | 5 | doh.debug = print; 6 | 7 | // Override the doh._report method to make it quit with an 8 | // appropriate exit code in case of test failures. 9 | (function(){ 10 | var oldReport = doh._report; 11 | doh._report = function(){ 12 | oldReport.apply(doh, arguments); 13 | if(this._failureCount > 0 || this._errorCount > 0){ 14 | quit(1); 15 | } 16 | } 17 | })(); 18 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/method/program.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "test","a"], function(require, exports, module) { 2 | var test = require('test'); 3 | var a = require('a'); 4 | var foo = a.foo; 5 | test.assert(a.foo() == a, 'calling a module member'); 6 | test.assert(foo() == (function (){return this})(), 'members not implicitly bound'); 7 | a.set(10); 8 | test.assert(a.get() == 10, 'get and set') 9 | test.print('DONE', 'info'); 10 | 11 | }); 12 | -------------------------------------------------------------------------------- /docs/jquery-require-sample/webapp/scripts/app.build.js: -------------------------------------------------------------------------------- 1 | ({ 2 | appDir: "../", 3 | baseUrl: "scripts", 4 | dir: "../../webapp-build", 5 | //Comment out the optimize line if you want 6 | //the code minified by UglifyJS 7 | optimize: "none", 8 | 9 | paths: { 10 | "jquery": "require-jquery" 11 | }, 12 | 13 | modules: [ 14 | { 15 | name: "main", 16 | exclude: ["jquery"] 17 | } 18 | ] 19 | }) 20 | -------------------------------------------------------------------------------- /tests/dataMain.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: data-main Test 5 | 6 | 7 | 8 | 9 | 10 |

require.js: data-main Test

11 |

Check console for messages

12 | 13 | 14 | -------------------------------------------------------------------------------- /docs/jquery-require-sample/webapp/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jQuery+RequireJS Sample Page 5 | 6 | 7 | 8 | 9 |

jQuery+RequireJS Sample Page

10 |

Look at source or inspect the DOM to see how it works.

11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/baseUrl.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Default baseUrl Test 5 | 6 | 7 | 8 | 9 | 10 |

require.js: Default baseUrl Test

11 |

Check console for messages

12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/priority/priority.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Priority Test 5 | 6 | 7 | 8 | 9 | 10 |

require.js: Priority Test

11 |

Check console for messages

12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/anon/magenta.js: -------------------------------------------------------------------------------- 1 | define(function (require, exports, module) { 2 | //This is a fakeout require("fake1"); 3 | 4 | var red = require("red"), 5 | blue = require('./blue'), 6 | message = require('text!./message.txt'); 7 | 8 | /* 9 | And another fakeoute require("fake2"); 10 | */ 11 | 12 | //Use ugly exports 13 | exports.name = red.name + blue.name; 14 | exports.path = require.nameToUrl('./foo', '.html'); 15 | exports.message = message; 16 | }); 17 | -------------------------------------------------------------------------------- /tests/plugins/sync.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Sync Plugin Test 5 | 6 | 7 | 8 | 9 | 10 |

require.js: Sync Plugin Test

11 |

Check console for messages

12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/circular.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Circular Test 5 | 6 | 7 | 8 | 9 | 10 | 11 |

require.js: Circular Test

12 |

Check console for messages

13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | console.log('PASS ' + message, 'pass'); 12 | } else { 13 | console.error('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/jquery/scripts/dynamicApp.js: -------------------------------------------------------------------------------- 1 | require({ 2 | "baseUrl": "./scripts/", 3 | "paths": { 4 | "jquery": "http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.4.min" 5 | //"jquery": "http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min" 6 | } 7 | }); 8 | 9 | define(["jquery.gamma", "jquery.epsilon"], function() { 10 | 11 | $(function () { 12 | doh.is('epsilon', $('body').epsilon()); 13 | doh.is('epsilon', $('body').epsilon()); 14 | readyFired(); 15 | }); 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /tests/exports/exports.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Exports Test 5 | 6 | 7 | 8 | 9 | 10 | 11 |

require.js: Exports Test

12 |

Check console for messages

13 | 14 | 15 | -------------------------------------------------------------------------------- /adapt/tests/node/tests/server.js: -------------------------------------------------------------------------------- 1 | //The traditional nodejs http example 2 | 3 | require(['sys', 'foo', 'http', 'alpha/foo', 'text!alpha/hello.html'], function (sys, foo, http, alphaFoo, helloHtml) { 4 | http.createServer(function (req, res) { 5 | res.writeHead(200, {'Content-Type': 'text/plain'}); 6 | res.write('Hello ' + foo.name + '\nHello ' + alphaFoo.name + '\n'); 7 | res.write(helloHtml) 8 | res.end('\n'); 9 | }).listen(8000); 10 | sys.puts('Server running at http://127.0.0.1:8000/'); 11 | }); 12 | -------------------------------------------------------------------------------- /tests/packages/packages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Packages Test 5 | 6 | 7 | 8 | 9 | 10 | 11 |

require.js: Packages Test

12 |

Check console for messages

13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/cyclic/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/method/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/missing/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/monkeys/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/nested/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/absolute/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/determinism/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/exactExports/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/relative/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/transitive/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/hasOwnProperty/program.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Program Runner 5 | 6 | 15 | 16 | 17 |

Program Runner

18 |

Check console for results.

19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/jquery/scripts/jquery.gamma.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | //Define the plugin. 3 | function plugin($) { 4 | $.fn.gamma = function() { 5 | return 'gamma'; 6 | }; 7 | 8 | $(function () { 9 | doh.is('gamma', $('body').gamma()); 10 | readyFired(); 11 | }); 12 | } 13 | 14 | //Register the plugin. 15 | if (typeof define !== 'undefined') { 16 | define(['jquery'], plugin); 17 | } else if (typeof jQuery !== 'undefined') { 18 | plugin(jQuery); 19 | } 20 | }()); 21 | -------------------------------------------------------------------------------- /tests/anon/anonSimple.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Simple Anonymous Module Test 5 | 6 | 7 | 8 | 9 | 10 | 11 |

require.js: Simple Anonymous Module Test

12 |

Check console for messages

13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/doh/README: -------------------------------------------------------------------------------- 1 | DOH may be run standalone by issuing a command like the following: 2 | 3 | java -jar ../shrinksafe/js.jar runner.js testModule=tests.colors 4 | 5 | where the testModule argument is optional and shrinksafe/js.jar is just a 6 | convenient copy of the Rhino JavaScript engine -- the custom patch is not 7 | required. 8 | 9 | Optional arguments include: 10 | * dojoUrl - specifies the location of dojo.js 11 | * testUrl - specifies a Javascript file to load with initialization code 12 | * testModule - specifies a test module in the dojo package namespace 13 | -------------------------------------------------------------------------------- /tests/jquery/scripts/jquery.epsilon.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | //Define the plugin. 3 | function plugin($) { 4 | $.fn.epsilon = function() { 5 | return 'epsilon'; 6 | }; 7 | 8 | $(function () { 9 | doh.is('epsilon', $('body').epsilon()); 10 | readyFired(); 11 | }); 12 | } 13 | 14 | //Register the plugin. 15 | if (typeof define !== 'undefined') { 16 | define(['jquery'], plugin); 17 | } else if (typeof jQuery !== 'undefined') { 18 | plugin(jQuery); 19 | } 20 | }()); 21 | -------------------------------------------------------------------------------- /tests/relative/relative.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Relative Module Names Test 5 | 6 | 7 | 8 | 9 | 10 | 11 |

require.js: Relative Module Names Test

12 |

Check console for messages

13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/cyclic/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/method/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/missing/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/monkeys/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/nested/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/absolute/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/determinism/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/exactExports/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/relative/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/transitive/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/hasOwnProperty/test.js: -------------------------------------------------------------------------------- 1 | define(["require", "exports", "module", "system"], function(require, exports, module) { 2 | 3 | exports.print = typeof print !== "undefined" ? print : function () { 4 | var system = require("system"); 5 | var stdio = system.stdio; 6 | stdio.print.apply(stdio, arguments); 7 | }; 8 | 9 | exports.assert = function (guard, message) { 10 | if (guard) { 11 | exports.print('PASS ' + message, 'pass'); 12 | } else { 13 | exports.print('FAIL ' + message, 'fail'); 14 | } 15 | }; 16 | 17 | 18 | }); 19 | -------------------------------------------------------------------------------- /tests/doh/_nodeRunner.js: -------------------------------------------------------------------------------- 1 | 2 | /*global doh: false, process: false */ 3 | 4 | var aps = Array.prototype.slice; 5 | 6 | doh.debug = function () { 7 | //Could have multiple args, join them all together. 8 | var msg = aps.call(arguments, 0).join(' '); 9 | console.log(msg); 10 | }; 11 | 12 | // Override the doh._report method to make it quit with an 13 | // appropriate exit code in case of test failures. 14 | var oldReport = doh._report; 15 | doh._report = function () { 16 | oldReport.apply(doh, arguments); 17 | if (this._failureCount > 0 || this._errorCount > 0) { 18 | process.exit(1); 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /tests/depoverlap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Dependency Overlap Test 5 | 6 | 7 | 8 | 9 | 10 |

require.js: Dependency Overlap Test

11 |

uno requires dos and tres, but tres also requires dos. Make sure 12 | dos is only added once, and that all are defined correctly.

13 |

Check console for messages

14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/exports/exports-tests.js: -------------------------------------------------------------------------------- 1 | require({ 2 | baseUrl: require.isBrowser ? "./" : "./exports/" 3 | }, 4 | ["require", "vanilla", "funcSet", "assign", "assign2"], 5 | function(require, vanilla, funcSet, assign, assign2) { 6 | doh.register( 7 | "exports", 8 | [ 9 | function exports(t){ 10 | t.is("vanilla", vanilla.name); 11 | t.is("funcSet", funcSet); 12 | t.is("assign", assign); 13 | t.is("assign2", assign2); 14 | } 15 | ] 16 | ); 17 | doh.run(); 18 | } 19 | ); 20 | -------------------------------------------------------------------------------- /tests/layers/layer1.js: -------------------------------------------------------------------------------- 1 | //Example layer file. 2 | 3 | require.def("alpha", 4 | ["beta", "gamma"], 5 | function (beta, gamma) { 6 | return { 7 | name: "alpha", 8 | betaName: beta.name 9 | }; 10 | } 11 | ); 12 | 13 | define("beta", 14 | ["gamma"], 15 | function (gamma) { 16 | return { 17 | name: "beta", 18 | gammaName: gamma.name 19 | }; 20 | } 21 | ); 22 | 23 | define("gamma", 24 | ["epsilon"], 25 | function (epsilon) { 26 | return { 27 | name: "gamma", 28 | epsilonName: epsilon.name 29 | }; 30 | } 31 | ); 32 | -------------------------------------------------------------------------------- /tests/priority/priorityWithDeps/script/req/bootstrap.js: -------------------------------------------------------------------------------- 1 | require.def('req/bootstrap', [ 2 | 'req/begin', 3 | 'req/config', 4 | 'req/utils/utils' 5 | ], function() { 6 | ip.bootstrap = 'bootstrap'; 7 | }); 8 | 9 | 10 | /* 11 | //begin module defines a global 12 | var begin = {}; 13 | require.def('begin', function () { 14 | begin.name = 'begin'; 15 | }); 16 | 17 | //appConfig defines a global. 18 | var appConfig = {}; 19 | require.def('appConfig', ['begin'], function () { 20 | appConfig.state = 'alpha'; 21 | }); 22 | 23 | require.def('bootstrap', ['begin', 'appConfig'], function () { 24 | appConfig.bootstrap = 'bootstrap'; 25 | }); 26 | */ 27 | -------------------------------------------------------------------------------- /tests/relative/relative-tests.js: -------------------------------------------------------------------------------- 1 | require({ 2 | baseUrl: require.isBrowser ? "./" : "./relative/", 3 | paths: { 4 | require: "../../require" 5 | } 6 | }, 7 | ["require", "foo/bar/one"], 8 | function(require, one) { 9 | doh.register( 10 | "relative", 11 | [ 12 | function relative(t){ 13 | t.is("one", one.name); 14 | t.is("two", one.twoName); 15 | t.is("three", one.threeName); 16 | t.is("hello world", one.message); 17 | } 18 | ] 19 | ); 20 | 21 | doh.run(); 22 | } 23 | ); 24 | -------------------------------------------------------------------------------- /tests/plugins/sync-tests.js: -------------------------------------------------------------------------------- 1 | require({ 2 | baseUrl: require.isBrowser ? "./" : "./plugins/" 3 | }, ['require', 'earth', 'prime/earth'], 4 | function (require, earth, primeEarth) { 5 | 6 | doh.register( 7 | "pluginsSync", 8 | [ 9 | function pluginsSync(t){ 10 | t.is("a", earth.getA().name); 11 | t.is("c", earth.getC().name); 12 | t.is("b", earth.getB().name); 13 | t.is("aPrime", primeEarth.getA().name); 14 | t.is("cPrime", primeEarth.getC().name); 15 | t.is("bPrime", primeEarth.getB().name); 16 | } 17 | ] 18 | ); 19 | doh.run(); 20 | }); 21 | -------------------------------------------------------------------------------- /tests/simple-tests.js: -------------------------------------------------------------------------------- 1 | require({ 2 | baseUrl: "./" 3 | }, 4 | ["require", "map", "simple", "dimple", "func"], 5 | function(require, map, simple, dimple, func) { 6 | doh.register( 7 | "simple", 8 | [ 9 | function colors(t){ 10 | t.is("map", map.name); 11 | t.is("blue", simple.color); 12 | t.is("dimple-blue", dimple.color); 13 | t.is("You called a function", func()); 14 | } 15 | ] 16 | ); 17 | 18 | //In rhino there is no more simple tests, but in web browser there is. 19 | if (typeof moreSimpleTests === 'undefined') { 20 | doh.run(); 21 | } 22 | } 23 | ); 24 | -------------------------------------------------------------------------------- /tests/jsonp/twitter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: JSONP Test: Twitter 5 | 6 | 19 | 20 | 21 |

require.js: JSONP Test: Twitter

22 |

Just a standalone .

23 | REQUIRES access to internet/Twitter to run. Otherwise it will fail. 24 |

Check console for the current trends JSON return value.

25 | 26 | 27 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 |
2 |

/* ---

3 | 4 |

RequireJS is a JavaScript file and module loader. It is optimized for 5 | in-browser use, but it can be used in other JavaScript environments, 6 | like Rhino and Node. Using 7 | a modular script loader like RequireJS will improve the speed and 8 | quality of your code.

9 | 10 |

11 | IE 6+ .......... compatible ✔
12 | Firefox 2+ ..... compatible ✔
13 | Safari 3.2+ .... compatible ✔
14 | Chrome 3+ ...... compatible ✔
15 | Opera 10+ ...... compatible ✔ 16 |

17 | 18 |

Get started then check out the API.

19 | 20 |

--- */

21 |
22 | -------------------------------------------------------------------------------- /dist/init.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function($) { 2 | 3 | // set panel min-height to full browser height 4 | $(window).bind("load resize", function(){ 5 | var h = $(window).height(); 6 | $("#wrapper, #grid, #navBg").css({ "min-height" : (h) }); 7 | $("#content").css({ "min-height" : (h-168) }); 8 | }); 9 | 10 | // toggle grid 11 | 12 | $("#grid").hide(); 13 | 14 | $(document.documentElement).keyup(function (event) { 15 | if (event.keyCode == 71) { 16 | $("#grid").fadeToggle(100); 17 | } 18 | }); 19 | 20 | // if window is larger than #nav then #nav == fixed, if #nav is larger than window #nav == relative 21 | $(window).bind("load resize", function(){ 22 | var w = $(window).height(); 23 | var h = $("#nav").outerHeight(); 24 | $("#nav").css("position",(w < h) ? ("relative") : ("fixed")); 25 | }); 26 | 27 | // done! 28 | }); 29 | -------------------------------------------------------------------------------- /adapt/tests/node/canvasTest.js: -------------------------------------------------------------------------------- 1 | //Tested with nave, node 0.2.5, 2 | //npm install canvas 3 | //npm install express 4 | 5 | /*jslint strict: false */ 6 | /*global require: false, console: false */ 7 | 8 | var Canvas = require('canvas'), 9 | express = require('express'), 10 | canvas = new Canvas(200, 200), 11 | ctx = canvas.getContext('2d'), 12 | app = express.createServer(); 13 | 14 | 15 | app.configure(function () { 16 | 17 | app.get('/', function (req, res) { 18 | res.send('hello world'); 19 | }); 20 | 21 | app.use(express.gzip()); 22 | app.listen(3000); 23 | }); 24 | 25 | 26 | ctx.font = '30px Impact'; 27 | ctx.rotate(0.1); 28 | ctx.fillText("Awesome!", 50, 100); 29 | 30 | var te = ctx.measureText('Awesome!'); 31 | ctx.strokeStyle = 'rgba(0,0,0,0.5)'; 32 | ctx.beginPath(); 33 | ctx.lineTo(50, 102); 34 | ctx.lineTo(50 + te.width, 102); 35 | ctx.stroke(); 36 | 37 | console.log(''); -------------------------------------------------------------------------------- /tests/circular-tests.js: -------------------------------------------------------------------------------- 1 | require({ 2 | baseUrl: "./" 3 | }, 4 | ["require", "two", "funcTwo", "funcThree"], 5 | function(require, two, funcTwo, funcThree) { 6 | var args = two.doSomething(); 7 | var twoInst = new funcTwo("TWO"); 8 | doh.register( 9 | "circular", 10 | [ 11 | function circular(t) { 12 | t.is("small", args.size); 13 | t.is("redtwo", args.color); 14 | } 15 | ] 16 | ); 17 | doh.run(); 18 | 19 | doh.register( 20 | "circularFunc", 21 | [ 22 | function circularFunc(t) { 23 | t.is("TWO", twoInst.name); 24 | t.is("ONE-NESTED", twoInst.oneName()); 25 | t.is("THREE-THREE_SUFFIX", funcThree("THREE")); 26 | } 27 | ] 28 | ); 29 | doh.run(); 30 | } 31 | ); 32 | -------------------------------------------------------------------------------- /tests/commonjs/tests/modules/1.0/all.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Links for Every Test 5 | 6 | 7 |

Links for Every Test

8 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/simple-nohead.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

require.js: Simple Test, no head tag

4 |

Check console for messages

5 | 6 | 11 | 12 | 13 | 14 | 31 | -------------------------------------------------------------------------------- /tests/priority/three.js: -------------------------------------------------------------------------------- 1 | //Example layer file. 2 | 3 | require.def("alpha", 4 | ["beta", "gamma"], 5 | function (beta, gamma) { 6 | return { 7 | name: "alpha", 8 | betaName: beta.name 9 | }; 10 | } 11 | ); 12 | 13 | require.def("beta", 14 | ["gamma"], 15 | function (gamma) { 16 | return { 17 | name: "beta", 18 | gammaName: gamma.name 19 | }; 20 | } 21 | ); 22 | 23 | 24 | //Example layer file. 25 | 26 | require.def("gamma", 27 | ["theta", "epsilon"], 28 | function (theta, epsilon) { 29 | return { 30 | name: "gamma", 31 | thetaName: theta.name, 32 | epsilonName: epsilon.name 33 | }; 34 | } 35 | ); 36 | 37 | require.def("theta", 38 | function () { 39 | return { 40 | name: "theta" 41 | }; 42 | } 43 | ); 44 | 45 | require.def("epsilon", 46 | { 47 | name: "epsilon" 48 | } 49 | ); 50 | -------------------------------------------------------------------------------- /tests/browsertests/docwritenested/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Nested doc.write Test 5 | 12 | 13 | 14 |

Nested doc.write Test

15 | 16 |

This test checks how the browser treats document.write calls that are nested.

17 |
    18 |
  1. a script for one.js is written via document.write()
  2. 19 |
  3. when one.js loads it asks for two.js to be written via document.write()
  4. 20 |
  5. one.js then immediately accesses something defined in two.js
  6. 21 |
22 | 23 |

The expectation is that the access to the variable defined by two.js in one.js 24 | will fail.

25 | 26 |

Check the console for output

27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/plugins/index.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 3 | function parse(name) { 4 | var parts = name.split('?'), 5 | index = parseInt(parts[0], 10), 6 | choices = parts[1].split(':'), 7 | choice = choices[index]; 8 | 9 | return { 10 | index: index, 11 | choices: choices, 12 | choice: choice 13 | }; 14 | } 15 | 16 | define({ 17 | pluginBuilder: './indexBuilder', 18 | normalize: function (name, normalize) { 19 | var parsed = parse(name), 20 | choices = parsed.choices; 21 | 22 | //Normalize each path choice. 23 | for (i = 0; i < choices.length; i++) { 24 | choices[i] = normalize(choices[i]); 25 | } 26 | 27 | return parsed.index + '?' + choices.join(':'); 28 | }, 29 | 30 | load: function (name, req, load, config) { 31 | req([parse(name).choice], function (value) { 32 | load(value); 33 | }); 34 | } 35 | }); 36 | 37 | }()); 38 | -------------------------------------------------------------------------------- /tests/text/textOnly.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Text Test 5 | 6 | 7 | 8 | 29 | 30 | 31 |

require.js: Text Test

32 |

Test for usage of text! require plugin. 33 |

Check console for messages

34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/jquery/scripts/jquery-MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 John Resig, http://jquery.com/ 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /docs/jquery-require-sample/webapp/scripts/jquery-MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 John Resig, http://jquery.com/ 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /tests/jquery/jquery.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jQuery+RequireJS Sample Page 5 | 6 | 7 | 8 | 9 | 28 | 29 | 30 |

jQuery+RequireJS Test Page

31 |

Tests loading of jquery plugins with require.

32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/layers/allplugins-text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: allplugins-text Test 5 | 6 | 7 | 8 | 27 | 28 | 29 |

require.js: allplugins-text Test

30 |

REQUIRES a built allplugins-require.js file from the build/require/build/ location

31 |

Check console for messages

32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/jquery/jqueryDynamic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jQuery+RequireJS Sample Page 5 | 6 | 7 | 8 | 33 | 34 | 35 |

jQuery+RequireJS Test Page

36 |

Tests loading of jquery plugins with require.

37 | 38 | 39 | -------------------------------------------------------------------------------- /tests/depoverlap.js: -------------------------------------------------------------------------------- 1 | require(["require", "uno"], 2 | function (require, uno) { 3 | doh.register( 4 | "depoverlap", 5 | [ 6 | function depoverlap(t){ 7 | //First confirm there is only one script tag for each 8 | //module: 9 | var scripts = document.getElementsByTagName("script"), 10 | i, counts = {}, modName, props, something; 11 | for (var i = scripts.length - 1; i > -1; i--) { 12 | modName = scripts[i].getAttribute("data-requiremodule"); 13 | if (modName) { 14 | if (!(modName in counts)) { 15 | counts[modName] = 0; 16 | } 17 | counts[modName] += 1; 18 | } 19 | } 20 | 21 | //Now that we counted all the modules make sure count 22 | //is always one. 23 | for (prop in counts) { 24 | t.is(1, counts[prop]); 25 | } 26 | 27 | t.is("uno", uno.name); 28 | something = uno.doSomething(); 29 | t.is("dos", something.dosName); 30 | t.is("tres", something.tresName); 31 | } 32 | ] 33 | ); 34 | doh.run(); 35 | }); 36 | -------------------------------------------------------------------------------- /adapt/tests/all.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 3 | * Available via the MIT or new BSD license. 4 | * see: http://github.com/jrburke/requirejs for details 5 | */ 6 | 7 | /** 8 | * BUILD r.js IN THIS DIRECTORY FIRST BEFORE RUNNING THIS FILE 9 | * 10 | * To run in Node: 11 | * node ../r.js all.js 12 | * 13 | * To run in Rhino: 14 | * java -jar ../../build/lib/rhino/js.jar ../r.js all.js 15 | * Debug: 16 | * java -classpath ../../build/lib/rhino/js.jar org.mozilla.javascript.tools.debugger.Main ../r.js all.js 17 | */ 18 | 19 | /*jslint strict: false */ 20 | /*global require: false, doh: false */ 21 | 22 | //Special global flag used by DOH. 23 | skipDohSetup = true; 24 | 25 | require({ 26 | paths: { 27 | env: '../../build/jslib/env' 28 | } 29 | }, [ 30 | 'alpha', 31 | 'beta', 32 | '../../tests/doh/runner.js', 33 | 'env!../../tests/doh/_{env}Runner.js' 34 | ], function (alpha, beta) { 35 | 36 | doh.register('rjsTests', 37 | [ 38 | function rjsTests(t) { 39 | t.is('alpha', alpha.name); 40 | t.is('beta', beta.name); 41 | t.is('betaSubName', beta.subName); 42 | } 43 | ] 44 | ); 45 | doh.run(); 46 | 47 | //Print out the test summary. 48 | doh.run(); 49 | }); 50 | -------------------------------------------------------------------------------- /tests/plugins/indexBuilder.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | 3 | function parse(name) { 4 | var parts = name.split('?'), 5 | index = parseInt(parts[0], 10), 6 | choices = parts[1].split(':'), 7 | choice = choices[index]; 8 | 9 | return { 10 | index: index, 11 | choices: choices, 12 | choice: choice 13 | }; 14 | } 15 | 16 | define({ 17 | normalize: function (name, normalize) { 18 | var parsed = parse(name), 19 | choices = parsed.choices; 20 | 21 | //Normalize each path choice. 22 | for (i = 0; i < choices.length; i++) { 23 | choices[i] = normalize(choices[i]); 24 | } 25 | 26 | return parsed.index + '?' + choices.join(':'); 27 | }, 28 | 29 | load: function (name, req, load, config) { 30 | req([parse(name).choice], function (value) { 31 | load(value); 32 | }); 33 | }, 34 | 35 | //This is strictly not necessary (and *not* recommended), 36 | //but just doing it as a test. 37 | write: function (pluginName, moduleName, write) { 38 | var parsed = parse(moduleName); 39 | write("define('" + pluginName + "!" + moduleName + 40 | "', ['" + parsed.choice + "'], function (value) { return value;});\n"); 41 | } 42 | }); 43 | 44 | }()); 45 | -------------------------------------------------------------------------------- /tests/simple.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Simple Test 5 | 6 | 7 | 8 | 9 | 10 | 31 | 32 | 33 |

require.js: Simple Test

34 |

Check console for messages

35 | 36 | 37 | -------------------------------------------------------------------------------- /adapt/dist.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 3 | * Available via the MIT or new BSD license. 4 | * see: http://github.com/jrburke/requirejs for details 5 | */ 6 | 7 | /* 8 | * This script will create the final r.js file used in node projects to use 9 | * RequireJS. 10 | * 11 | * This file uses Node to run: 12 | * node dist.js 13 | */ 14 | 15 | /*jslint strict: false */ 16 | /*global require: false */ 17 | 18 | /** 19 | * Escapes a string so it is safe as a JS string 20 | * Taken from Dojo's buildUtil.jsEscape 21 | * @param {String} str 22 | * @returns {String} 23 | */ 24 | function jsEscape(str) { 25 | return ('"' + str.replace(/(["\\])/g, '\\$1') + '"' 26 | ).replace(/[\f]/g, '\\f' 27 | ).replace(/[\b]/g, '\\b' 28 | ).replace(/[\n]/g, '\\n' 29 | ).replace(/[\t]/g, '\\t' 30 | ).replace(/[\r]/g, '\\r'); // string 31 | } 32 | 33 | var fs = require('fs'), 34 | contents = fs.readFileSync('../bin/x.js', 'utf8'), 35 | loadRegExp = /readFile\(requireBuildPath \+ '([\w\/\.]+)'\)/g; 36 | 37 | //Inline file contents 38 | contents = contents.replace(loadRegExp, function (match, fileName) { 39 | return jsEscape(fs.readFileSync('../' + fileName, 'utf8')); 40 | }); 41 | 42 | //Switch the behavior to "inlined mode" 43 | contents = contents.replace(/useRequireBuildPath \= true/, 'useRequireBuildPath = false'); 44 | 45 | fs.writeFileSync('r.js', contents, 'utf8'); 46 | -------------------------------------------------------------------------------- /tests/uniques/uniques.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Unique Dependency Test 5 | 6 | 7 | 8 | 33 | 34 | 35 |

require.js: Unique Dependency Test

36 |

Make sure if a dependency is listed more than once code still operates correctly.

37 |

Check console for messages

38 | 39 | 40 | -------------------------------------------------------------------------------- /dist/README.md: -------------------------------------------------------------------------------- 1 | # RequireJS dist 2 | 3 | This directory contains the tools that are used to build distributions of RequireJS and its web site. 4 | 5 | When doing a release, do the following: 6 | 7 | * Update files to the new version number: 8 | * require.js 9 | * README.md 10 | * docs/download.md: check for nested paths too, add new release section 11 | * pre.html 12 | * post.html 13 | * Update integrated jQuery versioned-builds: 14 | * Save a built jQuery to build/jquery 15 | * Make sure to apply changes from previous converted jQuery to new one via examining diffs. 16 | * Be sure to add /** * @license to the jQuery license block so that it survives google closure compiler. 17 | * Update build/jquery/require-jquery.build.js and requireplugins-jquery.build.js to reference the new version of jQuery. 18 | * Update dist/dist-build.sh to reference the right jQuery file. 19 | * Commit/push changes 20 | 21 | * Tag the tree: 22 | * git tag -am "Release 0.0.0" 0.0.0 23 | * git push --tags 24 | 25 | Now pull down the tagged version to do a distribution: 26 | 27 | * git clone git://github.com/jrburke/requirejs.git requirejs-dist 28 | * cd requirejs-dist 29 | * git checkout 0.0.0 30 | * cd dist 31 | 32 | Run the distribution tasks. 33 | 34 | To generate the web site: 35 | 36 | * java -jar ../build/lib/rhino/js.jar dist-site.js 37 | 38 | To generate a build 39 | 40 | * ./dist-build.sh 0.0.0 41 | 42 | When done, reset versions to: 43 | 44 | * 0.0.0+ in require.js 45 | * X.X.X in pre.html 46 | -------------------------------------------------------------------------------- /tests/browsertests/common.js: -------------------------------------------------------------------------------- 1 | //Common functions for the test files. *MUST* be included after require.js. 2 | 3 | (function() { 4 | var messages = []; 5 | var bodyReady = false; 6 | 7 | window.log = function(message) { 8 | if (typeof console != "undefined" && console.log) { 9 | console.log(message); 10 | } else { 11 | messages.push(message); 12 | if (bodyReady) { 13 | dumpLogs(); 14 | } 15 | } 16 | } 17 | 18 | function dumpLogs() { 19 | bodyReady = true; 20 | if (messages.length) { 21 | var body = document.getElementsByTagName("body")[0]; 22 | if (body) { 23 | for (var i = 0; i < messages.length; i++) { 24 | var div = document.createElement("div"); 25 | div.innerHTML = messages[i]; 26 | body.appendChild(div); 27 | } 28 | } 29 | messages =[]; 30 | } 31 | } 32 | 33 | //Wait for document ready before dumping results. 34 | //Will not work with Firefox 3.5 or earlier, but just 35 | //be sure to use Firebug or something that defines console.log 36 | var tries = 0; 37 | function checkDom() { 38 | if (document.readyState === "complete") { 39 | dumpLogs(); 40 | } else if (tries < 5) { 41 | tries += 1; 42 | setTimeout(checkDom, 1000); 43 | } 44 | } 45 | 46 | checkDom(); 47 | })(); -------------------------------------------------------------------------------- /tests/jquery/jqueryDynamic2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | jQuery+RequireJS Sample Page 5 | 6 | 7 | 8 | 40 | 41 | 42 |

jQuery+RequireJS Test Page

43 |

Tests loading of jquery plugins with require.

44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/config.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Config Test 5 | 6 | 7 | 36 | 37 | 38 | 39 |

require.js: Config Test

40 |

Tests require being defined as an object with init and ready configuration.

41 |

Check console for messages.

42 | 43 | 44 | -------------------------------------------------------------------------------- /tests/priority/priority.js: -------------------------------------------------------------------------------- 1 | var master = new doh.Deferred(), 2 | count = 0; 3 | doh.register( 4 | "priority", 5 | [ 6 | { 7 | name: "priority", 8 | timeout: 5000, 9 | runTest: function () { 10 | return master; 11 | } 12 | } 13 | ] 14 | ); 15 | doh.run(); 16 | 17 | require( 18 | { 19 | baseUrl: "./", 20 | priority: ["one", "two"] 21 | }, 22 | ["alpha", "beta", "gamma", "epsilon"], 23 | function (alpha, beta, gamma, epsilon) { 24 | count += 1; 25 | 26 | //Make sure callback is only called once. 27 | doh.is(1, count); 28 | 29 | doh.is("alpha", alpha.name); 30 | doh.is("beta", alpha.betaName); 31 | doh.is("beta", beta.name); 32 | doh.is("gamma", beta.gammaName); 33 | doh.is("gamma", gamma.name); 34 | doh.is("theta", gamma.thetaName); 35 | doh.is("epsilon", gamma.epsilonName); 36 | doh.is("epsilon", epsilon.name); 37 | } 38 | ); 39 | 40 | function verifyFunc() { 41 | var regExp = /alpha|beta|gamma|theta/, 42 | i, 43 | scripts = document.getElementsByTagName("script"); 44 | for (i = scripts.length - 1; i > -1; i--) { 45 | doh.f(regExp.test(scripts[i].src)); 46 | } 47 | master.callback(true); 48 | } 49 | 50 | //Account for requiring this test with a version of require.js that 51 | //does not have require.ready built in. 52 | if (require.ready) { 53 | require.ready(verifyFunc); 54 | } else { 55 | setTimeout(verifyFunc, 3000); 56 | } 57 | -------------------------------------------------------------------------------- /dist/Markdown-License.text: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004, John Gruber 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name "Markdown" nor the names of its contributors may 17 | be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | This software is provided by the copyright holders and contributors "as 21 | is" and any express or implied warranties, including, but not limited 22 | to, the implied warranties of merchantability and fitness for a 23 | particular purpose are disclaimed. In no event shall the copyright owner 24 | or contributors be liable for any direct, indirect, incidental, special, 25 | exemplary, or consequential damages (including, but not limited to, 26 | procurement of substitute goods or services; loss of use, data, or 27 | profits; or business interruption) however caused and on any theory of 28 | liability, whether in contract, strict liability, or tort (including 29 | negligence or otherwise) arising in any way out of the use of this 30 | software, even if advised of the possibility of such damage. 31 | -------------------------------------------------------------------------------- /tests/browsertests/functionToString.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Function toString() Test 5 | 14 | 15 | 37 | 38 | 39 |

Function toString() Test

40 |

This test shows how a function is converted to a string value via the Function.prototype.toString() method. 41 | See the source of this file to see the source for of the function that is converted to a string.

42 | 43 |
44 | 45 | 46 | 47 |
48 | 49 | 50 | -------------------------------------------------------------------------------- /tests/browsertests/appendbeforeload/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Script appendChild Before Page Load Test 5 | 27 | 28 | 29 |

Script Blocking Before Page Load Test

30 |

This test requires PHP. Rename one.dphpd in this directory to 31 | one.php before trying this test.

32 | 33 |

This test looks at scripts added via appendChild before the page loads. 34 | Do the scripts execute in the order added to the DOM or the order in which 35 | they are received from the network?

36 | 37 |

Normally after page load, IE and WebKit 38 | will evaluate scripts in network receive order, not in DOM order. This test 39 | is checking the behavior before page load.

40 | 41 |

Expected results:
42 | ONE
43 | TWO
44 |

45 | 46 |

>Actual results: see browser console. IE and WebKit will execute scripts 47 | in network receive order, not in DOM order.

48 | 49 | 50 | -------------------------------------------------------------------------------- /tests/text/text.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Text Test 5 | 6 | 7 | 8 | 34 | 35 | 36 |

require.js: Text Test

37 |

Test for usage of text! require plugin. 38 |

Check console for messages

39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/order/order.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Order Plugin Test 5 | 6 | 7 | 8 | 38 | 39 | 40 |

require.js: Order Plugin Test

41 |

To properly test, clear cache in the browser.

42 |

Check console for messages

43 | 44 | 45 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # RequireJS Testing 2 | 3 | This is a list of things to test before doing a RequireJS release. 4 | 5 | ## Items in tests directory 6 | 7 | First build allplugins-require.js in build/require, since one test relies on an up-to-date version. 8 | 9 | * All browsers: tests/doh/runner.html?testUrl=../all in all the browsers 10 | * Node: node all-server.js 11 | * Rhino: java -jar ../build/lib/rhino/js.jar all-server.js 12 | * Optional, only do on major refactors: tests/commonjs, run each file in browser. 13 | 14 | ## Node testing 15 | 16 | Go to adapt/ and run the following: 17 | 18 | * node dist.js 19 | * cd tests 20 | * node ../r.js all.js 21 | * java -jar ../../build/lib/rhino/js.jar ../r.js all.js 22 | * cd node 23 | * node ../../r.js index.js 24 | * Try r.js a larger node project if available. 25 | 26 | For this test, use nave, and do the npm installs listed in the JS file: 27 | 28 | * node r.js canvasTest.js 29 | 30 | Do these tests for each version of Node to support. 31 | 32 | Be sure to update the r.js in the build directory. 33 | 34 | ## Build testing in build/tests 35 | 36 | To run automated tests: 37 | 38 | * ../../bin/x all.js 39 | * ../../bin/xj all.js 40 | 41 | Try manual testing: 42 | 43 | * ../build.sh indexBuilder.build.js - confirm plugin write calls are done. 44 | * ../build.sh text.build.js - confirm plugin write calls are done. 45 | * ../build.sh i18n.build.js - confirm plugin required the nls/en-us-surfer/colors module. 46 | * ../build.sh order.build.js - confirm one, two, three are in order. 47 | * ../build.sh hasTestModule.build.js - confirm has replacements have been done. 48 | 49 | # Sample jQuery project 50 | 51 | Test the sample jQuery project, complete with running the optimizer, testing the output. 52 | -------------------------------------------------------------------------------- /tests/workers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Web Workers Test 5 | 6 | 7 | 51 | 52 | 53 |

require.js: Web Workers Test

54 |

Check console for messages

55 | 56 | 57 | -------------------------------------------------------------------------------- /tests/i18n/common.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Common I18N Test 5 | 6 | 7 | 8 | 46 | 47 | 48 |

Common i18n bundle test

49 |

This page tests for an i18n plugin resource that is specified by two different modules.

50 | 51 | 52 | -------------------------------------------------------------------------------- /docs/dojo.html: -------------------------------------------------------------------------------- 1 |
2 |

How to use RequireJS with Dojo

3 | 8 |

As of Dojo 1.6, Dojo Core and Dijit have preliminary support for loading its modules with a loader like RequireJS that understands the AMD API proposal. Only a few of the Dojox modules have been converted to allow AMD loading.

9 | 10 |

AMD loading is still considered experimental in Dojo 1.6, and it only works by using a source distribution, not one of the built distributions.

11 |
12 | 13 |
14 |

15 | Get the template 16 | § 1 17 |

18 | 19 |

Ben Hockey has set up a nice template project for getting started with Dojo+RequireJS. The directions are fairly straightforward. Some notes:

20 | 28 |
29 | -------------------------------------------------------------------------------- /tests/jsonp/jsonp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: JSONP Test 5 | 6 | 7 | 8 | 38 | 39 | 40 |

require.js: JSONP Test

41 |

Test for usage of a JSONP URL as a dependency.

42 | REQUIRES access to internet/Google to run the test. Otherwise it will fail. 43 |

Check console for messages

44 | 45 | 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RequireJS 2 | 3 | RequireJS loads plain JavaScript files as well as more defined modules. It is optimized for in-browser use, including in [a Web Worker](requirejs/tree/master/docs/api.md#webworker), but it can be used in other JavaScript environments, like Rhino and [Node](requirejs/tree/master/docs/node.md). It implements the [Asynchronous Module](http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition) API. 4 | 5 | RequireJS uses plain script tags to load modules/files, so it should allow for easy debugging. It can be used [simply to load existing JavaScript files](requirejs/tree/master/docs/api.md#jsfiles), so you can add it to your existing project without having to re-write your JavaScript files. 6 | 7 | RequireJS includes [an optimization tool](requirejs/tree/master/docs/optimization.md) you can run as part of your packaging steps for deploying your code. The optimization tool can combine and minify your JavaScript files to allow for better performance. 8 | 9 | If the JavaScript file defines a JavaScript module via [define()](requirejs/tree/master/docs/api.md#define), then there are other benefits RequireJS can offer: [better CommonJS support](requirejs/tree/master/docs/commonjs.md) and [loading multiple versions](requirejs/tree/master/docs/api.md#multiversion) of a module in a page. RequireJS also has a plugin system that supports features like [i18n string bundles](requirejs/tree/master/docs/api.md#i18n), and [text file dependencies](requirejs/tree/master/docs/api.md#text). 10 | 11 | RequireJS does not have any dependencies on a JavaScript framework. It is dual-licensed -- new BSD or MIT. 12 | 13 | The standard require.js file is around 5KB when minified via Closure Compiler and gzipped. 14 | 15 | RequireJS works in IE 6+, Firefox 2+, Safari 3.2+, Chrome 3+, and Opera 10+. 16 | 17 | Latest Release: [0.22.0](http://requirejs.org/docs/download.html) 18 | -------------------------------------------------------------------------------- /tests/paths/paths.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: paths Test 5 | 6 | 7 | 8 | 49 | 50 | 51 |

require.js: paths Test

52 |

Check console for messages

53 | 54 | 55 | -------------------------------------------------------------------------------- /docs/jquery-require-sample/dist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script preps the jquery-require-sample for distribution. 4 | 5 | # Make the dist directory 6 | rm -rf dist 7 | mkdir dist 8 | mkdir dist/jquery-require-sample 9 | cd dist/jquery-require-sample 10 | 11 | # Copy the sample files. 12 | cp -r ../../webapp ./webapp 13 | 14 | # Do a build of requirejs with jquery 15 | cd ../../../../build/jquery 16 | ../build.sh require-jquery.build.js 17 | cp dist/require-jquery.js ../../docs/jquery-require-sample/dist/jquery-require-sample/webapp/scripts/require-jquery.js 18 | rm -rf dist/ 19 | cd ../../docs/jquery-require-sample/dist/jquery-require-sample 20 | 21 | # Copy over the RequireJS plugins. 22 | cp -r ../../../../require webapp/scripts 23 | 24 | # Copy over the build system for requirejs and basic require files, used by the build. 25 | mkdir requirejs 26 | mkdir requirejs/adapt 27 | mkdir requirejs/build 28 | mkdir requirejs/build/convert 29 | mkdir requirejs/build/convert/node 30 | cp -r ../../../../bin requirejs/bin 31 | cp -r ../../../../build/jslib requirejs/build/jslib 32 | cp -r ../../../../build/lib requirejs/build/lib 33 | cp ../../../../build/example.build.js requirejs/build/example.build.js 34 | cp ../../../../build/build.bat requirejs/build/build.bat 35 | cp ../../../../build/build.js requirejs/build/build.js 36 | cp ../../../../build/build.sh requirejs/build/build.sh 37 | cp ../../../../build/buildj.bat requirejs/build/buildj.bat 38 | cp ../../../../build/buildj.sh requirejs/build/buildj.sh 39 | cp ../../../../adapt/r.js requirejs/adapt/r.js 40 | cp ../../../../adapt/node.js requirejs/adapt/node.js 41 | cp ../../../../adapt/rhino.js requirejs/adapt/rhino.js 42 | 43 | cp ../../../../require.js requirejs/ 44 | cp -r ../../../../require requirejs/require 45 | cp ../../../../LICENSE requirejs/LICENSE 46 | 47 | # Start the build. 48 | cd webapp/scripts 49 | ../../requirejs/build/build.sh app.build.js 50 | cd ../../.. 51 | 52 | # Mac weirdness 53 | find . -name .DS_Store -exec rm {} \; 54 | 55 | # Package it. 56 | zip -r jquery-require-sample.zip jquery-require-sample/* 57 | -------------------------------------------------------------------------------- /tests/anon/anon-tests.js: -------------------------------------------------------------------------------- 1 | require({ 2 | baseUrl: require.isBrowser ? "./" : "./anon/", 3 | paths: { 4 | require: "../../require" 5 | } 6 | }, 7 | ["require", "magenta", "red", "blue", "green", "yellow", "a", "c"], 8 | function(require, magenta, red, blue, green, yellow, a, c) { 9 | 10 | doh.register( 11 | "anonSimple", 12 | [ 13 | function colors(t){ 14 | t.is("redblue", magenta.name); 15 | t.is((require.isBrowser ? "foo.html" : "anon/foo.html"), magenta.path); 16 | t.is("red", red.name); 17 | t.is("blue", blue.name); 18 | t.is("green", green.name); 19 | t.is("yellow", yellow.name); 20 | t.is("a", a.name); 21 | t.is("sub/b", a.bName); 22 | t.is("c", c.name); 23 | t.is("a", c.aName); 24 | } 25 | ] 26 | ); 27 | doh.run(); 28 | 29 | //Also try a require call after initial page 30 | //load that uses already loaded modules, 31 | //to be sure the require callback is called. 32 | var onReady = function () { 33 | require(["blue", "red", "magenta"], function (blue, red) { 34 | doh.register( 35 | "anonSimpleCached", 36 | [ 37 | function colorsCached(t){ 38 | t.is("red", red.name); 39 | t.is("blue", blue.name); 40 | t.is("redblue", magenta.name); 41 | t.is("hello world", magenta.message); 42 | } 43 | ] 44 | ); 45 | doh.run(); 46 | }); 47 | } 48 | if (require.isBrowser) { 49 | require.ready(function () { 50 | setTimeout(onReady, 100); 51 | }) 52 | } else { 53 | onReady(); 54 | } 55 | } 56 | ); 57 | -------------------------------------------------------------------------------- /tests/all-server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 3 | * Available via the MIT or new BSD license. 4 | * see: http://github.com/jrburke/requirejs for details 5 | */ 6 | 7 | /** 8 | * Run the tests in Node with this command: 9 | * node all-server.js 10 | * 11 | * Run the tests in Rhino with this command: 12 | * java -jar ../build/lib/rhino/js.jar all-server.js 13 | * 14 | * To run with debugger: 15 | * java -classpath ../build/lib/rhino/js.jar org.mozilla.javascript.tools.debugger.Main all-server.js 16 | */ 17 | 18 | /*jslint strict: false, evil: true */ 19 | /*global Packages: false, process: false, require: true, doh: false */ 20 | 21 | //A hack to doh to avoid dojo setup stuff in doh/runner.js 22 | var skipDohSetup = true, 23 | fs, load, env, exec; 24 | 25 | (function () { 26 | if (typeof Packages !== 'undefined') { 27 | env = 'rhino'; 28 | exec = function (text, fileName) { 29 | eval(text); 30 | }; 31 | } else if (typeof process !== 'undefined') { 32 | env = 'node'; 33 | 34 | //Get the fs module via Node's require before it 35 | //gets replaced. Used in require/node.js 36 | fs = require('fs'); 37 | load = function (path) { 38 | return process.compile(fs.readFileSync(path, 'utf8'), path); 39 | }; 40 | exec = process.compile; 41 | } 42 | 43 | if (env === 'node') { 44 | this.nodeRequire = require; 45 | //Remove the require definition so require.js can create a new one. 46 | require = null; 47 | } 48 | }()); 49 | 50 | //Load require with rhino extension 51 | load("../require.js"); 52 | load("../adapt/" + env + ".js"); 53 | 54 | 55 | //Load the tests. 56 | load("doh/runner.js"); 57 | load('doh/_' + env + 'Runner.js'); 58 | load("simple-tests.js"); 59 | load("circular-tests.js"); 60 | load("relative/relative-tests.js"); 61 | load("exports/exports-tests.js"); 62 | load("anon/anon-tests.js"); 63 | load("packages/packages-tests.js"); 64 | load("plugins/sync-tests.js"); 65 | 66 | //Print out the final report 67 | doh.run(); 68 | -------------------------------------------------------------------------------- /tests/i18n/i18n.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: I18N Test 5 | 6 | 7 | 8 | 55 | 56 | 57 |

i18n bundle test

58 |

This page tests the i18n bundling in require.js. You can change the locale to use by passing locale= or bundle=

59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /tests/priority/priorityWithDeps/priorityWithDeps.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Priority With Deps Test 5 | 6 | 7 | 8 | 9 | 10 | 11 | 44 | 45 | 46 | 48 | 49 | 50 | 51 |

require.js: Priority With Deps Test

52 |

Tests a priority with a callback, and with the priority item needing 53 | to still load some modules, not all of the modules are included in the 54 | priority build layer.

55 |

Check console for messages

56 | 57 |

QUnit Test Suite

58 |

59 |
60 |

61 |
    62 |
    test markup
    63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /tests/priority/priorityOrder.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Priority order! Test 5 | 6 | 7 | 8 | 67 | 68 | 69 |

    require.js: Priority order! Test

    70 |

    Check console for messages

    71 | 72 | 73 | -------------------------------------------------------------------------------- /tests/layers/layers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Layers Test 5 | 6 | 7 | 8 | 62 | 63 | 64 |

    require.js: Layers Test

    65 |

    Check console for messages

    66 | 67 | 68 | -------------------------------------------------------------------------------- /tests/simple-badbase.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | require.js: Simple Bad Base Test 4 | 5 | 6 | 7 | 8 | 28 | 49 | 50 | 51 |

    require.js: Simple Test

    52 |

    You may need to change the IP address used for this test for it to work correctly.

    53 |

    Check console for messages

    54 | 55 | 56 | -------------------------------------------------------------------------------- /tests/priority/prioritySingleCall.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Priority Single Call Test 5 | 6 | 7 | 8 | 65 | 66 | 67 |

    require.js: Priority Single Call Test

    68 |

    Makes sure the callback is only called once when all dependencies are 69 | loaded in one priority bundle.

    70 |

    Check console for messages

    71 | 72 | 73 | -------------------------------------------------------------------------------- /tests/urlfetch/urlfetch.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: urlFetch Mapping Test 5 | 6 | 7 | 8 | 57 | 58 | 59 |

    require.js: urlFetch Mapping Test

    60 |

    Make sure that multiple modules mapped to the same URL only get 61 | the URL fetched once.

    62 |

    Check console for messages

    63 | 64 | 65 | -------------------------------------------------------------------------------- /adapt/rhino.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license RequireJS rhino Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 3 | * Available via the MIT or new BSD license. 4 | * see: http://github.com/jrburke/requirejs for details 5 | */ 6 | 7 | /*jslint strict: false */ 8 | /*global require: false, java: false, load: false */ 9 | 10 | (function () { 11 | 12 | require.load = function (context, moduleName, url) { 13 | //isDone is used by require.ready() 14 | require.s.isDone = false; 15 | 16 | //Indicate a the module is in process of loading. 17 | context.loaded[moduleName] = false; 18 | context.scriptCount += 1; 19 | 20 | load(url); 21 | 22 | //Support anonymous modules. 23 | context.completeLoad(moduleName); 24 | }; 25 | 26 | //Adapter to get text plugin to work. 27 | require.fetchText = function (url, callback) { 28 | var encoding = "utf-8", 29 | file = new java.io.File(url), 30 | lineSeparator = java.lang.System.getProperty("line.separator"), 31 | input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)), 32 | stringBuffer, line, 33 | content = ''; 34 | try { 35 | stringBuffer = new java.lang.StringBuffer(); 36 | line = input.readLine(); 37 | 38 | // Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324 39 | // http://www.unicode.org/faq/utf_bom.html 40 | 41 | // Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK: 42 | // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058 43 | if (line && line.length() && line.charAt(0) === 0xfeff) { 44 | // Eat the BOM, since we've already found the encoding on this file, 45 | // and we plan to concatenating this buffer with others; the BOM should 46 | // only appear at the top of a file. 47 | line = line.substring(1); 48 | } 49 | 50 | stringBuffer.append(line); 51 | 52 | while ((line = input.readLine()) !== null) { 53 | stringBuffer.append(lineSeparator); 54 | stringBuffer.append(line); 55 | } 56 | //Make sure we return a JavaScript string and not a Java string. 57 | content = String(stringBuffer.toString()); //String 58 | } finally { 59 | input.close(); 60 | } 61 | callback(content); 62 | }; 63 | 64 | }()); -------------------------------------------------------------------------------- /dist/fonts/PT-Sans/Paratype PT Sans Free Font License.txt: -------------------------------------------------------------------------------- 1 | Copyright © 2009 ParaType Ltd. 2 | with Reserved Names "PT Sans" and "ParaType". 3 | 4 | FONT LICENSE 5 | 6 | PERMISSION & CONDITIONS 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of the font software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the font software, subject to the following conditions: 8 | 9 | 1) Neither the font software nor any of its individual components, in original or modified versions, may be sold by itself. 10 | 11 | 2) Original or modified versions of the font software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. 12 | 13 | 3) No modified version of the font software may use the Reserved Name(s) or combinations of Reserved Names with other words unless explicit written permission is granted by the ParaType. This restriction only applies to the primary font name as presented to the users. 14 | 15 | 4) The name of ParaType or the author(s) of the font software shall not be used to promote, endorse or advertise any modified version, except to acknowledge the contribution(s) of ParaType and the author(s) or with explicit written permission of ParaType. 16 | 17 | 5) The font software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. 18 | 19 | TERMINATION & TERRITORY 20 | This license has no limits on time and territory, but it becomes null and void if any of the above conditions are not met. 21 | 22 | DISCLAIMER 23 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL PARATYPE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. 24 | 25 | ParaType Ltd 26 | http://www.paratype.ru -------------------------------------------------------------------------------- /tests/multiversion.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | require.js: Multiversion Test 5 | 6 | 7 | 8 | 85 | 86 | 87 |

    require.js: Multiversion Test

    88 | 89 |

    Check console for messages.

    90 | 91 |

    This test loads two different versions of a module by using the 92 | "context" settings for require.

    93 | 94 |

    It also tests loading a plain js file.

    95 | 96 | 97 | -------------------------------------------------------------------------------- /tests/browsertests/onerror/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Script onerror Test 5 | 6 | 59 | 60 | 61 |

    Script onerror Test

    62 | 63 |

    Test different script loading scenarios to see if an error callback is 64 | given on the script tag.

    65 | 66 |

    Press the button and check console for output. There should be a log 67 | message for each button.

    68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /dist/dist-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #@license RequireJS Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 4 | #Available via the MIT or new BSD license. 5 | #see: http://github.com/jrburke/requirejs for details 6 | 7 | #version should be something like 0.9.0beta or 0.9.0 8 | version=$1 9 | if [ -z $version ]; then 10 | echo "Please pass in a version number" 11 | exit 1 12 | fi 13 | 14 | myDir=`cd \`dirname "$0"\`; pwd` 15 | 16 | jqueryName=jquery-1.4.4.js 17 | 18 | # Setup a build directory 19 | rm -rf ../../requirejs-build 20 | mkdir ../../requirejs-build 21 | cp -r ../ ../../requirejs-build/requirejs-$version 22 | 23 | # Zip up the full source 24 | cd ../../requirejs-build 25 | zip -r requirejs-$version.zip requirejs-$version/* 26 | 27 | # Create the version output dir 28 | mkdir $version 29 | mkdir $version/minified 30 | mkdir $version/comments 31 | mv requirejs-$version.zip $version 32 | 33 | # Build requirejs 34 | cd requirejs-$version/build/require 35 | ./build.sh 36 | cd build 37 | sed -i '' 's/\/\*jslint/\/\*jslint white\: false\,/' require.js 38 | sed -i '' 's/\/\*jslint/\/\*jslint white\: false\,/' allplugins-require.js 39 | cp require.js ../../../../$version/comments/require.js 40 | cp allplugins-require.js ../../../../$version/comments/allplugins-require.js 41 | 42 | 43 | # Build jquery options 44 | cd ../../jquery 45 | ../build.sh require-jquery.build.js 46 | ../build.sh requireplugins-jquery.build.js 47 | 48 | sed -i '' 's/\/\*jslint/\/\*jslint white\: false\,/' dist/require-jquery.js 49 | sed -i '' 's/\/\*jslint/\/\*jslint white\: false\,/' dist/requireplugins-jquery.js 50 | mv dist/require-jquery.js ../../../$version/comments/require-$jqueryName 51 | mv dist/requireplugins-jquery.js ../../../$version/comments/requireplugins-$jqueryName 52 | 53 | # Build the sample jQuery project 54 | cd ../../ 55 | cd docs/jquery-require-sample 56 | ./dist.sh 57 | cp dist/jquery-require-sample.zip ../../../$version 58 | 59 | # Create node integration layer 60 | cd ../../ 61 | cd adapt 62 | node dist.js 63 | mkdir ../../$version/node 64 | cp r.js ../../$version/ 65 | cp tests/node/index.js ../../$version/node 66 | cd ../ 67 | 68 | # Minify any of the browser-based JS files 69 | cd ../$version/comments 70 | java -jar ../../requirejs-$version/build/lib/closure/compiler.jar --js require.js --js_output_file ../minified/require.js 71 | java -jar ../../requirejs-$version/build/lib/closure/compiler.jar --js allplugins-require.js --js_output_file ../minified/allplugins-require.js 72 | java -jar ../../requirejs-$version/build/lib/closure/compiler.jar --js require-$jqueryName --js_output_file ../minified/require-$jqueryName 73 | java -jar ../../requirejs-$version/build/lib/closure/compiler.jar --js requireplugins-$jqueryName --js_output_file ../minified/requireplugins-$jqueryName 74 | 75 | cd ../../../ 76 | -------------------------------------------------------------------------------- /adapt/node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license RequireJS node Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. 3 | * Available via the MIT or new BSD license. 4 | * see: http://github.com/jrburke/requirejs for details 5 | */ 6 | 7 | /*jslint regexp: false, strict: false */ 8 | /*global require: false, define: false, nodeRequire: true, process: false */ 9 | 10 | /** 11 | * This adapter assumes that x.js has loaded it and set up 12 | * some variables. This adapter just allows limited RequireJS 13 | * usage from within the requirejs directory. The general 14 | * node adapater is r.js. 15 | */ 16 | (function () { 17 | var req = nodeRequire, 18 | fs = req('fs'), 19 | path = req('path'), 20 | vm = req('vm'); 21 | 22 | //Clear out the global set by x.js 23 | nodeRequire = null; 24 | 25 | //Make nodeRequire available off of require, to allow a script to 26 | //add things to its require.paths for example. 27 | require.nodeRequire = req; 28 | 29 | //Supply an implementation that allows synchronous get of a module. 30 | require.get = function (context, moduleName, relModuleMap) { 31 | if (moduleName === "require" || moduleName === "exports" || moduleName === "module") { 32 | require.onError(new Error("Explicit require of " + moduleName + " is not allowed.")); 33 | } 34 | 35 | var ret, 36 | moduleMap = context.makeModuleMap(moduleName, relModuleMap); 37 | 38 | //Normalize module name, if it contains . or .. 39 | moduleName = moduleMap.fullName; 40 | 41 | if (moduleName in context.defined) { 42 | ret = context.defined[moduleName]; 43 | } else { 44 | if (ret === undefined) { 45 | //Try to dynamically fetch it. 46 | require.load(context, moduleName, moduleMap.url); 47 | //The above call is sync, so can do the next thing safely. 48 | ret = context.defined[moduleName]; 49 | } 50 | } 51 | 52 | return ret; 53 | }; 54 | 55 | require.load = function (context, moduleName, url) { 56 | var contents; 57 | 58 | //isDone is used by require.ready() 59 | require.s.isDone = false; 60 | 61 | //Indicate a the module is in process of loading. 62 | context.loaded[moduleName] = false; 63 | context.scriptCount += 1; 64 | 65 | if (path.existsSync(url)) { 66 | contents = fs.readFileSync(url, 'utf8'); 67 | vm.runInThisContext(contents, url); 68 | } else { 69 | define(function () { 70 | return req(moduleName); 71 | }); 72 | } 73 | 74 | //Support anonymous modules. 75 | context.completeLoad(moduleName); 76 | }; 77 | 78 | //Adapter to get text plugin to work. 79 | require.fetchText = function (url, callback) { 80 | callback(fs.readFileSync(url, 'utf8')); 81 | }; 82 | 83 | }()); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | RequireJS is released under two licenses: new BSD, and MIT. You may pick the 2 | license that best suits your development needs. The text of both licenses are 3 | provided below. 4 | 5 | 6 | The "New" BSD License: 7 | ---------------------- 8 | 9 | Copyright (c) 2010-2011, The Dojo Foundation 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this 16 | list of conditions and the following disclaimer. 17 | * Redistributions in binary form must reproduce the above copyright notice, 18 | this list of conditions and the following disclaimer in the documentation 19 | and/or other materials provided with the distribution. 20 | * Neither the name of the Dojo Foundation nor the names of its contributors 21 | may be used to endorse or promote products derived from this software 22 | without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 25 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 28 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | 37 | MIT License 38 | ----------- 39 | 40 | Copyright (c) 2010-2011, The Dojo Foundation 41 | 42 | Permission is hereby granted, free of charge, to any person obtaining a copy 43 | of this software and associated documentation files (the "Software"), to deal 44 | in the Software without restriction, including without limitation the rights 45 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 46 | copies of the Software, and to permit persons to whom the Software is 47 | furnished to do so, subject to the following conditions: 48 | 49 | The above copyright notice and this permission notice shall be included in 50 | all copies or substantial portions of the Software. 51 | 52 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 53 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 54 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 55 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 56 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 57 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 58 | THE SOFTWARE. 59 | -------------------------------------------------------------------------------- /tests/all.js: -------------------------------------------------------------------------------- 1 | //PS3 does not have a usable Function.prototype.toString, 2 | //so avoid those tests. 3 | var hasToString = (function () { 4 | var test = 'hello world'; 5 | }).toString().indexOf('hello world') !== -1; 6 | 7 | doh.registerUrl("simple", "../simple.html"); 8 | 9 | //PS3 does not like this test 10 | doh.registerUrl("baseUrl", "../baseUrl.html"); 11 | 12 | doh.registerUrl("config", "../config.html"); 13 | doh.registerUrl("dataMain", "../dataMain.html"); 14 | 15 | if (hasToString) { 16 | doh.registerUrl("anonSimple", "../anon/anonSimple.html"); 17 | doh.registerUrl("packages", "../packages/packages.html"); 18 | } 19 | 20 | doh.registerUrl("simple-nohead", "../simple-nohead.html"); 21 | 22 | //Only do the base test if the urls work out. 23 | if (location.href.indexOf('http://127.0.0.1/requirejs/') === 0) { 24 | doh.registerUrl("simple-badbase", "../simple-badbase.html"); 25 | } 26 | 27 | 28 | doh.registerUrl("circular", "../circular.html"); 29 | doh.registerUrl("depoverlap", "../depoverlap.html"); 30 | doh.registerUrl("urlfetch", "../urlfetch/urlfetch.html"); 31 | doh.registerUrl("uniques", "../uniques/uniques.html"); 32 | doh.registerUrl("multiversion", "../multiversion.html", 10000); 33 | doh.registerUrl("jquery", "../jquery/jquery.html"); 34 | 35 | //Next three tests fail in PS3 36 | doh.registerUrl("jqueryDynamic", "../jquery/jqueryDynamic.html"); 37 | doh.registerUrl("jqueryDynamic2", "../jquery/jqueryDynamic2.html"); 38 | doh.registerUrl("i18nlocaleunknown", "../i18n/i18n.html?bundle=i18n!nls/fr-fr/colors"); 39 | 40 | doh.registerUrl("i18n", "../i18n/i18n.html"); 41 | //Fail in PS3 42 | doh.registerUrl("i18nlocale", "../i18n/i18n.html?locale=en-us-surfer"); 43 | //Fail in PS3 44 | doh.registerUrl("i18nbundle", "../i18n/i18n.html?bundle=i18n!nls/en-us-surfer/colors"); 45 | 46 | //Probably fail in PS3 47 | doh.registerUrl("i18ncommon", "../i18n/common.html"); 48 | doh.registerUrl("i18ncommonlocale", "../i18n/common.html?locale=en-us-surfer"); 49 | 50 | 51 | doh.registerUrl("paths", "../paths/paths.html"); 52 | 53 | doh.registerUrl("layers", "../layers/layers.html", 10000); 54 | doh.registerUrl("allplugins-text", "../layers/allplugins-text.html"); 55 | 56 | doh.registerUrl("afterload", "../afterload.html", 10000); 57 | 58 | doh.registerUrl("pluginsSync", "../plugins/sync.html"); 59 | doh.registerUrl("text", "../text/text.html"); 60 | doh.registerUrl("textOnly", "../text/textOnly.html"); 61 | doh.registerUrl("jsonp", "../jsonp/jsonp.html"); 62 | doh.registerUrl("order", "../order/order.html"); 63 | 64 | doh.registerUrl("relative", "../relative/relative.html"); 65 | 66 | //Hmm, PS3 does not like exports test? assign2 is undefined? 67 | doh.registerUrl("exports", "../exports/exports.html"); 68 | 69 | 70 | doh.registerUrl("priority", "../priority/priority.html"); 71 | doh.registerUrl("priorityWithDeps", "../priority/priorityWithDeps/priorityWithDeps.html"); 72 | doh.registerUrl("prioritySingleCall", "../priority/prioritySingleCall.html"); 73 | 74 | if (typeof Worker !== "undefined") { 75 | doh.registerUrl("workers", "../workers.html"); 76 | } -------------------------------------------------------------------------------- /tests/browsertests/scriptload/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Script Load Test 5 | 6 | 87 | 88 | 89 |

    Script Load Test

    90 | 91 |

    This test checks the order in which script onloads are called. Hopefully 92 | only one script onload is fired at a time and it matches the just-evaluated 93 | script tag. If this does not work, then it means require.js files *must* specify 94 | a module name for a module definition call, instead of letting it be derived 95 | from the file path.

    96 |

    Check the console for output

    97 | 98 | 99 | -------------------------------------------------------------------------------- /docs/history.html: -------------------------------------------------------------------------------- 1 |
    2 |

    RequireJS History

    3 |
    4 | 5 |
    6 |

    I work a lot on the Dojo Loader. The normal dojo loader uses synchronous XMLHttpRequest (XHR) calls. However, the XHR loader cannot load Dojo modules from other domains because of the same-origin restrictions. So I created the xdomain loader that required a build step to inject function wrappers similar to what RequireJS uses, but more complex, due to i18n bundle loading and dojo.requireIf behavior. Because of the more complex i18n and requireIf requirements and the existence of many dojo modules already out in the world, I did not feel like the Dojo community would consider writing modules with function wrappers manually.

    7 | 8 |

    However, the sync XHR loader has other issues, like making debugging harder. In 2009, David Mark suggested that Dojo use document.write() to load modules before the page loads to help with that issue, but that means required dependencies would not load until after the current module executes. This can cause errors if the module references a dependency as part of the module's definition. So a function wrapper is needed. The Dojo community seemed more amenable to considering a function wrapper, particularly since we are considering a Dojo 2.0 that can break some APIs. I fleshed out some of the details for RequireJS on the dojo-contributors list, and Mike Wilson originally pushed for a more generic loader that could load plain files as well as allow for different contexts. It is likely RequireJS will be used for any Dojo 2.0 effort.

    9 | 10 |

    YUI 3's use() function is also very similar to require, and use()'s API (but not code) also informed require's structure. I believe RequireJS is more generic, since YUI seems to use labels for their modules that do not directly correspond to file paths. It also looks like it cannot load plain JS files, and I liked explicitly passing the dependent modules as arguments to the function definition. YUI.use() might support some of these features underneath, but I just looked at the top-level API doc.

    11 | 12 |

    I originally wanted something that would work with CommonJS modules, but those modules seem to be structured assuming a synchronous module loader, which is possible in server-side JavaScript environments. However, I am mostly concerned with something that works well in the browser, and that means needing a function wrapper so we can use script tags. Using synchronous XHR is not very friendly for new developers or people who want easy of debugging across browsers. It can also be slower than plain script tag loading. Some environments, like Adobe AIR do not allow eval() and most developers are taught that eval() is evil and should be avoided.

    13 | 14 |

    I created the seeds of RequireJS as RunJS. As I tried to get more in sync with CommonJS modules to allow more code reuse, I proposed CommonJS Transport/C proposal. The transport format allows mapping traditional CommonJS modules to a format that works best in the browser. I then converted the RunJS code to RequireJS to match the API in the Transport/C proposal. There is a conversion script to convert CommonJS modules to the format that RequireJS understands. While that script does basic module conversion, it may not work for all modules, and some modules do not make sense to run in a browser environment.

    15 |
    -------------------------------------------------------------------------------- /tests/packages/packages-tests.js: -------------------------------------------------------------------------------- 1 | require({ 2 | baseUrl: require.isBrowser ? "./" : "./packages/", 3 | paths: { 4 | 'alpha/replace' : 'replace' 5 | }, 6 | packagePaths: { 7 | 'pkgs': [ 8 | 'alpha', 9 | { 10 | name: 'beta', 11 | location: 'beta/0.2', 12 | lib: 'scripts', 13 | main: 'scripts/beta' 14 | }, 15 | 'dojox/chair', 16 | { 17 | name: 'dojox/table', 18 | lib: '.', 19 | main: 'table' 20 | } 21 | ] 22 | }, 23 | packages: [ 24 | { 25 | name: 'bar', 26 | location: 'bar/0.4', 27 | lib: 'scripts', 28 | main: 'scripts/main' 29 | }, 30 | { 31 | name: 'foo', 32 | location: 'foo' 33 | }, 34 | { 35 | name: 'funky', 36 | main: 'index.js' 37 | }, 38 | { 39 | name: 'baz', 40 | location: 'baz', 41 | main: 'lib/index' 42 | }, 43 | { 44 | name: 'dojox/window', 45 | location: 'dojox/window', 46 | lib: '.', 47 | main: 'window' 48 | } 49 | ] 50 | }, 51 | ["require", "alpha", "alpha/replace", "beta", "beta/util", "bar", "baz", 52 | "foo", "foo/second", "dojox/chair", "dojox/table", "dojox/door", "dojox/window/pane", 53 | "dojox/window", "dojox/table/legs", "funky"], 54 | function(require, alpha, replace, beta, util, bar, baz, 55 | foo, second, chair, table, door, pane, 56 | window, legs, funky) { 57 | var dataUrl = require.nameToUrl('foo/../data', '.html'); 58 | doh.register( 59 | "packages", 60 | [ 61 | function packages(t){ 62 | t.is("alpha", alpha.name); 63 | t.is("fake/alpha/replace", replace.name); 64 | t.is("beta", beta); 65 | t.is("beta/util", util.name); 66 | t.is("bar", bar.name); 67 | t.is("0.4", bar.version); 68 | t.is("baz", baz.name); 69 | t.is("0.4", baz.barDepVersion); 70 | t.is("foo", baz.fooName); 71 | t.is("baz/helper", baz.helperName); 72 | t.is("foo", foo.name); 73 | t.is("alpha", foo.alphaName); 74 | t.is("foo/second", second.name); 75 | t.is((require.isBrowser ? "./foo/lib/../data.html" : "./packages/foo/lib/../data.html"), dataUrl); 76 | t.is('dojox/chair', chair.name); 77 | t.is('dojox/chair/legs', chair.legsName); 78 | t.is('dojox/table', table.name); 79 | t.is('dojox/chair', table.chairName); 80 | t.is('dojox/table/legs', legs.name); 81 | t.is('dojox/door', door.name); 82 | t.is('dojox/window/pane', pane.name); 83 | t.is('dojox/window', window.name); 84 | t.is('dojox/window/pane', window.paneName); 85 | t.is('funky', funky.name); 86 | t.is('monkey', funky.monkeyName); 87 | } 88 | ] 89 | ); 90 | doh.run(); 91 | }); 92 | -------------------------------------------------------------------------------- /docs/contributing.html: -------------------------------------------------------------------------------- 1 |
    2 |

    Contributing to RequireJS

    3 | 4 | 8 | 9 | Note: The source for RequireJS is available on GitHub 10 | 11 |

    For something that is bigger than a one or two line fix:

    12 | 13 |
      14 |
    1. Create your own fork of the code
    2. 15 |
    3. Do the changes in your fork
    4. 16 |
    5. If you like the change and think the project could use it: 17 |
        18 |
      1. Be sure you have followed the code style for the project.
      2. 19 |
      3. Sign a Contributor License Agreement, CLA, with the Dojo Foundation and send it to them.
      4. 20 |
      5. Send a pull request indicating that you have a CLA on file.
      6. 21 |
    6. 22 |
    23 | 24 |

    For one or two line fixes, you can use the RequireJS GitHub Issues page to indicate the problem. You can also do the full fork/pull request as mentioned above, but a CLA is not needed for one or two line fixes.

    25 | 26 |

    For discussions on code changes/additions/requests use the RequireJS Group.

    27 |
    28 | 29 |
    30 |

    Why a CLA?§ 1

    31 | 32 |

    CLAs are common with open source projects, with the Apache projects probably being the most well known. The goal is to allow RequireJS to be used in as many projects as possible, and for some companies, using only CLA-approved code is the best option.

    33 | 34 |

    You still own the copyright on your contribution, the CLA just gives the most flexibility for licensing, and assures the lineage of the intellectual property. You should only submit patches for your own intellectual property, and not the intellectual property of others.

    35 | 36 |

    Additional reading that may be helpful:

    37 | 38 | 41 |
    42 | 43 |
    44 |

    Code Style§ 2

    45 | 46 |

    JSLint is used for checking code style. It is also useful for avoiding some errors. The default settings on JSLint should be fine to use, in particular, 4 spaces for indentation, do not use tabs.

    47 | 48 |

    camelCase should be used for all variables and file names. Avoid the use of underscores as word separators. This extends to things like CSS class names, IDs in test HTML documents, everything.

    49 | 50 |

    Some exceptions to JSLint can be indicated at the top of each JS file, but they should be avoided when possible. Two common exceptions you may see in the source:

    51 | 52 | 56 |
    -------------------------------------------------------------------------------- /tests/browsertests/async/async.php: -------------------------------------------------------------------------------- 1 | \n"; 5 | } 6 | else 7 | { 8 | echo "\n"; 9 | } 10 | ?> 11 | 12 | 13 | Async Attribute Test 14 | 15 | 54 | 55 | 56 |

    Async Attribute Test

    57 |

    This test requires PHP to be enabled to run.

    58 | 59 |

    This test tests async attribute. It attaches two scripts to the DOM, one.php and two.js. 60 | The URLs to the scripts always has a timestamp querystring to make sure the scripts are fetched 61 | fresh for each request.

    62 | 63 |

    one.php uses a PHP sleep of 3 seconds before returning its result (a log message), where two.js will return 64 | immediately with a log message.

    65 | 66 |

    If the async attribute is being effective (In Gecko 1.9.2+/Firefox 3.6+ browsers, maybe 67 | Opera in the future), then the log message for two.js should appear before the one.php log message. 68 | If async is not effective, then one.php's log message will appear first.

    69 | 70 |

    You can also try this page in quirks mode. 71 | When you are done, come back to standards mode.

    72 | 73 |

    Watch the console for log messages. If no console is available, then it should print 74 | the log messages in the DOM.

    75 | 76 |

    Expected Results in All Browsers (except Opera):

    77 | 81 | 82 |
    83 | 84 | 90 | 91 |
    92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /docs/node.html: -------------------------------------------------------------------------------- 1 |
    2 |

    RequireJS in Node

    3 | 4 | 15 | 16 |
    17 | 18 |
    19 |

    20 | Doesn't Node already have a module loader? 21 | § 1 22 |

    23 | 24 |

    Yes Node does. That loader uses the CommonJS module format. The CommonJS module format is non-optimal for the browser, and I do not prefer some of the trade-offs made in the CommonJS module format. By using RequireJS on the server, you can use one format for all your modules, whether they are running server side or in the browser. That way you can preserve the speed benefits and easy debugging you get with RequireJS in the browser, and not have to worry about extra translation costs for moving between two formats.

    25 |
    26 | 27 |
    28 |

    29 | Can I use Node modules already written in the CommonJS module format? 30 | § 2

    31 | 32 |

    Yes! The Node adapter for RequireJS, called r.js, will use Node's implementation of require and Node's search paths if the module is not found with the configuration used by RequireJS, so you can continue to use your existing Node-based modules without having to do changes to them.

    33 | 34 |

    However, the top most app file, the one you pass to r.js on startup, needs to be coded to the RequireJS API.

    35 | 36 |

    RequireJS will use its Configuration Options first to find modules. If RequireJS cannot find the module with its configuration, it is assumed to be a module that uses Node's type of modules and configuration. So, only configure module locations with RequireJS if they use the RequireJS API. For modules that expect Node's APIs and configuration/paths, just install them with a Node package manager, like npm, and do not configure their locations with RequireJS.

    37 | 38 |

    Even though RequireJS is an asynchronous loader in the browser, the RequireJS Node adapter loads modules synchronously in the Node environment to match the default loading behavior in Node.

    39 | 40 |

    Finally, RequireJS in Node can only load modules that are on the local disk -- fetching modules across http, for instance, is not supported at this time.

    41 | 42 |
    43 | 44 |
    45 |

    46 | How do I use it? 47 | § 3 48 |

    49 | 50 |

    Download r.js from the the download page and place it on your disk somewhere. Then run this command:

    51 | 52 |
    node path/to/r.js myNodeApp.js
    53 | 
    54 | 55 |

    This assumes you are in the directory that contains myNodeApp.js, your top-level Node application file.

    56 | 57 |

    That is it!

    58 | 59 |

    If you want to try a sample app that works with r.js, see the index.js Hello World app on the download page.

    60 | 61 |

    If you find you have a problem, and want to report it, use the RequireJS GitHub Issues page.

    62 | 63 |

    If you want to discuss the RequireJS-Node integration, you can use the RequireJS Group.

    64 |
    65 | --------------------------------------------------------------------------------