3.0 source code

This commit is contained in:
agolybev
2015-04-28 17:59:00 +03:00
parent c69fd34bdd
commit 7b3b2248e5
16311 changed files with 1445974 additions and 3108429 deletions

View File

@@ -0,0 +1,5 @@
define(['text!./resources/local.html'], function (localHtml) {
return {
localHtml: localHtml
}
});

View File

@@ -0,0 +1 @@
hello world

View File

@@ -0,0 +1 @@
<h1>Local</h1>

View File

@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title>sample.html</title>
<script type="text/javascript" src="../require.js"></script>
</head>
<body class="foo" onload="alert('hello')"><span>Hello World!</span></body>
</html>

View File

@@ -0,0 +1,2 @@
//Stub file for testing optimization of all plugin resources in a build.
define(['text!resources/sample.html!strip'], function () {});

View File

@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title>sample.html</title>
<script type="text/javascript" src="../require.js"></script>
</head>
<body class="foo" onload="alert('hello')"><div data-type="subwidget"><h1>This is a subwidget</h1></div></body>
</html>

View File

@@ -0,0 +1,10 @@
define("subwidget",
["text!subwidget.html!strip", "text!subwidget2.html"],
function(template, template2) {
return {
name: "subwidget",
template: template,
template2: template2
};
}
);

View File

@@ -0,0 +1 @@
<span>This! is template2</span>

View File

@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Text Test</title>
<script type="text/javascript" src="../../require.js"></script>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript">
require({
baseUrl: "./",
paths: {
text: "../../../text/text"
} //, priority: ['widgetlayer']
});
require(
["require", "widget", "local", "text!resources/sample.html!strip"],
function(require, widget, local, sampleText) {
doh.register(
"text",
[
function text(t){
t.is("<span>Hello World!</span>", sampleText);
t.is('<div data-type="widget"><h1>This is a widget!</h1><p>I am in a widget</p></div>', widget.template);
t.is('subwidget', widget.subWidgetName);
t.is('<div data-type="subwidget"><h1>This is a subwidget</h1></div>', widget.subWidgetTemplate);
t.is('<span>This! is template2</span>', widget.subWidgetTemplate2);
t.is('<h1>Local</h1>', local.localHtml);
},
function textLocalXhr(t){
var text = require('text');
t.is(true, text.useXhr('./some/thing.html', 'http', 'some.domain.com'));
t.is(false, text.useXhr('https://some.domain.com/some/thing.html', 'http', 'some.domain.com'));
t.is(false, text.useXhr('http://domain.com/some/thing.html', 'http', 'some.domain.com'));
t.is(true, text.useXhr('//some.domain.com/some/thing.html', 'http', 'some.domain.com'));
t.is(true, text.useXhr('https://some.domain.com:444/some/thing.html', 'https', 'some.domain.com', '444'));
t.is(false, text.useXhr('https://some.domain.com/some/thing.html', 'https', 'some.domain.com', '444'));
t.is(true, text.useXhr('http://localhost/some/thing.html', 'http', 'localhost'));
}
]
);
doh.run();
}
);
</script>
</head>
<body>
<h1>require.js: Text Test</h1>
<p>Test for usage of text! require plugin.
<p>Check console for messages</p>
</body>
</html>

View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Text Built Test</title>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript" data-main="textBuilt" src="../../require.js"></script>
</head>
<body>
<h1>require.js: Text Built Test</h1>
<p>Test for usage of text! require plugin in a build scenario where text resources are inlined.
<p>Check console for messages</p>
</body>
</html>

View File

