├── .gitmodules
├── test
├── stuff
│ ├── blank.css
│ ├── module-without-ext
│ ├── bad-import.css
│ ├── random.js
│ ├── aView
│ │ ├── css.css
│ │ ├── template.html
│ │ └── controller.js
│ ├── template.html
│ ├── second.css
│ ├── zero.js
│ ├── base.css
│ ├── undefined-module.js
│ ├── xdtext.html
│ ├── nls
│ │ └── strings.js
│ ├── foo.defineModule.js
│ ├── plain_old_2.js
│ ├── issue53.js
│ ├── cascade-end.css
│ ├── one.js
│ ├── css-on-cdn.js
│ ├── cascade-middle.css
│ ├── two.js
│ ├── wants-js-and-css.js
│ ├── increments.js
│ ├── three.js
│ └── cascade-start.css
├── support
│ ├── commonjs
│ │ ├── folder
│ │ │ ├── non-cjs.js
│ │ │ ├── returnMain.js
│ │ │ └── deep
│ │ │ │ └── returnMain.js
│ │ ├── relative-dep.js
│ │ ├── return-config.js
│ │ ├── foo.js
│ │ ├── main.js
│ │ ├── main2.js
│ │ ├── exports.js
│ │ ├── main-with-relative-dep.js
│ │ ├── module.js
│ │ ├── named-main.js
│ │ ├── nakedSimpleCjsm1.1.js
│ │ ├── hybrid.js
│ │ ├── nakedDependentCjsm1.1.js
│ │ ├── this.js
│ │ ├── package.json
│ │ └── loop
│ │ │ ├── hybrid-loop1.js
│ │ │ ├── hybrid-loop2.js
│ │ │ └── hybrid-loop3.js
│ ├── loop
│ │ ├── loop-start.js
│ │ ├── loop1.js
│ │ ├── loop2.js
│ │ └── loop3.js
│ ├── foo-bar-define
│ │ └── simple.js
│ ├── requires-fake.js
│ ├── main-plugin.js
│ ├── simple-plugin.js
│ └── fake.js
├── i18n
│ ├── strings.js
│ └── strings
│ │ └── en-gb.js
├── tdd
│ ├── Spy.js
│ ├── MethodSpy.js
│ └── configureAsserts.js
├── defineConflict2.html
├── apiConflict.html
├── apiConflict2.html
├── simple-plugin.html
├── apiName2.html
├── apiName.html
├── js-test-option-failure.html
├── js-test-option-success.html
├── issue53.html
├── plugin-errback.html
├── defineContext2.html
├── defineContext.html
├── apiAfter.html
├── link.html
├── defineAfter.html
├── many-plugin-callbacks.html
├── js-load-once-issue30.html
├── link-parent-path-issue108.html
├── dist-kitchen-sink.html
├── underscore.html
├── issue34.html
├── issue37.html
├── packages-as-object.html
├── issue20.html
├── plugin-relative-ids.html
├── relative-plugins.html
├── cjsModules1.1.html
├── cjsm1.1-prewrapped.html
├── cycle-correction-hybrid.html
├── top-level-plugin.html
├── jquery-ready.html
├── preload.html
├── protocol-relative-urls.html
├── basic.html
├── undefine.html
├── debug.html
├── plainOldJs.html
├── pluginConfig.html
├── i18n.html
├── plugin-specific-paths.html
├── package-specific-config.html
├── next.html
├── module-returns-undefined.html
├── issue28.html
├── defineConflict.html
├── local-require.html
├── multiple_curl_calls.html
├── dontAddFileExt.html
├── then.html
├── config.html
├── many-css-resources.html
├── paths.html
├── tdd-runner.html
└── packages.html
├── src
└── curl
│ ├── plugin
│ ├── builder
│ │ ├── i18n.js
│ │ ├── text.js
│ │ └── css.js
│ ├── README.md
│ ├── domReady.js
│ ├── text.js
│ ├── async.js
│ ├── link.js
│ ├── js.js
│ └── i18n.js
│ ├── tdd
│ ├── undefine.js
│ └── runner.js
│ ├── shim
│ ├── dojo16.js
│ └── ssjs.js
│ ├── debug.js
│ ├── domReady.js
│ └── loader
│ └── cjsm11.js
├── bin
├── compile.sh
├── make.sh
└── make-all.sh
├── package.json
├── LICENSE.txt
├── dist
├── README.md
├── curl
│ └── curl.js
├── curl-for-dojo1.6
│ └── curl.js
├── curl-with-js-and-domReady
│ └── curl.js
└── curl-for-jQuery
│ └── curl.js
└── docs
└── release-notes.md
/.gitmodules:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stuff/blank.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/stuff/module-without-ext:
--------------------------------------------------------------------------------
1 | define({});
--------------------------------------------------------------------------------
/test/stuff/bad-import.css:
--------------------------------------------------------------------------------
1 | @import url('nowhere.css');
2 |
--------------------------------------------------------------------------------
/test/stuff/random.js:
--------------------------------------------------------------------------------
1 | window.random = Math.random();
2 |
--------------------------------------------------------------------------------
/test/stuff/aView/css.css:
--------------------------------------------------------------------------------
1 | .aView {
2 | color: blue;
3 | }
4 |
--------------------------------------------------------------------------------
/test/stuff/template.html:
--------------------------------------------------------------------------------
1 |
If you see this, you WIN!
2 |
--------------------------------------------------------------------------------
/test/stuff/second.css:
--------------------------------------------------------------------------------
1 | P {
2 | text-transform: uppercase;
3 | }
4 |
--------------------------------------------------------------------------------
/test/stuff/zero.js:
--------------------------------------------------------------------------------
1 | define('stuff/zero', function () { return 0; });
2 |
--------------------------------------------------------------------------------
/test/stuff/aView/template.html:
--------------------------------------------------------------------------------
1 | this is a template
2 |
--------------------------------------------------------------------------------
/test/stuff/base.css:
--------------------------------------------------------------------------------
1 | body {
2 | color: #00f;
3 | border: 1px solid #000;
4 | }
5 |
--------------------------------------------------------------------------------
/test/stuff/undefined-module.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | // returns nothing
3 | });
--------------------------------------------------------------------------------
/test/stuff/xdtext.html:
--------------------------------------------------------------------------------
1 | define("this is a div fetched via jsonp
");
2 |
--------------------------------------------------------------------------------
/test/support/commonjs/folder/non-cjs.js:
--------------------------------------------------------------------------------
1 | define({
2 | itWorks: 'it works'
3 | });
4 |
--------------------------------------------------------------------------------
/test/stuff/nls/strings.js:
--------------------------------------------------------------------------------
1 | define({
2 | root: {
3 | hello: 'hi coderz!'
4 | }
5 | });
6 |
--------------------------------------------------------------------------------
/test/support/commonjs/relative-dep.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | return 'dep';
3 | });
4 |
--------------------------------------------------------------------------------
/test/stuff/foo.defineModule.js:
--------------------------------------------------------------------------------
1 | foo.defineModule({ msg: 'this module doesn\'t use global define' });
--------------------------------------------------------------------------------
/test/stuff/plain_old_2.js:
--------------------------------------------------------------------------------
1 | testDomain.awesome = {};
2 | testDomain.awesome.sauce = 'ketchup';
3 |
--------------------------------------------------------------------------------
/test/support/commonjs/return-config.js:
--------------------------------------------------------------------------------
1 | exports.config = function () { return module.config() };
--------------------------------------------------------------------------------
/test/support/loop/loop-start.js:
--------------------------------------------------------------------------------
1 | define(['./loop1'], function (loop1) {
2 | return loop1;
3 | });
--------------------------------------------------------------------------------
/test/support/loop/loop1.js:
--------------------------------------------------------------------------------
1 | define(['./loop2'], function (loop2) {
2 | return loop2;
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/loop/loop2.js:
--------------------------------------------------------------------------------
1 | define(['./loop3'], function (loop3) {
2 | return loop3;
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/foo-bar-define/simple.js:
--------------------------------------------------------------------------------
1 | foo.bar([], function () {
2 |
3 | return 1;
4 |
5 | });
6 |
--------------------------------------------------------------------------------
/test/support/requires-fake.js:
--------------------------------------------------------------------------------
1 | define(['./fake!foo'], function (foo) {
2 |
3 | return {};
4 |
5 | });
6 |
--------------------------------------------------------------------------------
/test/stuff/issue53.js:
--------------------------------------------------------------------------------
1 | define(['eaf.util', 'eaf.core'], function (util, core) {
2 | return "it works";
3 | });
--------------------------------------------------------------------------------
/test/support/commonjs/foo.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | exports.id = 'foo';
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/loop/loop3.js:
--------------------------------------------------------------------------------
1 | define(['./loop1'], function (loop1) {
2 | return 'this is from loop3';
3 | });
4 |
--------------------------------------------------------------------------------
/test/stuff/cascade-end.css:
--------------------------------------------------------------------------------
1 | #test-cascade {
2 | position: absolute;
3 | top: 33px;
4 | color: #face0f;
5 | }
6 |
--------------------------------------------------------------------------------
/test/stuff/one.js:
--------------------------------------------------------------------------------
1 | /*
2 | * stuff/one
3 | */
4 | //define(function () {
5 | // return 1;
6 | //});
7 | define(1);
8 |
--------------------------------------------------------------------------------
/test/support/commonjs/main.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | exports.id = module.id;
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/commonjs/main2.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | exports.id = module.id;
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/commonjs/exports.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports) {
2 | exports.testMessage = 'it works';
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/commonjs/main-with-relative-dep.js:
--------------------------------------------------------------------------------
1 | define(['./relative-dep'], function (dep) {
2 | return dep;
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/commonjs/module.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | this.testMessage = module.id;
3 | });
4 |
--------------------------------------------------------------------------------
/test/stuff/css-on-cdn.js:
--------------------------------------------------------------------------------
1 | define(["css!dijit/claro/claro.css","css!dojo/dojo.css"], function (ss1, ss2) {
2 | return 1;
3 | });
4 |
--------------------------------------------------------------------------------
/test/stuff/cascade-middle.css:
--------------------------------------------------------------------------------
1 | #test-cascade {
2 | position: absolute;
3 | top: 13px;
4 | left: 20px;
5 | color: #f0cc0f;
6 | }
7 |
--------------------------------------------------------------------------------
/test/stuff/two.js:
--------------------------------------------------------------------------------
1 | /*
2 | * stuff/two depends on stuff/one
3 | */
4 | define(['./one'], function (one) {
5 | return one + 1;
6 | });
7 |
--------------------------------------------------------------------------------
/test/stuff/wants-js-and-css.js:
--------------------------------------------------------------------------------
1 | define(["js!stuff/plain_old.js", "css!stuff/base.css"], function (plain, ss) {
2 | return "47%";
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/commonjs/named-main.js:
--------------------------------------------------------------------------------
1 | define('named/named-main', function (require, exports) {
2 |
3 | exports.name = 'named';
4 |
5 | });
6 |
--------------------------------------------------------------------------------
/test/support/commonjs/folder/returnMain.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | exports.id = function () { return require('..').id; };
3 | });
4 |
--------------------------------------------------------------------------------
/test/support/commonjs/folder/deep/returnMain.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | exports.id = function () { return require('../..').id; };
3 | });
4 |
--------------------------------------------------------------------------------
/test/stuff/increments.js:
--------------------------------------------------------------------------------
1 | var counter;
2 | define([], function () {
3 | if (typeof counter == 'undefined') counter = 0;
4 | else counter++;
5 | return counter;
6 |
7 | });
8 |
--------------------------------------------------------------------------------
/test/support/commonjs/nakedSimpleCjsm1.1.js:
--------------------------------------------------------------------------------
1 | // simple module without require()
2 | exports.testMessage = 'test';
3 | exports.uri = module.uri;
4 | exports.id = module.id;
5 |
--------------------------------------------------------------------------------
/test/support/commonjs/hybrid.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 |
3 | var foo = require('./module');
4 | exports.foo = function () { return foo; };
5 |
6 | });
7 |
--------------------------------------------------------------------------------
/test/stuff/three.js:
--------------------------------------------------------------------------------
1 | /*
2 | * stuff/three depends on stuff/one and stuff/two
3 | */
4 | define(['./one', './two', 'stuff/zero'], function (one, two) {
5 | return one + two;
6 | });
7 |
--------------------------------------------------------------------------------
/test/support/main-plugin.js:
--------------------------------------------------------------------------------
1 | define(function(){
2 | return {
3 | load: function (id, require, loaded, config) {
4 | // just echo config back
5 | loaded(config);
6 | }
7 | };
8 | });
9 |
--------------------------------------------------------------------------------
/test/support/commonjs/nakedDependentCjsm1.1.js:
--------------------------------------------------------------------------------
1 | // simple module with require()
2 | var simple = require('./nakedSimpleCjsm1.1');
3 | exports.testMessage = simple.testMessage;
4 | exports.stuff = 'stuff';
5 |
--------------------------------------------------------------------------------
/src/curl/plugin/builder/i18n.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 |
3 | return {
4 |
5 | normalize: function (id, toAbsId) {
6 |
7 | },
8 |
9 | compile: function (absId, req, io, config) {
10 |
11 | }
12 | };
13 |
14 | });
15 |
--------------------------------------------------------------------------------
/test/stuff/cascade-start.css:
--------------------------------------------------------------------------------
1 | #test-cascade-parent {
2 | position: relative;
3 | }
4 |
5 | #test-cascade {
6 | margin: 0;
7 | padding: 0;
8 | position: absolute;
9 | top: 3px;
10 | left: 0px;
11 | color: #b00bee;
12 | }
13 |
--------------------------------------------------------------------------------
/test/support/simple-plugin.js:
--------------------------------------------------------------------------------
1 | define(function(){
2 | return {
3 | load: function(id, require, loaded, config){
4 | this.config = config; // just to test if config is passed correctly
5 | require([id], loaded);
6 | }
7 | };
8 | });
9 |
--------------------------------------------------------------------------------
/test/support/commonjs/this.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 | "use strict";
3 | var messages = require('./folder/non-cjs'),
4 | mod = require('./module');
5 | this.testMessage = messages.itWorks;
6 | this._module = module;
7 | });
8 |
--------------------------------------------------------------------------------
/test/i18n/strings.js:
--------------------------------------------------------------------------------
1 | define({
2 |
3 | labels: {
4 | beer: 'brew',
5 | abode: 'apartment',
6 | transport: 'bus'
7 | },
8 |
9 | values: {
10 | date: '01/01/2010',
11 | number: 5,
12 | boolean: true,
13 | string: 'string'
14 | }
15 |
16 | });
--------------------------------------------------------------------------------
/test/i18n/strings/en-gb.js:
--------------------------------------------------------------------------------
1 | define({
2 |
3 | labels: {
4 | beer: 'pint',
5 | abode: 'flat',
6 | transport: 'lorry'
7 | },
8 |
9 | values: {
10 | date: '01/01/2010',
11 | number: 5,
12 | boolean: true,
13 | string: 'string'
14 | }
15 |
16 | });
--------------------------------------------------------------------------------
/test/support/fake.js:
--------------------------------------------------------------------------------
1 | // fake plugin
2 |
3 | define(function () {
4 |
5 | var plugin;
6 |
7 | plugin = {
8 | load: function (name, resolver, callback, config) {
9 | plugin.testValue = config.testValue;
10 | callback(config.testValue);
11 | }
12 | };
13 |
14 | return plugin;
15 |
16 | });
17 |
--------------------------------------------------------------------------------
/test/support/commonjs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "commonjs-test",
3 | "version": "0.0.1",
4 | "description": "curl package test",
5 | "licenses": [
6 | {
7 | "type": "MIT",
8 | "url": "http://www.opensource.org/licenses/mit-license.php"
9 | }
10 | ],
11 | "directories": {
12 | "lib": "."
13 | },
14 | "main": "./main"
15 | }
16 |
--------------------------------------------------------------------------------
/test/stuff/aView/controller.js:
--------------------------------------------------------------------------------
1 | define(['text!./template', 'css!./css'], function (template, css) {
2 | return {
3 | render: function (node) {
4 | try {
5 | node.innerHTML = template;
6 | }
7 | catch (ex) {
8 | // firggin IE
9 | var div = node.ownerDocument.createElement('div');
10 | div.innerHTML = template;
11 | while (div.firstChild) {
12 | node.appendChild(div.removeChild(div.firstChild));
13 | }
14 | }
15 | }
16 | }
17 | });
18 |
--------------------------------------------------------------------------------
/test/support/commonjs/loop/hybrid-loop1.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 |
3 | // implements multiply(), but delegates add() and subtract()
4 | var loop2 = require('./hybrid-loop2');
5 | var loop3 = require('./hybrid-loop3');
6 | exports.multiply = function (a, b) {
7 | return a * b;
8 | };
9 | exports.add = function (a, b) {
10 | return loop2.add(a, b);
11 | };
12 | exports.subtract = function (a, b) {
13 | return loop3.subtract(a, b);
14 | };
15 |
16 | });
--------------------------------------------------------------------------------
/test/support/commonjs/loop/hybrid-loop2.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 |
3 | // implements add(), but delegates multiply() and subtract()
4 | var loop1 = require('./hybrid-loop1');
5 | var loop3 = require('./hybrid-loop3');
6 | exports.add = function (a, b) {
7 | return a + b;
8 | };
9 | exports.multiply = function (a, b) {
10 | return loop1.multiply(a, b);
11 | }
12 | exports.subtract = function (a, b) {
13 | return loop3.subtract(a, b);
14 | }
15 |
16 | });
--------------------------------------------------------------------------------
/test/support/commonjs/loop/hybrid-loop3.js:
--------------------------------------------------------------------------------
1 | define(function (require, exports, module) {
2 |
3 | // implements subtract(), but delegates multiply() and add()
4 | var loop1 = require('./hybrid-loop1');
5 | var loop2 = require('./hybrid-loop2');
6 | exports.multiply = function (a, b) {
7 | return loop1.multiply(a, b);
8 | };
9 | exports.add = function (a, b) {
10 | return loop2.add(a, b);
11 | };
12 | exports.subtract = function (a, b) {
13 | return a - b;
14 | };
15 |
16 | });
--------------------------------------------------------------------------------
/test/tdd/Spy.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 |
3 | function Spy () {
4 | var count, spy;
5 |
6 | count = 0;
7 | spy = function () {};
8 |
9 | spy.calledNever = function () { return count == 0; };
10 | spy.calledOnce = function () { return count == 1; };
11 | spy.calledTwice = function () { return count == 2; };
12 | spy.calledMany = function (howMany) { return count == howMany; };
13 | spy.callCount = function () { return count; };
14 |
15 | return spy;
16 | }
17 |
18 | return Spy;
19 |
20 | });
21 |
--------------------------------------------------------------------------------
/bin/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # run a file through google closure compiler
3 |
4 | # TODO: start using a js_externs parameter:
5 | # paths and other config params
6 | # full promise api (for communicating with plugins)
7 | # -d js_externs=promise.then=function(cb,eb){};promise.resolve=function(val){};promise.reject=function(ex){};
8 |
9 | curl \
10 | --data-urlencode "js_code@$1" \
11 | -d compilation_level=$2 \
12 | -d output_info=compiled_code \
13 | -d output_format=text \
14 | -d 'output_wrapper=(function(){%25output%25}).call(this);' \
15 | http://closure-compiler.appspot.com/compile
16 |
--------------------------------------------------------------------------------
/test/tdd/MethodSpy.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 |
3 | function MethodSpy (method, context) {
4 | var count, orig;
5 |
6 | count = 0;
7 | orig = context[method];
8 |
9 | context[method] = function () {
10 | count++;
11 | return orig.apply(context, arguments);
12 | };
13 |
14 | return {
15 | calledNever: function () { return count == 0; },
16 | calledOnce: function () { return count == 1; },
17 | calledTwice: function () { return count == 2; },
18 | calledMany: function (howMany) { return count == howMany; },
19 | callCount: function () { return count; }
20 | };
21 | }
22 |
23 | return MethodSpy;
24 |
25 | });
26 |
--------------------------------------------------------------------------------
/src/curl/plugin/README.md:
--------------------------------------------------------------------------------
1 | curl.js loader plugins
2 | ===
3 |
4 | Please see the wiki for information about using plugins. If you're interested
5 | in creating your own plugins, please check out the Plugin Author's Guide
6 | on the wiki (TBD).
7 |
8 | All of these plugins conform to the AMD specification. However, that
9 | doesn't necessarily mean that they'll work with other AMD loaders or
10 | builders. Until the build-time API of AMD is finalized, there will be
11 | incompatibilities.
12 |
13 | Modules that should work with any loader/builder:
14 |
15 | async!
16 | domReady!
17 | js!
18 | link!
19 |
20 | TODO:
21 |
22 | json! (auto-detects xdomain and uses JSON-P)
23 |
--------------------------------------------------------------------------------
/test/tdd/configureAsserts.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 |
3 | return function configureAsserts (success, failure, name) {
4 |
5 | function doFail (msg) {
6 | failure(name + (msg ? ' - ' + msg : ''));
7 | }
8 |
9 | function doSuccess (msg) {
10 | success(name + (msg ? ' - ' + msg : ''));
11 | }
12 |
13 | function assert (val, msg) {
14 | (val === true ? doSuccess : doFail)(msg);
15 | }
16 |
17 | assert.equal = function equal (expected, val, msg) {
18 | if (val !== expected) {
19 | doFail(msg + ' (expected: ' + expected + '. got: ' + val + ')');
20 | }
21 | else {
22 | doSuccess(msg);
23 | }
24 | };
25 |
26 | return assert;
27 | };
28 |
29 | });
30 |
--------------------------------------------------------------------------------
/test/defineConflict2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | noConflict define test
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
28 |
29 |
--------------------------------------------------------------------------------
/test/apiConflict.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | noConflict api test
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
34 |
35 |
--------------------------------------------------------------------------------
/src/curl/plugin/domReady.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl domReady loader plugin
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | *
9 | */
10 |
11 | /**
12 | *
13 | * allows the curl/domReady module to be used like a plugin
14 | * this is for better compatibility with other loaders.
15 | *
16 | * Usage:
17 | *
18 | * curl(["domReady!"]).then(doSomething);
19 | *
20 | * TODO: use "../domReady" instead of "curl/domReady" when curl's make.sh is updated to use cram
21 | */
22 |
23 | define(/*=='curl/plugin/domReady',==*/ ['../domReady'], function (domReady) {
24 |
25 | return {
26 |
27 | 'load': function (name, req, cb, cfg) {
28 | domReady(cb);
29 | }
30 |
31 | };
32 |
33 | });
34 |
--------------------------------------------------------------------------------
/test/apiConflict2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | noConflict api test
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
33 |
34 |
--------------------------------------------------------------------------------
/bin/make.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # get optional optimization instruction
4 | opt=$1
5 | if [ "${opt:0:2}" = "--" ]; then
6 | opt=${opt:2}
7 | shift
8 | else
9 | opt=ADVANCED_OPTIMIZATIONS
10 | fi
11 |
12 | # grab the output file
13 | out=$1
14 | tmpfile=$(mktemp -t cram.XXXXXX)
15 |
16 | # use all of the remaining parameters as files to be concatenated
17 | shift
18 |
19 | echo "making $out"
20 | echo "optimization level is $opt"
21 |
22 | # concatenate all of the files to a temp file
23 | cat $@ | sed -e "s:\/\*==::g" -e "s:==\*\/::g" > "$tmpfile"
24 |
25 | if [ "$opt" = "NONE" ]; then
26 | # cat files to the output file
27 | cat "$tmpfile" > "$out"
28 | else
29 | # compile files to the output file
30 | ./compile.sh "$tmpfile" "$opt" > "$out"
31 | fi
32 |
33 | # remove the temporary concatenated file
34 | rm "$tmpfile"
35 |
36 | echo "created $out"
37 |
--------------------------------------------------------------------------------
/test/simple-plugin.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | simple plugin test
5 |
6 |
18 |
19 |
20 |
21 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/test/apiName2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | apiName/apiContext curl test file
5 |
6 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/test/apiName.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | apiName/apiContext curl test file
5 |
6 |
18 |
19 |
20 |
21 |
22 |
23 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "curl",
3 | "version": "0.7.3",
4 | "description": "A small, fast module and resource loader with dependency management. (AMD, CommonJS Modules/1.1, CSS, HTML, etc.)",
5 | "keywords": ["curl", "cujo", "amd", "loader", "module"],
6 | "licenses": [
7 | {
8 | "type": "MIT",
9 | "url": "http://www.opensource.org/licenses/mit-license.php"
10 | }
11 | ],
12 | "repositories": [
13 | {
14 | "type": "git",
15 | "url": "https://github.com/cujojs/curl"
16 | }
17 | ],
18 | "bugs": "https://github.com/cujojs/curl/issues",
19 | "maintainers": [
20 | {
21 | "name": "John Hann",
22 | "web": "http://unscriptable.com"
23 | }
24 | ],
25 | "contributors": [
26 | {
27 | "name": "John Hann",
28 | "web": "http://unscriptable.com"
29 | },
30 | {
31 | "name": "Brian Cavalier",
32 | "web": "http://hovercraftstudios.com"
33 | }
34 | ],
35 | "main": "./src/curl",
36 | "directories": {
37 | "test": "test"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/test/js-test-option-failure.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | js! plugin !test option
5 |
6 |
16 |
17 |
18 |
19 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/test/js-test-option-success.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | js! plugin !test option
5 |
6 |
17 |
18 |
19 |
20 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/test/issue53.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | issue 53
5 |
6 |
7 |
8 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/test/plugin-errback.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | plugin errback test
5 |
6 |
15 |
16 |
17 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/test/defineContext2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | defineName/defineContext curl test file (2)
5 |
6 |
7 |
8 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/bin/make-all.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # make simple, compiled curl.js
4 | ./make.sh ../dist/curl/curl.js ../src/curl.js
5 |
6 | # make other versions of curl
7 | ./make.sh ../dist/curl-with-js-and-domReady/curl.js ../src/curl.js ../src/curl/domReady.js ../src/curl/plugin/js.js ../src/curl/plugin/domReady.js
8 | ./make.sh ../dist/curl-for-dojo1.6/curl.js ../src/curl.js ../src/curl/domReady.js ../src/curl/shim/dojo16.js ../src/curl/plugin/domReady.js
9 | ./make.sh ../dist/curl-kitchen-sink/curl.js ../src/curl.js ../src/curl/domReady.js ../src/curl/shim/dojo16.js ../src/curl/plugin/js.js ../src/curl/plugin/text.js ../src/curl/plugin/async.js ../src/curl/plugin/css.js ../src/curl/plugin/link.js ../src/curl/plugin/domReady.js ../src/curl/loader/cjsm11.js ../src/curl/shim/ssjs.js
10 | ./make.sh ../dist/curl-for-jQuery/curl.js ../src/curl.js ../src/curl/domReady.js ../src/curl/plugin/js.js ../src/curl/plugin/link.js ../src/curl/plugin/domReady.js
11 |
12 | #make minimally-compressed ssjs
13 | ./make.sh --NONE ../dist/curl-for-ssjs/curl.js ../src/curl.js ../src/curl/loader/cjsm11.js ../src/curl/shim/ssjs.js
14 |
--------------------------------------------------------------------------------
/test/defineContext.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | defineName/defineContext curl test file
5 |
6 |
18 |
19 |
20 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/test/apiAfter.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | apiName/apiContext curl test file
5 |
6 |
13 |
14 |
15 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/test/link.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | curl loading test for <link>ed css
5 |
6 |
18 |
19 |
20 |
21 |
45 |
46 |
47 |
48 |
49 | This text should all be the same color if the css file loaded.
50 | If the second file loaded, these are all caps, too.
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/test/defineAfter.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | apiName/apiContext curl test file
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/test/many-plugin-callbacks.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | many curls test
5 |
6 |
15 |
16 |
17 |
36 |
37 |
38 |
39 |
40 | This text should all be the same color if the css file loaded.
41 |
42 |
43 |
--------------------------------------------------------------------------------
/test/js-load-once-issue30.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | js! plugin load once
5 |
6 |
16 |
17 |
18 |
19 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/test/link-parent-path-issue108.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | curl loading test for <link>ed css
5 |
6 |
18 |
19 |
20 |
21 |
45 |
46 |
47 |
48 |
49 | This text should all be the same color if the css file loaded.
50 | If the second file loaded, these are all caps, too.
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/test/dist-kitchen-sink.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | main curl test file
5 |
6 |
15 |
16 |
17 |
42 |
43 |
44 |
45 |
46 | This text should all be the same color if the css file loaded.
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/test/underscore.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | underscore test file
5 |
6 |
18 |
19 |
20 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/test/issue34.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | test for github issue #34
5 |
6 |
7 |
8 |
9 |
10 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/test/issue37.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | test for github issue #37
5 |
6 |
7 |
8 |
9 |
10 |
41 |
42 |
43 |
44 |
45 | Success or failure message below:
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/test/packages-as-object.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Packages as object test
5 |
6 |
21 |
22 |
23 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Open Source Initiative OSI - The MIT License
2 |
3 | http://www.opensource.org/licenses/mit-license.php
4 |
5 | Copyright (c) 2012 Brian Cavalier and John Hann
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining
8 | a copy of this software and associated documentation files (the
9 | "Software"), to deal in the Software without restriction, including
10 | without limitation the rights to use, copy, modify, merge, publish,
11 | distribute, sublicense, and/or sell copies of the Software, and to
12 | permit persons to whom the Software is furnished to do so, subject to
13 | the following conditions:
14 |
15 | The above copyright notice and this permission notice shall be
16 | included in all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 |
--------------------------------------------------------------------------------
/test/issue20.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | test for github issue #20
5 |
6 |
26 |
27 |
28 |
29 |
30 |
50 |
51 |
52 |
53 |
54 | You should see the word, "loaded".
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/test/plugin-relative-ids.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | plugin relative ids test
5 |
6 |
15 |
16 |
17 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/test/relative-plugins.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | relative plugins and resources
5 |
6 |
7 |
8 |
9 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/test/cjsModules1.1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CommonJS Modules 1.1 loading test
5 |
6 |
29 |
30 |
31 |
32 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/test/cjsm1.1-prewrapped.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CommonJS Modules 1.1 loading test
5 |
6 |
16 |
17 |
18 |
19 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/test/cycle-correction-hybrid.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | cycle correction for hybrid modules
5 |
6 |
17 |
18 |
19 |
20 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/test/top-level-plugin.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | top-level plugin test
5 |
6 |
20 |
21 |
22 |
23 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/test/jquery-ready.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | jquery $.ready() test file
5 |
6 |
15 |
16 |
17 |
49 |
50 |
51 |
52 |
53 |
54 |
61 |
62 |
--------------------------------------------------------------------------------
/test/preload.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | preloads test file
5 |
6 |
25 |
26 |
27 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/test/protocol-relative-urls.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | protocol-relative-urls
5 |
6 |
30 |
31 |
32 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/src/curl/tdd/undefine.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl createContext module
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | *
9 | */
10 |
11 | define(['curl/_privileged', 'require'], function (priv, require) {
12 | var cache, cleanupScript, loadScript;
13 |
14 | cache = priv['cache'];
15 |
16 | cleanupScript = noop;
17 |
18 | if (typeof document != 'undefined') {
19 | cleanupScript = removeScript;
20 | loadScript = priv['core'].loadScript;
21 | priv['core'].loadScript = function (def) {
22 | var el = loadScript.apply(this, arguments);
23 | el._curl_id = def.id;
24 | }
25 | }
26 |
27 | /**
28 | * Removes a module from curl.js's cache so that it can
29 | * be re-defined or re-required. Provide an array of moduleIds
30 | * instead of a single moduleId to delete many at a time.
31 | * @param moduleId {String|Array} the id of a module (or modules)
32 | */
33 | return function undefine (moduleId) {
34 | var ids, id;
35 | ids = [].concat(moduleId);
36 | while ((id = ids.pop())) {
37 | delete cache[id];
38 | cleanupScript(id);
39 | }
40 | };
41 |
42 | function removeScript (id) {
43 | var scripts, i, script;
44 | scripts = document.getElementsByTagName('script');
45 | i = 0;
46 | while ((script = scripts[i++])) {
47 | if (script._curl_id == id) {
48 | script.parentNode.removeChild(script);
49 | return; // all done!
50 | }
51 | }
52 | }
53 |
54 | function noop () {}
55 |
56 | });
57 |
--------------------------------------------------------------------------------
/test/basic.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | main curl test file
5 |
6 |
15 |
16 |
17 |
53 |
54 |
55 |
56 |
57 | This text should all be the same color if the css file loaded.
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/test/undefine.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | undefine test
5 |
6 |
17 |
18 |
19 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/test/debug.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | curl debug module test file
5 |
6 |
30 |
31 |
32 |
54 |
55 |
56 |
57 |
58 | This text should all be the same color if the css file loaded.
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/test/plainOldJs.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | curl loading test for plain old javascript
5 |
6 |
18 |
19 |
20 |
21 |
22 |
45 |
46 |
47 |
48 |
49 | This text should all be the same color if the css file loaded.
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/test/pluginConfig.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | plugin config test file
5 |
6 |
9 |
10 |
11 |
55 |
56 |
57 |
58 |
59 | There should be text below if this page loaded.
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/test/i18n.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | i18n tests
5 |
6 |
20 |
21 |
22 |
23 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/src/curl/plugin/builder/text.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl text! loader builder plugin
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | */
9 | define(function () {
10 | "use strict";
11 |
12 | // collection of modules that have been written to the built file
13 | var built = {};
14 |
15 | function nameWithExt (name, defaultExt) {
16 | return name.lastIndexOf('.') <= name.lastIndexOf('/') ?
17 | name + '.' + defaultExt : name;
18 | }
19 |
20 | function jsEncode (text) {
21 | // TODO: hoist the map and regex to the enclosing scope for better performance
22 | var map = { 34: '\\"', 13: '\\r', 12: '\\f', 10: '\\n', 9: '\\t', 8: '\\b' };
23 | return text.replace(/(["\n\f\t\r\b])/g, function (c) {
24 | return map[c.charCodeAt(0)];
25 | });
26 | }
27 |
28 | return {
29 |
30 | build: function (writer, fetcher, config) {
31 | // writer is a function used to output to the built file
32 | // fetcher is a function used to fetch a text file
33 | // config is the global config
34 | // returns a function that the build tool can use to tell this
35 | // plugin to write-out a resource
36 | return function write (pluginId, resource, resolver) {
37 | var url, absId, text, output;
38 | url = resolver['toUrl'](nameWithExt(resource, 'html'));
39 | absId = resolver['toAbsMid'](resource);
40 | if (!(absId in built)) {
41 | built[absId] = true;
42 | // fetch text
43 | text = jsEncode(fetcher(url));
44 | // write out a define
45 | output = 'define("' + pluginId + '!' + absId + '", function () {\n' +
46 | '\treturn "' + text + '";\n' +
47 | '});\n';
48 | writer(output);
49 | }
50 | };
51 | }
52 |
53 |
54 | };
55 |
56 | });
57 |
--------------------------------------------------------------------------------
/test/plugin-specific-paths.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | plugin-specific-paths
5 |
6 |
33 |
34 |
35 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/src/curl/shim/dojo16.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl dojo 1.6 shim
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | */
9 |
10 | /**
11 | * Until AMD becomes well established, there will be issues with the various
12 | * libs. This one overcomes some minor issues with dojo 1.6's initial
13 | * foray into AMD territory. :)
14 | *
15 | * usage:
16 | * curl(['curl/shim/dojo16', 'curl/domReady'])
17 | * .next(['dojo/parser'])
18 | * .then(function (parser) {
19 | * parser.parse();
20 | * });
21 | *
22 | */
23 | var require;
24 | define(/*=='curl/shim/dojo16',==*/ ['curl/_privileged', 'curl/domReady'], function (priv, domReady) {
25 | "use strict";
26 |
27 | var _curl = priv['_curl'],
28 | origCreateContext = priv['core'].createContext;
29 |
30 | function duckPunchRequire (req) {
31 | // create a ready method on `require`
32 | if (!req['ready']){
33 | req['ready'] = function (cb) {
34 | domReady(cb);
35 | };
36 | }
37 | // map non-standard nameToUrl to toUrl
38 | if (!req['nameToUrl']) {
39 | req['nameToUrl'] = function (name, ext) {
40 | return req['toUrl'](name + (ext || ''));
41 | };
42 | }
43 | // dojo 1.7 has a few unchecked `require.cache` usages
44 | if (!req['cache']) req['cache'] = {};
45 | return req;
46 | }
47 |
48 | // modify global curl cuz dojo doesn't always use local `require`
49 | // as a dependency
50 | duckPunchRequire(_curl);
51 |
52 | // dojo 1.7 still expects a global `require`, so make sure they've got one
53 | if (typeof require == 'undefined') {
54 | require = _curl;
55 | }
56 |
57 | // override createContext to override "local require"
58 | priv['core'].createContext = function () {
59 | var def = origCreateContext.apply(this, arguments);
60 | duckPunchRequire(def.require);
61 | return def;
62 | };
63 |
64 | return true;
65 |
66 | });
67 |
--------------------------------------------------------------------------------
/test/package-specific-config.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CommonJS Modules 1.1 loading test
5 |
6 |
30 |
31 |
32 |
33 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/test/next.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | test next()
5 |
6 |
29 |
30 |
31 |
75 |
76 |
77 |
78 |
79 | This text should all be the same color if the css file loaded.
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/test/module-returns-undefined.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | undefined module loads once
5 |
6 |
15 |
16 |
17 |
78 |
79 |
80 |
81 |
82 | press this button to load the local module again
83 | dump cache to console
84 |
85 |
86 |
--------------------------------------------------------------------------------
/src/curl/plugin/text.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl text! loader plugin
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | */
9 |
10 | /**
11 | * TODO: load xdomain text, too
12 | *
13 | */
14 |
15 | define(/*=='curl/plugin/text',==*/ function () {
16 |
17 | var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
18 |
19 | function xhr () {
20 | if (typeof XMLHttpRequest !== "undefined") {
21 | // rewrite the getXhr method to always return the native implementation
22 | xhr = function () { return new XMLHttpRequest(); };
23 | }
24 | else {
25 | // keep trying progIds until we find the correct one, then rewrite the getXhr method
26 | // to always return that one.
27 | var noXhr = xhr = function () {
28 | throw new Error("getXhr(): XMLHttpRequest not available");
29 | };
30 | while (progIds.length > 0 && xhr === noXhr) (function (id) {
31 | try {
32 | new ActiveXObject(id);
33 | xhr = function () { return new ActiveXObject(id); };
34 | }
35 | catch (ex) {}
36 | }(progIds.shift()));
37 | }
38 | return xhr();
39 | }
40 |
41 | function fetchText (url, callback, errback) {
42 | var x = xhr();
43 | x.open('GET', url, true);
44 | x.onreadystatechange = function (e) {
45 | if (x.readyState === 4) {
46 | if (x.status < 400) {
47 | callback(x.responseText);
48 | }
49 | else {
50 | errback(new Error('fetchText() failed. status: ' + x.statusText));
51 | }
52 | }
53 | };
54 | x.send(null);
55 | }
56 |
57 | function error (ex) {
58 | throw ex;
59 | }
60 |
61 | return {
62 |
63 | // 'normalize': function (resourceId, toAbsId) {
64 | // // remove options
65 | // return resourceId ? toAbsId(resourceId.split("!")[0]) : resourceId;
66 | // },
67 |
68 | load: function (resourceName, req, callback, config) {
69 | // remove suffixes (future)
70 | // get the text
71 | fetchText(req['toUrl'](resourceName), callback, callback['error'] || error);
72 | },
73 |
74 | 'plugin-builder': './builder/text'
75 |
76 | };
77 |
78 | });
79 |
--------------------------------------------------------------------------------
/test/issue28.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | test for github issue #28
5 |
6 |
7 |
8 |
9 |
10 |
64 |
65 |
66 |
67 |
68 | Success or failure message below:
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/test/defineConflict.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | noConflict define test
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
73 |
74 |
--------------------------------------------------------------------------------
/src/curl/plugin/async.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl async! plugin
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | *
9 | */
10 | /*
11 | async plugin takes another module as it's resource and defers callback
12 | until that module is complete. the module must return a promise-like
13 | object (i.e. has a then method). usage:
14 |
15 | // module that depends upon a deferred (async) resource:
16 | define(['async!deferredResource'], function (deferredResource) {
17 | // use deferredResource
18 | });
19 |
20 | // deferredResource:
21 | define(function () {
22 | var resolved, queue, undef;
23 | queue = [];
24 | function fetchResource () {
25 | // go get the resource and call loaded when done
26 | }
27 | function loaded (resource) {
28 | var callback;
29 | resolved = resource;
30 | while ((callback = queue.pop()) callback(resolved);
31 | }
32 | return {
33 | then: function (callback, errback) {
34 | if (resolved != undef) callback(resolved); else queue.push(callback);
35 | }
36 | };
37 | });
38 |
39 | */
40 | define(/*=='curl/plugin/async',==*/ function () {
41 |
42 | return {
43 |
44 | 'load': function (resourceId, require, callback, config) {
45 |
46 | function rejected (error) {
47 | // report that an error happened
48 | if (typeof callback.error == 'function') {
49 | // promise-like callback
50 | callback.error(error);
51 | }
52 | // no way to report errors if the callback doesn't have error()
53 | }
54 |
55 | // go get the module in the standard way
56 | require([resourceId], function (module) {
57 |
58 | if (typeof module.then == 'function') {
59 | // promise-like module
60 | module.then(
61 | function (resource) {
62 | if (arguments.length == 0) resource = module;
63 | callback(resource);
64 | },
65 | rejected
66 | );
67 | }
68 | else {
69 | // just a normal module
70 | callback(module);
71 | }
72 | }, callback['error'] || function (ex) { throw ex; });
73 | },
74 |
75 | // for cram's analyze phase
76 | 'analyze': function (resourceId, api, addDep) {
77 | addDep(resourceId);
78 | }
79 |
80 | }
81 |
82 | });
83 |
--------------------------------------------------------------------------------
/test/local-require.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | local require tests
5 |
6 |
19 |
20 |
21 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/test/multiple_curl_calls.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | load module once test file
5 |
6 |
16 |
17 |
18 |
83 |
84 |
85 |
86 |
87 | press this button to load the local module again
88 | press this button to load the remote module again
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/src/curl/debug.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl debug plugin
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | *
9 | */
10 |
11 | /**
12 | * usage:
13 | * curl({ preloads: ['curl/debug'] }, ['my/app'], function (myApp) {
14 | * // do stuff while logging debug messages
15 | * });
16 | *
17 | * TODO: warn when main module still has leading dots (normalizePackageDescriptor)
18 | * TODO: warn when a module id still has leading dots (toAbsId)
19 | * TODO: use curl/tdd/undefine module instead of quick-and-dirty method below
20 | * TODO: only add logging to some of the useful core functions
21 | *
22 | */
23 | define(['require', 'curl/_privileged'], function (require, priv) {
24 | "use strict";
25 |
26 | var cache, totalWaiting, prevTotal, origDefine;
27 |
28 | if (typeof console == 'undefined') {
29 | throw new Error('`console` object must be defined to use debug module.');
30 | }
31 |
32 | priv._curl['undefine'] = function (moduleId) { delete cache[moduleId]; };
33 |
34 | cache = priv['cache'];
35 |
36 | // add logging to core functions
37 | for (var p in priv['core']) (function (name, orig) {
38 | priv['core'][name] = function () {
39 | var result;
40 | console.log('curl ' + name + ' arguments:', arguments);
41 | result = orig.apply(this, arguments);
42 | console.log('curl ' + name + ' return:', result);
43 | return result;
44 | };
45 | }(p, priv['core'][p]));
46 |
47 | // add logging to define
48 | origDefine = priv._define;
49 | priv._define = function () {
50 | console.log('curl define:', arguments);
51 | return origDefine.apply(this, arguments);
52 | };
53 |
54 | // log cache stats periodically
55 | totalWaiting = 0;
56 |
57 | function count () {
58 | totalWaiting = 0;
59 | for (var p in cache) {
60 | if (cache[p] instanceof priv['Promise']) totalWaiting++;
61 | }
62 | }
63 | count();
64 |
65 | function periodicLogger () {
66 | count();
67 | if (prevTotal != totalWaiting) {
68 | console.log('curl: ********** modules waiting: ' + totalWaiting);
69 | for (var p in cache) {
70 | if (cache[p] instanceof priv['Promise']) {
71 | console.log('curl: ********** module waiting: ' + p);
72 | }
73 | }
74 | }
75 | prevTotal = totalWaiting;
76 | setTimeout(periodicLogger, 500);
77 | }
78 | periodicLogger();
79 |
80 | return true;
81 |
82 | });
83 |
--------------------------------------------------------------------------------
/test/dontAddFileExt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Packages test
5 |
6 |
7 |
8 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/test/then.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | test then()
5 |
6 |
20 |
21 |
22 |
107 |
108 |
109 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/dist/README.md:
--------------------------------------------------------------------------------
1 | Distribution Files
2 | ==================
3 |
4 | These are "compiled" versions of curl.js for your convenience.
5 |
6 | Please note: these versions have been processed with Google Closure Compiler
7 | in Advanced Mode. Advanced Mode obfuscates any identifiers that haven't
8 | been specifically declared as "exported".
9 | Therefore, any modules/files that aren't compiled at the same time
10 | may not work together after being compiled.
11 |
12 | curl.js only exports identifiers needed for AMD compatibility or needed
13 | to process configuration settings. What this means to you:
14 |
15 | If you plan to use any of curl's plugins or other auxiliary modules,
16 | you may have to compile them into curl.js (see below) -- or
17 | compile curl.js into your application's optimized files. If you see "method
18 | not defined" or similar errors within curl.js, this is likely the problem.
19 |
20 | Use curl/curl.js if you are only loading AMD-formatted javascript modules.
21 |
22 | Use curl-with-js-and-domReady/curl.js if you wish to use non-AMD javascript
23 | files and don't have an alternative domReady implementation handy.
24 |
25 | Use curl-for-jQuery for a version of curl that has instructions for
26 | jQuery 1.7 to register as an AMD module and has the js! and link! plugins
27 | built in. This is an adequate configuration for many simple jQuery projects
28 | (and some sophisticated ones, too).
29 |
30 | curl-for-dojo1.6 has the domReady! plugin built in as well as some
31 | compatibility shims for dojo 1.6 and dojo 1.7.
32 |
33 | You can build your own custom version of curl.js by using the `make.sh` script
34 | in the /bin/ folder. You must run it from the /bin/ folder. Syntax:
35 |
36 | ./make.sh destination/curl.js ../src/curl.js [files to concat into curl.js]
37 |
38 | The following files can be concatenated into curl.js using make.sh:
39 |
40 | * ../src/curl/plugin/js.js (the js! plugin)
41 | * ../src/curl/plugin/text.js (the text! plugin)
42 | * ../src/curl/plugin/i18n.js (the i18n! plugin)
43 | * ../src/curl/plugin/css.js (the css! plugin)
44 | * ../src/curl/plugin/link.js (the link! plugin)
45 | * ../src/curl/plugin/domReady.js (the domReady plugin)
46 | * ../src/curl/domReady.js (the domReady module)
47 | * ../src/curl/shim/dojo16.js (the dojo 1.6 compatibility shim / module)
48 | * ../src/curl/loader/cjsm11.js (the CommonJS Modules/1.1 compatibility shim / module)
49 | * Any named AMD module (does not support anonymous modules, yet!)
50 | * Any non-AMD javascript file
51 |
52 | For example, to make a version of curl with the js! and text! plugins built-in:
53 |
54 | ./make.sh destination/curl.js ../src/curl.js ../src/curl/plugin/js.js ../src/curl/plugin/text.js
55 |
56 | Note: you will need a fairly recent version of `curl` (the unix utility, not
57 | curl.js!) to run `make.sh`. Version 7.18 or later is fine.
58 |
--------------------------------------------------------------------------------
/src/curl/plugin/link.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl link! plugin
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | *
9 | */
10 |
11 | (function (global) {
12 | "use strict";
13 |
14 | /*
15 | * curl link! plugin
16 | * This plugin will load css files as elements. It does not wait for
17 | * css file to finish loading / evaluating before executing dependent modules.
18 | * This plugin also does not handle IE's 31-stylesheet limit.
19 | * If you need any of the above behavior, use curl's css! plugin instead.
20 | *
21 | * All this plugin does is insert elements in a non-blocking manner.
22 | *
23 | * usage:
24 | * // load myproj/comp.css and myproj/css2.css
25 | * require(['link!myproj/comp,myproj/css2']);
26 | * // load some/folder/file.css
27 | * define(['css!some/folder/file'], {});
28 | *
29 | * Tested in:
30 | * Firefox 1.5, 2.0, 3.0, 3.5, 3.6, and 4.0b6
31 | * Safari 3.0.4, 3.2.1, 5.0
32 | * Chrome 7+
33 | * Opera 9.52, 10.63, and Opera 11.00
34 | * IE 6, 7, and 8
35 | * Netscape 7.2 (WTF? SRSLY!)
36 | * Does not work in Safari 2.x :(
37 | */
38 |
39 |
40 | var
41 | // compressibility shortcuts
42 | createElement = 'createElement',
43 | // doc will be undefined during a build
44 | doc = global.document,
45 | // regexp to find url protocol for IE7/8 fix (see fixProtocol)
46 | isProtocolRelativeRx = /^\/\//,
47 | // find the head element and set it to it's standard property if nec.
48 | head;
49 |
50 | if (doc) {
51 | head = doc.head || (doc.head = doc.getElementsByTagName('head')[0]);
52 | }
53 |
54 | function nameWithExt (name, defaultExt) {
55 | return name.lastIndexOf('.') <= name.lastIndexOf('/') ?
56 | name + '.' + defaultExt : name;
57 | }
58 |
59 | function createLink (doc, href) {
60 | var link = doc[createElement]('link');
61 | link.rel = "stylesheet";
62 | link.type = "text/css";
63 | link.href = href;
64 | return link;
65 | }
66 |
67 | function fixProtocol (url, protocol) {
68 | // IE 7 & 8 can't handle protocol-relative urls:
69 | // http://www.stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/
70 | return url.replace(isProtocolRelativeRx, protocol + '//');
71 | }
72 |
73 | define(/*=='curl/plugin/link',==*/ {
74 |
75 | // 'normalize': function (resourceId, toAbsId) {
76 | // // remove options
77 | // return resourceId ? toAbsId(resourceId.split("!")[0]) : resourceId;
78 | // },
79 |
80 | 'load': function (resourceId, require, callback, config) {
81 | var url, link, fix;
82 |
83 | url = nameWithExt(require['toUrl'](resourceId), 'css');
84 | fix = 'fixSchemalessUrls' in config ? config['fixSchemalessUrls'] : doc.location.protocol;
85 | url = fix ? fixProtocol(url, fix) : url;
86 | link = createLink(doc, url);
87 | head.appendChild(link);
88 |
89 | callback(link.sheet || link.styleSheet);
90 |
91 | }
92 |
93 | });
94 |
95 | })(this);
96 |
--------------------------------------------------------------------------------
/test/config.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | config tests
5 |
6 |
23 |
24 |
25 |
26 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/test/many-css-resources.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Many CSS Resources test
5 |
6 |
15 |
16 |
17 |
108 |
109 |
110 |
111 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/src/curl/shim/ssjs.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl ssjs shim
5 | * Modifies curl to work as an AMD loader function in server-side
6 | * environments such as RingoJS, Rhino, and NodeJS.
7 | *
8 | * Licensed under the MIT License at:
9 | * http://www.opensource.org/licenses/mit-license.php
10 | *
11 | * TODO: support environments that implement XMLHttpRequest such as Wakanda
12 | *
13 | * @experimental
14 | */
15 | define['amd'].ssjs = true;
16 | var require, load;
17 | (function (freeRequire, globalLoad) {
18 | define(/*=='curl/shim/ssjs',==*/ function (require, exports) {
19 | "use strict";
20 |
21 | var priv, config, hasProtocolRx, extractProtocolRx, protocol,
22 | http, localLoadFunc, remoteLoadFunc,
23 | undef;
24 |
25 | // first, bail if we're in a browser!
26 | if (typeof window == 'object' && (window.clientInformation || window.navigator)) {
27 | return;
28 | }
29 |
30 | priv = require('curl/_privileged');
31 | config = priv.config();
32 | hasProtocolRx = /^\w+:/;
33 | extractProtocolRx = /(^\w+:)?.*$/;
34 |
35 | protocol = fixProtocol(config.defaultProtocol)
36 | || extractProtocol(config.baseUrl)
37 | || 'http:';
38 |
39 | // sniff for capabilities
40 |
41 | if (globalLoad) {
42 | // rhino & ringo make this so easy
43 | localLoadFunc = remoteLoadFunc = loadScriptViaLoad;
44 | }
45 | else if (freeRequire) {
46 | localLoadFunc = loadScriptViaRequire;
47 | // try to find an http client
48 | try {
49 | // node
50 | http = freeRequire('http');
51 | remoteLoadFunc = loadScriptViaNodeHttp;
52 | }
53 | catch (ex) {
54 | remoteLoadFunc = failIfInvoked;
55 | }
56 |
57 | }
58 | else {
59 | localLoadFunc = remoteLoadFunc = failIfInvoked;
60 | }
61 |
62 | function stripExtension (url) {
63 | return url.replace(/\.js$/, '');
64 | }
65 |
66 | priv.core.loadScript = function (def, success, fail) {
67 | var urlOrPath;
68 | // figure out if this is local or remote and call appropriate function
69 | // remote urls always have a protocol or a // at the beginning
70 | urlOrPath = def.url;
71 | if (/^\/\//.test(urlOrPath)) {
72 | // if there's no protocol, use configured protocol
73 | def.url = protocol + def.url;
74 | }
75 | if (hasProtocolRx.test(def.url)) {
76 | return remoteLoadFunc(def, success, fail);
77 | }
78 | else {
79 | return localLoadFunc(def, success, fail);
80 | }
81 | };
82 |
83 | function loadScriptViaLoad (def, success, fail) {
84 | try {
85 | globalLoad(def.url);
86 | success();
87 | }
88 | catch (ex) {
89 | fail(ex);
90 | }
91 | }
92 |
93 | function loadScriptViaRequire (def, success, fail) {
94 | var modulePath;
95 | try {
96 | modulePath = stripExtension(def.url);
97 | freeRequire(modulePath);
98 | success();
99 | }
100 | catch (ex) {
101 | fail(ex);
102 | }
103 | }
104 |
105 | function loadScriptViaNodeHttp (def, success, fail) {
106 | var options, source;
107 | options = freeRequire('url').parse(def.url, false, true);
108 | source = '';
109 | http.get(options, function (response) {
110 | response
111 | .on('data', function (chunk) { source += chunk; })
112 | .on('end', function () { executeScript(source); success(); })
113 | .on('error', fail);
114 | }).on('error', fail);
115 | }
116 |
117 | function failIfInvoked (def) {
118 | throw new Error('ssjs: unable to load module in current environment: ' + def.url);
119 | }
120 |
121 | function executeScript (source) {
122 | eval(source);
123 | }
124 |
125 | function extractProtocol (url) {
126 | var protocol;
127 | protocol = url && url.replace(extractProtocolRx,
128 | function (m, p) { return p; }
129 | );
130 | return protocol;
131 | }
132 |
133 | function fixProtocol (protocol) {
134 | return protocol && protocol[protocol.length - 1] != ':'
135 | ? protocol += ':'
136 | : protocol;
137 | }
138 |
139 | });
140 | }(require, load));
141 |
--------------------------------------------------------------------------------
/test/paths.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Paths test
5 |
6 |
15 |
16 |
17 |
18 |
19 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/src/curl/domReady.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl domReady
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | */
9 |
10 | /**
11 | * usage:
12 | * require(['ModuleA', 'curl/domReady'], function (ModuleA, domReady) {
13 | * var a = new ModuleA();
14 | * domReady(function () {
15 | * document.body.appendChild(a.domNode);
16 | * });
17 | * });
18 | *
19 | * also: check out curl's domReady! plugin
20 | *
21 | * HT to Bryan Forbes who wrote the initial domReady code:
22 | * http://www.reigndropsfall.net/
23 | *
24 | */
25 | (function (global, doc) {
26 |
27 | var
28 | readyState = 'readyState',
29 | // keep these quoted so closure compiler doesn't squash them
30 | readyStates = { 'loaded': 1, 'interactive': 1, 'complete': 1 },
31 | callbacks = [],
32 | fixReadyState = doc && typeof doc[readyState] != "string",
33 | // IE needs this cuz it won't stop setTimeout if it's already queued up
34 | completed = false,
35 | pollerTime = 10,
36 | addEvent,
37 | remover,
38 | removers = [],
39 | pollerHandle,
40 | undef;
41 |
42 | function ready () {
43 | completed = true;
44 | clearTimeout(pollerHandle);
45 | while (remover = removers.pop()) remover();
46 | if (fixReadyState) {
47 | doc[readyState] = "complete";
48 | }
49 | // callback all queued callbacks
50 | var cb;
51 | while ((cb = callbacks.shift())) {
52 | cb();
53 | }
54 | }
55 |
56 | var testEl;
57 | function isDomManipulable () {
58 | // question: implement Diego Perini's IEContentLoaded instead?
59 | // answer: The current impl seems more future-proof rather than a
60 | // non-standard method (doScroll). i don't care if the rest of the js
61 | // world is using doScroll! They can have fun repairing their libs when
62 | // the IE team removes doScroll in IE 13. :)
63 | if (!doc.body) return false; // no body? we're definitely not ready!
64 | if (!testEl) testEl = doc.createTextNode('');
65 | try {
66 | // webkit needs to use body. doc
67 | doc.body.removeChild(doc.body.appendChild(testEl));
68 | testEl = undef;
69 | return true;
70 | }
71 | catch (ex) {
72 | return false;
73 | }
74 | }
75 |
76 | function checkDOMReady (e) {
77 | var isReady;
78 | // all browsers except IE will be ready when readyState == 'interactive'
79 | // so we also must check for document.body
80 | isReady = readyStates[doc[readyState]] && isDomManipulable();
81 | if (!completed && isReady) {
82 | ready();
83 | }
84 | return isReady;
85 | }
86 |
87 | function poller () {
88 | checkDOMReady();
89 | if (!completed) {
90 | pollerHandle = setTimeout(poller, pollerTime);
91 | }
92 | }
93 |
94 | // select the correct event listener function. all of our supported
95 | // browsers will use one of these
96 | if ('addEventListener' in global) {
97 | addEvent = function (node, event) {
98 | node.addEventListener(event, checkDOMReady, false);
99 | return function () { node.removeEventListener(event, checkDOMReady, false); };
100 | };
101 | }
102 | else {
103 | addEvent = function (node, event) {
104 | node.attachEvent('on' + event, checkDOMReady);
105 | return function () { node.detachEvent(event, checkDOMReady); };
106 | };
107 | }
108 |
109 | if (doc) {
110 | if (!checkDOMReady()) {
111 | // add event listeners and collect remover functions
112 | removers = [
113 | addEvent(global, 'load'),
114 | addEvent(doc, 'readystatechange'),
115 | addEvent(global, 'DOMContentLoaded')
116 | ];
117 | // additionally, poll for readystate
118 | pollerHandle = setTimeout(poller, pollerTime);
119 | }
120 | }
121 |
122 | define(/*=='curl/domReady',==*/ function () {
123 |
124 | // this is simply a callback, but make it look like a promise
125 | function domReady (cb) {
126 | if (completed) cb(); else callbacks.push(cb);
127 | }
128 | domReady['then'] = domReady;
129 | domReady['amd'] = true;
130 |
131 | return domReady;
132 |
133 | });
134 |
135 | }(this, this.document));
136 |
--------------------------------------------------------------------------------
/src/curl/loader/cjsm11.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl CommonJS Modules/1.1 loader
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | */
9 |
10 | /**
11 | * @experimental
12 | */
13 | (function (global, document, globalEval) {
14 |
15 | define(/*=='curl/loader/cjsm11',==*/ function () {
16 |
17 | var head, insertBeforeEl /*, findRequiresRx, myId*/;
18 |
19 | // findRequiresRx = /require\s*\(\s*['"](\w+)['"]\s*\)/,
20 |
21 | // function nextId (index) {
22 | // var varname = '', part;
23 | // do {
24 | // part = index % 26;
25 | // varname += String.fromCharCode(part + 65);
26 | // index -= part;
27 | // }
28 | // while (index > 0);
29 | // return 'curl$' + varname;
30 | // }
31 |
32 | // /**
33 | // * @description Finds the require() instances in the source text of a cjs
34 | // * module and collects them. If removeRequires is true, it also replaces
35 | // * them with a unique variable name. All unique require()'d module ids
36 | // * are assigned a unique variable name to be used in the define(deps)
37 | // * that will be constructed to wrap the cjs module.
38 | // * @param source - source code of cjs module
39 | // * @param moduleIds - hashMap (object) to receive pairs of moduleId /
40 | // * unique variable name
41 | // * @param removeRequires - if truthy, replaces all require() instances with
42 | // * a unique variable
43 | // * @return - source code of cjs module, possibly with require()s replaced
44 | // */
45 | // function parseDepModuleIds (source, moduleIds, removeRequires) {
46 | // var index = 0;
47 | // // fast parse
48 | // source = source.replace(findRequiresRx, function (match, id) {
49 | // if (!moduleIds[id]) {
50 | // moduleIds[id] = nextId(index++);
51 | // moduleIds.push(id);
52 | // }
53 | // return removeRequires ? moduleIds[id] : match;
54 | // });
55 | // return source;
56 | // }
57 |
58 | head = document && (document['head'] || document.getElementsByTagName('head')[0]);
59 | // to keep IE from crying, we need to put scripts before any
60 | // elements, but after any . this should do it:
61 | insertBeforeEl = head && head.getElementsByTagName('base')[0] || null;
62 |
63 | function wrapSource (source, resourceId, fullUrl) {
64 | var sourceUrl = fullUrl ? '////@ sourceURL=' + fullUrl.replace(/\s/g, '%20') + '.js' : '';
65 | return "define('" + resourceId + "'," +
66 | "['require','exports','module'],function(require,exports,module){" +
67 | source + "\n});\n" + sourceUrl + "\n";
68 | }
69 |
70 | var injectSource = function (el, source) {
71 | // got this from Stoyan Stefanov (http://www.phpied.com/dynamic-script-and-style-elements-in-ie/)
72 | injectSource = ('text' in el) ?
73 | function (el, source) { el.text = source; } :
74 | function (el, source) { el.appendChild(document.createTextNode(source)); };
75 | injectSource(el, source);
76 | };
77 |
78 | function injectScript (source) {
79 | var el = document.createElement('script');
80 | injectSource(el, source);
81 | el.charset = 'utf-8';
82 | head.insertBefore(el, insertBeforeEl);
83 | }
84 |
85 | return {
86 | 'load': function (resourceId, require, callback, config) {
87 | // TODO: extract xhr from text! plugin and use that instead (after we upgrade to cram.js)
88 | require(['text!' + resourceId + '.js', 'curl/_privileged'], function (source, priv) {
89 | var moduleMap;
90 |
91 | // find (and replace?) dependencies
92 | moduleMap = priv['core'].extractCjsDeps(source);
93 | //source = parseDepModuleIds(source, moduleMap, config.replaceRequires);
94 |
95 | // get deps
96 | require(moduleMap, function () {
97 |
98 | // wrap source in a define
99 | source = wrapSource(source, resourceId, config['injectSourceUrl'] !== false && require.toUrl(resourceId));
100 |
101 | if (config['injectScript']) {
102 | injectScript(source);
103 | }
104 | else {
105 | //eval(source);
106 | globalEval(source);
107 | }
108 |
109 | // call callback now that the module is defined
110 | callback(require(resourceId));
111 |
112 | }, callback['error'] || function (ex) { throw ex; });
113 |
114 | });
115 | }
116 | };
117 |
118 | });
119 |
120 | }(this, this.document, function () { /* FB needs direct eval here */ eval(arguments[0]); }));
121 |
--------------------------------------------------------------------------------
/test/tdd-runner.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | tdd runner test
5 |
6 |
15 |
16 |
17 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
--------------------------------------------------------------------------------
/test/packages.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Packages test
5 |
6 |
15 |
16 |
17 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
--------------------------------------------------------------------------------
/src/curl/plugin/builder/css.js:
--------------------------------------------------------------------------------
1 | /** MIT License (c) copyright B Cavalier & J Hann */
2 |
3 | /**
4 | * curl css! plugin build-time module
5 | *
6 | * Licensed under the MIT License at:
7 | * http://www.opensource.org/licenses/mit-license.php
8 | */
9 | define(function () {
10 | "use strict";
11 |
12 | // collection of modules that have been written to the built file
13 | var built = {};
14 |
15 | function nameWithExt (name, defaultExt) {
16 | return name.lastIndexOf('.') <= name.lastIndexOf('/') ?
17 | name + '.' + defaultExt : name;
18 | }
19 |
20 | function jsEncode (text) {
21 | // TODO: hoist the map and regex to the enclosing scope for better performance
22 | var map = { 34: '\\"', 13: '\\r', 12: '\\f', 10: '\\n', 9: '\\t', 8: '\\b' };
23 | return text.replace(/(["\n\f\t\r\b])/g, function (c) {
24 | return map[c.charCodeAt(0)];
25 | });
26 | }
27 |
28 | function parseSuffixes (name) {
29 | // creates a dual-structure: both an array and a hashmap
30 | // suffixes[0] is the actual name
31 | var parts = name.split('!'),
32 | suf, i = 1, pair;
33 | while ((suf = parts[i++])) { // double-parens to avoid jslint griping
34 | pair = suf.split('=', 2);
35 | parts[pair[0]] = pair.length == 2 ? pair[1] : true;
36 | }
37 | return parts;
38 | }
39 |
40 | var
41 | // this actually tests for absolute urls and root-relative urls
42 | // they're both non-relative
43 | nonRelUrlRe = /^\/|^[^:]*:\/\//,
44 | // Note: this will fail if there are parentheses in the url
45 | findUrlRx = /url\s*\(['"]?([^'"\)]*)['"]?\)/g;
46 |
47 | function translateUrls (cssText, baseUrl) {
48 | return cssText.replace(findUrlRx, function (all, url) {
49 | return 'url("' + translateUrl(url, baseUrl) + '")';
50 | });
51 | }
52 |
53 | function translateUrl (url, parentPath) {
54 | // if this is a relative url
55 | if (!nonRelUrlRe.test(url)) {
56 | // append path onto it
57 | url = parentPath + url;
58 | }
59 | return url;
60 | }
61 |
62 | function createSheetProxy (sheet) {
63 | return {
64 | cssRules: function () {
65 | return sheet.cssRules || sheet.rules;
66 | },
67 | insertRule: sheet.insertRule || function (text, index) {
68 | var parts = text.split(/\{|\}/g);
69 | sheet.addRule(parts[0], parts[1], index);
70 | return index;
71 | },
72 | deleteRule: sheet.deleteRule || function (index) {
73 | sheet.removeRule(index);
74 | return index;
75 | },
76 | sheet: function () {
77 | return sheet;
78 | }
79 | };
80 | }
81 |
82 | /***** style element functions *****/
83 |
84 | var currentStyle;
85 |
86 | function createStyle (cssText) {
87 | clearTimeout(createStyle.debouncer);
88 | if (createStyle.accum) {
89 | createStyle.accum.push(cssText);
90 | }
91 | else {
92 | createStyle.accum = [cssText];
93 | currentStyle = doc.createStyleSheet ? doc.createStyleSheet() :
94 | head.appendChild(doc.createElement('style'));
95 | }
96 |
97 | createStyle.debouncer = setTimeout(function () {
98 | // Note: IE 6-8 won't accept the W3C method for inserting css text
99 | var style, allCssText;
100 |
101 | style = currentStyle;
102 | currentStyle = undef;
103 |
104 | allCssText = createStyle.accum.join('\n');
105 | createStyle.accum = undef;
106 |
107 | // for safari which chokes on @charset "UTF-8";
108 | allCssText = allCssText.replace(/.+charset[^;]+;/g, '');
109 |
110 | // TODO: hoist all @imports to the top of the file to follow w3c spec
111 |
112 | 'cssText' in style ? style.cssText = allCssText :
113 | style.appendChild(doc.createTextNode(allCssText));
114 |
115 | }, 0);
116 |
117 | return currentStyle;
118 | }
119 |
120 | /*
121 | // return the run-time API
122 | callback({
123 | 'translateUrls': function (cssText, baseId) {
124 | var baseUrl;
125 | baseUrl = require['toUrl'](baseId);
126 | baseUrl = baseUrl.substr(0, baseUrl.lastIndexOf('/') + 1);
127 | return translateUrls(cssText, baseUrl);
128 | },
129 | 'injectStyle': function (cssText) {
130 | return createStyle(cssText);
131 | },
132 |
133 | 'proxySheet': function (sheet) {
134 | // for W3C, `sheet` is a reference to a