mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +00:00
Make test/underscore.html support the modularize option and cleanup test/index.html.
Former-commit-id: 98ab3a50a58f27508208655a983a9cd96d99f965
This commit is contained in:
@@ -52,9 +52,18 @@
|
|||||||
}
|
}
|
||||||
window.require && require(
|
window.require && require(
|
||||||
(function() {
|
(function() {
|
||||||
var modulePath = ui.buildPath.replace(/\.js$/, '');
|
var reModularize = /modularize/;
|
||||||
|
|
||||||
|
var baseUrl = reModularize.test(ui.urlParams.build)
|
||||||
|
? '../modularize/'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
var modulePath = reModularize.test(ui.urlParams.build)
|
||||||
|
? 'lodash'
|
||||||
|
: ui.buildPath.replace(/\.js$/, '');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'baseUrl': (/modularize/.test(ui.urlParams.build) ? 'modularize/' : ''),
|
'baseUrl': baseUrl,
|
||||||
'urlArgs': 't=' + (+new Date),
|
'urlArgs': 't=' + (+new Date),
|
||||||
'paths': {
|
'paths': {
|
||||||
'lodash': modulePath,
|
'lodash': modulePath,
|
||||||
|
|||||||
@@ -19,34 +19,31 @@
|
|||||||
</div>
|
</div>
|
||||||
<img id="chart_image" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==">
|
<img id="chart_image" src="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==">
|
||||||
</div>
|
</div>
|
||||||
|
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||||
<script src="../vendor/jquery/jquery.js"></script>
|
<script src="../vendor/jquery/jquery.js"></script>
|
||||||
<script src="../vendor/platform.js/platform.js"></script>
|
<script src="../vendor/platform.js/platform.js"></script>
|
||||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
|
||||||
<script src="test-ui.js"></script>
|
<script src="test-ui.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.write('<script src="../' + ui.buildPath + '"><\/script>');
|
function init(lodash) {
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
(function() {
|
|
||||||
var arrayProto = Array.prototype,
|
var arrayProto = Array.prototype,
|
||||||
concat = arrayProto.concat,
|
concat = arrayProto.concat,
|
||||||
pop = arrayProto.pop,
|
pop = arrayProto.pop,
|
||||||
push = arrayProto.push,
|
push = arrayProto.push,
|
||||||
slice = arrayProto.slice;
|
slice = arrayProto.slice;
|
||||||
|
|
||||||
if (_.chain().__chain__) {
|
if (lodash.chain && lodash.chain().__chain__) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_.mixin = function(object) {
|
lodash.mixin = function(object) {
|
||||||
_.forEach(_.functions(object), function(methodName) {
|
lodash.forEach(lodash.functions(object), function(methodName) {
|
||||||
var func = _[methodName] = object[methodName];
|
var func = lodash[methodName] = object[methodName];
|
||||||
_.prototype[methodName] = function() {
|
lodash.prototype[methodName] = function() {
|
||||||
var args = [this.__wrapped__];
|
var args = [this.__wrapped__];
|
||||||
push.apply(args, arguments);
|
push.apply(args, arguments);
|
||||||
|
|
||||||
var result = func.apply(_, args);
|
var result = func.apply(lodash, args);
|
||||||
if (this.__chain__) {
|
if (this.__chain__) {
|
||||||
result = new _(result);
|
result = new lodash(result);
|
||||||
result.__chain__ = true;
|
result.__chain__ = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -54,44 +51,93 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_.mixin(_);
|
lodash.mixin(lodash);
|
||||||
|
|
||||||
_.mixin({
|
lodash.chain = function(value) {
|
||||||
'findWhere': _.find
|
value = new lodash(value);
|
||||||
});
|
|
||||||
|
|
||||||
_.chain = function(value) {
|
|
||||||
value = new _(value);
|
|
||||||
value.__chain__ = true;
|
value.__chain__ = true;
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
_.prototype.chain = function() {
|
lodash.prototype.chain = function() {
|
||||||
this.__chain__ = true;
|
this.__chain__ = true;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
_.prototype.concat = function() {
|
lodash.prototype.concat = function() {
|
||||||
var result = concat.apply(this.__wrapped__, arguments);
|
var result = concat.apply(this.__wrapped__, arguments);
|
||||||
if (this.__chain__) {
|
if (this.__chain__) {
|
||||||
result = new _(result);
|
result = new lodash(result);
|
||||||
result.__chain__ = true;
|
result.__chain__ = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
_.prototype.pop = function() {
|
lodash.prototype.pop = function() {
|
||||||
pop.apply(this.__wrapped__, arguments);
|
pop.apply(this.__wrapped__, arguments);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
}());
|
|
||||||
|
// expose lodash
|
||||||
|
window._ = lodash;
|
||||||
|
}
|
||||||
|
|
||||||
|
// load Lo-Dash again to overwrite the existing `_` value
|
||||||
|
document.write('<script src="' + ui.buildPath + '"><\/script>');
|
||||||
|
|
||||||
|
// load test.js if not using require.js
|
||||||
|
document.write(ui.urlParams.loader != 'none'
|
||||||
|
? '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
|
||||||
|
: ([
|
||||||
|
'<script src="../vendor/underscore/test/collections.js"><\/script>',
|
||||||
|
'<script src="../vendor/underscore/test/arrays.js"><\/script>',
|
||||||
|
'<script src="../vendor/underscore/test/functions.js"><\/script>',
|
||||||
|
'<script src="../vendor/underscore/test/objects.js"><\/script>',
|
||||||
|
'<script src="../vendor/underscore/test/utility.js"><\/script>',
|
||||||
|
'<script src="../vendor/underscore/test/chaining.js"><\/script>'
|
||||||
|
].join('\n'))
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
if (window.curl) {
|
||||||
|
var require = curl;
|
||||||
|
}
|
||||||
|
if (!window.require) {
|
||||||
|
init(_);
|
||||||
|
}
|
||||||
|
// load Lo-Dash as a module
|
||||||
|
window.require && require(
|
||||||
|
(function() {
|
||||||
|
var reModularize = /modularize/;
|
||||||
|
|
||||||
|
var baseUrl = reModularize.test(ui.urlParams.build)
|
||||||
|
? '../modularize/'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
var modulePath = reModularize.test(ui.urlParams.build)
|
||||||
|
? 'lodash'
|
||||||
|
: ui.buildPath.replace(/\.js$/, '');
|
||||||
|
|
||||||
|
return {
|
||||||
|
'baseUrl': baseUrl,
|
||||||
|
'urlArgs': 't=' + (+new Date),
|
||||||
|
'paths': {
|
||||||
|
'lodash': modulePath
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}()),
|
||||||
|
['lodash'], function(lodash) {
|
||||||
|
init(lodash);
|
||||||
|
require([
|
||||||
|
'../vendor/underscore/test/collections.js',
|
||||||
|
'../vendor/underscore/test/arrays.js',
|
||||||
|
'../vendor/underscore/test/functions.js',
|
||||||
|
'../vendor/underscore/test/objects.js',
|
||||||
|
'../vendor/underscore/test/utility.js',
|
||||||
|
'../vendor/underscore/test/utility.js'
|
||||||
|
]);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<script src="../vendor/underscore/test/collections.js"></script>
|
|
||||||
<script src="../vendor/underscore/test/arrays.js"></script>
|
|
||||||
<script src="../vendor/underscore/test/functions.js"></script>
|
|
||||||
<script src="../vendor/underscore/test/objects.js"></script>
|
|
||||||
<script src="../vendor/underscore/test/utility.js"></script>
|
|
||||||
<script src="../vendor/underscore/test/chaining.js"></script>
|
|
||||||
<script type="text/html" id="template">
|
<script type="text/html" id="template">
|
||||||
<%
|
<%
|
||||||
// a comment
|
// a comment
|
||||||
|
|||||||
Reference in New Issue
Block a user