3.0 source code
This commit is contained in:
4
OfficeWeb/vendor/requirejs/tests/plugins/fromText/a.refine
vendored
Normal file
4
OfficeWeb/vendor/requirejs/tests/plugins/fromText/a.refine
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
//The refine plugin changes the word refine into define.
|
||||
refine({
|
||||
name: 'a'
|
||||
});
|
||||
7
OfficeWeb/vendor/requirejs/tests/plugins/fromText/b.refine
vendored
Normal file
7
OfficeWeb/vendor/requirejs/tests/plugins/fromText/b.refine
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
//The refine plugin changes the word refine into define.
|
||||
refine(function (require, exports, module) {
|
||||
return {
|
||||
name: 'b',
|
||||
color: module.config().color
|
||||
};
|
||||
});
|
||||
18
OfficeWeb/vendor/requirejs/tests/plugins/fromText/fromText-tests.js
vendored
Normal file
18
OfficeWeb/vendor/requirejs/tests/plugins/fromText/fromText-tests.js
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
require({
|
||||
baseUrl: requirejs.isBrowser ? './' : './plugins/fromText',
|
||||
paths: {
|
||||
'text': '../../../../text/text'
|
||||
}
|
||||
}, ['refine!a'],
|
||||
function (a) {
|
||||
|
||||
doh.register(
|
||||
'pluginsFromText',
|
||||
[
|
||||
function pluginsFromText(t){
|
||||
t.is('a', a.name);
|
||||
}
|
||||
]
|
||||
);
|
||||
doh.run();
|
||||
});
|
||||
13
OfficeWeb/vendor/requirejs/tests/plugins/fromText/fromText.html
vendored
Normal file
13
OfficeWeb/vendor/requirejs/tests/plugins/fromText/fromText.html
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>require.js: fromText Plugin 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="fromText-tests.js" src="../../../require.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>require.js: fromText Plugin Test</h1>
|
||||
<p>Check console for messages</p>
|
||||
</body>
|
||||
</html>
|
||||
38
OfficeWeb/vendor/requirejs/tests/plugins/fromText/fromTextConfig-tests.js
vendored
Normal file
38
OfficeWeb/vendor/requirejs/tests/plugins/fromText/fromTextConfig-tests.js
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
require({
|
||||
baseUrl: requirejs.isBrowser ? './' : './plugins/fromText',
|
||||
paths: {
|
||||
'text': '../../../../text/text'
|
||||
},
|
||||
config: {
|
||||
'refine!b': {
|
||||
color: 'blue'
|
||||
},
|
||||
'refine!c': {
|
||||
color: 'cyan'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//The refine plugin changes the word refine into define.
|
||||
define('refine!c', function (require, exports, module) {
|
||||
return {
|
||||
name: 'c',
|
||||
color: module.config().color
|
||||
};
|
||||
});
|
||||
|
||||
require(['refine!b', 'refine!c'], function (b, c) {
|
||||
|
||||
doh.register(
|
||||
'pluginsFromTextConfig',
|
||||
[
|
||||
function pluginsFromTextConfig(t){
|
||||
t.is('b', b.name);
|
||||
t.is('blue', b.color);
|
||||
t.is('c', c.name);
|
||||
t.is('cyan', c.color);
|
||||
}
|
||||
]
|
||||
);
|
||||
doh.run();
|
||||
});
|
||||
15
OfficeWeb/vendor/requirejs/tests/plugins/fromText/fromTextConfig.html
vendored
Normal file
15
OfficeWeb/vendor/requirejs/tests/plugins/fromText/fromTextConfig.html
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>require.js: fromText Config 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="fromTextConfig-tests.js" src="../../../require.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>require.js: fromText Config Test</h1>
|
||||
<p>Make sure built fromText modules get config values same as non-built
|
||||
case. <a href="https://github.com/jrburke/requirejs/issues/538">More info</a>.
|
||||
<p>Check console for messages</p>
|
||||
</body>
|
||||
</html>
|
||||
157
OfficeWeb/vendor/requirejs/tests/plugins/fromText/refine.js
vendored
Normal file
157
OfficeWeb/vendor/requirejs/tests/plugins/fromText/refine.js
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
|
||||
/*jslint strict: false, plusplus: false */
|
||||
/*global define: false, require: false, XMLHttpRequest: false, ActiveXObject: false,
|
||||
window: false, Packages: false, java: false, process: false, Components, FileUtils */
|
||||
|
||||
(function () {
|
||||
//Load the text plugin, so that the XHR calls can be made.
|
||||
var buildMap = {}, fetchText, fs, Cc, Ci,
|
||||
progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
|
||||
|
||||
function createXhr() {
|
||||
//Would love to dump the ActiveX crap in here. Need IE 6 to die first.
|
||||
var xhr, i, progId;
|
||||
if (typeof XMLHttpRequest !== "undefined") {
|
||||
return new XMLHttpRequest();
|
||||
} else {
|
||||
for (i = 0; i < 3; i++) {
|
||||
progId = progIds[i];
|
||||
try {
|
||||
xhr = new ActiveXObject(progId);
|
||||
} catch (e) {}
|
||||
|
||||
if (xhr) {
|
||||
progIds = [progId]; // so faster next time
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!xhr) {
|
||||
throw new Error("require.getXhr(): XMLHttpRequest not available");
|
||||
}
|
||||
|
||||
return xhr;
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined" && window.navigator && window.document) {
|
||||
fetchText = function (url, callback) {
|
||||
var xhr = createXhr();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.onreadystatechange = function (evt) {
|
||||
//Do not explicitly handle errors, those should be
|
||||
//visible via console output in the browser.
|
||||
if (xhr.readyState === 4) {
|
||||
callback(xhr.responseText);
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
};
|
||||
} else if (typeof process !== "undefined" &&
|
||||
process.versions &&
|
||||
!!process.versions.node) {
|
||||
//Using special require.nodeRequire, something added by r.js.
|
||||
fs = require.nodeRequire('fs');
|
||||
|
||||
fetchText = function (url, callback) {
|
||||
callback(fs.readFileSync(url, 'utf8'));
|
||||
};
|
||||
} else if (typeof Packages !== 'undefined') {
|
||||
//Why Java, why is this so awkward?
|
||||
fetchText = function (url, callback) {
|
||||
var encoding = "utf-8",
|
||||
file = new java.io.File(url),
|
||||
lineSeparator = java.lang.System.getProperty("line.separator"),
|
||||
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), encoding)),
|
||||
stringBuffer, line,
|
||||
content = '';
|
||||
try {
|
||||
stringBuffer = new java.lang.StringBuffer();
|
||||
line = input.readLine();
|
||||
|
||||
// Byte Order Mark (BOM) - The Unicode Standard, version 3.0, page 324
|
||||
// http://www.unicode.org/faq/utf_bom.html
|
||||
|
||||
// Note that when we use utf-8, the BOM should appear as "EF BB BF", but it doesn't due to this bug in the JDK:
|
||||
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4508058
|
||||
if (line && line.length() && line.charAt(0) === 0xfeff) {
|
||||
// Eat the BOM, since we've already found the encoding on this file,
|
||||
// and we plan to concatenating this buffer with others; the BOM should
|
||||
// only appear at the top of a file.
|
||||
line = line.substring(1);
|
||||
}
|
||||
|
||||
stringBuffer.append(line);
|
||||
|
||||
while ((line = input.readLine()) !== null) {
|
||||
stringBuffer.append(lineSeparator);
|
||||
stringBuffer.append(line);
|
||||
}
|
||||
//Make sure we return a JavaScript string and not a Java string.
|
||||
content = String(stringBuffer.toString()); //String
|
||||
} finally {
|
||||
input.close();
|
||||
}
|
||||
callback(content);
|
||||
};
|
||||
} else if (typeof Components !== 'undefined' && Components.classes &&
|
||||
Components.interfaces) {
|
||||
//Avert your gaze!
|
||||
Cc = Components.classes,
|
||||
Ci = Components.interfaces;
|
||||
Components.utils['import']('resource://gre/modules/FileUtils.jsm');
|
||||
|
||||
fetchText = function (url, callback) {
|
||||
var inStream, convertStream,
|
||||
readData = {},
|
||||
fileObj = new FileUtils.File(url);
|
||||
|
||||
//XPCOM, you so crazy
|
||||
try {
|
||||
inStream = Cc['@mozilla.org/network/file-input-stream;1']
|
||||
.createInstance(Ci.nsIFileInputStream);
|
||||
inStream.init(fileObj, 1, 0, false);
|
||||
|
||||
convertStream = Cc['@mozilla.org/intl/converter-input-stream;1']
|
||||
.createInstance(Ci.nsIConverterInputStream);
|
||||
convertStream.init(inStream, "utf-8", inStream.available(),
|
||||
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
|
||||
|
||||
convertStream.readString(inStream.available(), readData);
|
||||
convertStream.close();
|
||||
inStream.close();
|
||||
callback(readData.value);
|
||||
} catch (e) {
|
||||
throw new Error((fileObj && fileObj.path || '') + ': ' + e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
define(function () {
|
||||
return {
|
||||
load: function (name, parentRequire, load, config) {
|
||||
var url = parentRequire.toUrl(name + '.refine');
|
||||
fetchText(url, function (text) {
|
||||
text = text.replace(/refine\s*\(/g, 'define(');
|
||||
|
||||
if (config.isBuild) {
|
||||
buildMap[name] = text;
|
||||
}
|
||||
|
||||
//Add in helpful debug line
|
||||
text += "\r\n//@ sourceURL=" + url;
|
||||
|
||||
load.fromText(text);
|
||||
});
|
||||
},
|
||||
|
||||
write: function (pluginName, name, write) {
|
||||
if (name in buildMap) {
|
||||
var text = buildMap[name];
|
||||
write.asModule(pluginName + "!" + name, text);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
}());
|
||||
Reference in New Issue
Block a user