@@ -0,0 +1,64 @@
(function () {
define('text',[],function () {
var text = {
load: function (name, req, onLoad, config) {
throw "THE TEXT PLUGIN LOAD() FUNCTION SHOULD NOT BE CALLED";
}
};
return text;
});
}());
define('text!subwidget.html!strip', function () { return '<div data-type="subwidget"><h1>This is a subwidget</h1></div>';});
define('text!subwidget2.html', function () { return '<span>This! is template2</span>';});
define("subwidget",
["text!subwidget.html!strip", "text!subwidget2.html"],
function(template, template2) {
return {
name: "subwidget",
template: template,
template2: template2
};
}
);
define('text!widget.html', function () { return '<div data-type="widget"><h1>This is a widget!</h1><p>I am in a widget</p></div>';});
define("widget",
["subwidget", "text!widget.html"],
function(subwidget, template) {
return {
subWidgetName: subwidget.name,
subWidgetTemplate: subwidget.template,
subWidgetTemplate2: subwidget.template2,
template: template
};
}
);
/****************** TEST CODE IS BELOW ******************/
require({
baseUrl: "./",
paths: {
text: "../../../text/text"
}
});
require(
["widget"],
function(widget) {
doh.register(
"text",
[
function text(t){
t.is('<div data-type="widget"><h1>This is a widget!</h1><p>I am in a widget</p></div>', widget.template);
t.is('subwidget', widget.subWidgetName);
t.is('<div data-type="subwidget"><h1>This is a subwidget</h1></div>', widget.subWidgetTemplate);
t.is('<span>This! is template2</span>', widget.subWidgetTemplate2);
}
]
);
doh.run();
}
);

View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Text onError Test</title>
<script type="text/javascript" src="../../require.js"></script>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript">
require({
baseUrl: "./",
paths: {
text: "../../../text/text"
}
});
var master = new doh.Deferred();
doh.register(
"textOnError",
[
{
name: "textOnError",
timeout: 2000,
runTest: function () {
return master;
}
}
]
);
doh.run();
require(
["text!doesnotexist.html"],
function(doesNotExist) {
doh.is(false, true, "This should not fire");
master.callback(false);
}, function (err) {
doh.is(404, err.xhr.status);
master.callback(true);
}
);
</script>
</head>
<body>
<h1>require.js: Text Test</h1>
<p>Test for text! plugin triggering an error.
<p>Check console for messages</p>
</body>
</html>

View File

@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Text onXhr Test</title>
<script type="text/javascript" src="../../require.js"></script>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript">
var fired = false;
require({
baseUrl: "./",
paths: {
text: "../../../text/text"
},
config: {
text: {
onXhr: function (xhr, url) {
doh.is(true, !!xhr);
doh.is(true, url.indexOf('plain.txt') !== -1);
fired = true;
if (/\.txt$/.test(url) && xhr.overrideMimeType) {
xhr.overrideMimeType('text/plain; charset=utf8');
}
}
}
}
});
require(
["text!plain.txt"],
function(plainText) {
doh.register(
"textonXhr",
[
function textOnXhr(t){
t.is(true, plainText.indexOf('hello world') === 0);
t.is(true, fired);
}
]
);
doh.run();
}
);
</script>
</head>
<body>
<h1>require.js: Text onXhr Test</h1>
<p>Test onXhr for the text plugin.
<p>Check console for messages</p>
</body>
</html>

View File

@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js: Text Test</title>
<script type="text/javascript" src="../../require.js"></script>
<script type="text/javascript" src="../doh/runner.js"></script>
<script type="text/javascript" src="../doh/_browserRunner.js"></script>
<script type="text/javascript">
require({
baseUrl: "./",
paths: {
text: "../../../text/text"
}
},
["text!resources/sample.html!strip"],
function(sampleText) {
doh.register(
"textOnly",
[
function textOnly(t){
t.is("<span>Hello World!</span>", sampleText);
}
]
);
doh.run();
}
);
</script>
</head>
<body>
<h1>require.js: Text Test</h1>
<p>Test for usage of text! require plugin.
<p>Check console for messages</p>
</body>
</html>

View File

@@ -0,0 +1 @@
<div data-type="widget"><h1>This is a widget!</h1><p>I am in a widget</p></div>

View File

@@ -0,0 +1,11 @@
define("widget",
["subwidget", "text!widget.html"],
function(subwidget, template) {
return {
subWidgetName: subwidget.name,
subWidgetTemplate: subwidget.template,
subWidgetTemplate2: subwidget.template2,
template: template
};
}
);