4 /** The base path of the lodash builds. */
7 /** The lodash build to load. */
8 var build = (build = /build=([^&]+)/.exec(location.search)) && decodeURIComponent(build[1]);
10 /** The module loader to use. */
11 var loader = (loader = /loader=([^&]+)/.exec(location.search)) && decodeURIComponent(loader[1]);
13 /** The `ui` object. */
16 /*--------------------------------------------------------------------------*/
19 * Registers an event listener on an element.
22 * @param {Element} element The element.
23 * @param {string} eventName The name of the event.
24 * @param {Function} handler The event handler.
25 * @returns {Element} The element.
27 function addListener(element, eventName, handler) {
28 if (typeof element.addEventListener != 'undefined') {
29 element.addEventListener(eventName, handler, false);
30 } else if (typeof element.attachEvent != 'undefined') {
31 element.attachEvent('on' + eventName, handler);
35 /*--------------------------------------------------------------------------*/
37 // Initialize controls.
38 addListener(window, 'load', function() {
39 function eventHandler(event) {
40 var buildIndex = buildList.selectedIndex,
41 loaderIndex = loaderList.selectedIndex,
42 search = location.search.replace(/^\?|&?(?:build|loader)=[^&]*&?/g, '');
44 if (event.stopPropagation) {
45 event.stopPropagation();
47 event.cancelBubble = true;
50 location.href.split('?')[0] + '?' +
51 (search ? search + '&' : '') +
52 'build=' + (buildIndex < 0 ? build : buildList[buildIndex].value) + '&' +
53 'loader=' + (loaderIndex < 0 ? loader : loaderList[loaderIndex].value);
57 var toolbar = document.getElementById('qunit-testrunner-toolbar');
62 toolbar.appendChild(span1);
63 toolbar.appendChild(span2);
65 buildList.selectedIndex = (function() {
67 case 'lodash': return 1;
68 case 'lodash-core-dev': return 2;
69 case 'lodash-core': return 3;
76 loaderList.selectedIndex = (function() {
78 case 'curl': return 1;
79 case 'dojo': return 2;
80 case 'requirejs': return 3;
87 addListener(buildList, 'change', eventHandler);
88 addListener(loaderList, 'change', eventHandler);
91 var span1 = document.createElement('span');
92 span1.style.cssText = 'float:right';
94 '<label for="qunit-build">Build: </label>' +
95 '<select id="qunit-build">' +
96 '<option value="lodash-dev">lodash (development)</option>' +
97 '<option value="lodash">lodash (production)</option>' +
98 '<option value="lodash-core-dev">lodash-core (development)</option>' +
99 '<option value="lodash-core">lodash-core (production)</option>' +
102 var span2 = document.createElement('span');
103 span2.style.cssText = 'float:right';
105 '<label for="qunit-loader">Loader: </label>' +
106 '<select id="qunit-loader">' +
107 '<option value="none">None</option>' +
108 '<option value="curl">Curl</option>' +
109 '<option value="dojo">Dojo</option>' +
110 '<option value="requirejs">RequireJS</option>' +
113 var buildList = span1.lastChild,
114 loaderList = span2.lastChild;
116 setTimeout(function() {
117 ui.timing.loadEventEnd = +new Date;
123 // The lodash build file path.
124 ui.buildPath = (function() {
127 case 'lodash': result = 'dist/lodash.min.js'; break;
128 case 'lodash-core-dev': result = 'dist/lodash.core.js'; break;
129 case 'lodash-core': result = 'dist/lodash.core.min.js'; break;
130 case null: build = 'lodash-dev';
131 case 'lodash-dev': result = 'lodash.js'; break;
132 default: return build;
134 return basePath + result;
137 // The module loader file path.
138 ui.loaderPath = (function() {
141 case 'curl': result = 'node_modules/curl-amd/dist/curl-kitchen-sink/curl.js'; break;
142 case 'dojo': result = 'node_modules/dojo/dojo.js'; break;
143 case 'requirejs': result = 'node_modules/requirejs/require.js'; break;
144 case null: loader = 'none'; return '';
145 default: return loader;
147 return basePath + result;
150 // Used to indicate testing a core build.
151 ui.isCore = /\bcore(\.min)?\.js\b/.test(ui.buildPath);
153 // Used to indicate testing a foreign file.
154 ui.isForeign = RegExp('^(\\w+:)?//').test(build);
156 // Used to indicate testing a modularized build.
157 ui.isModularize = /\b(?:amd|commonjs|es|node|npm|(index|main)\.js)\b/.test([location.pathname, location.search]);
159 // Used to indicate testing in Sauce Labs' automated test cloud.
160 ui.isSauceLabs = location.port == '9001';
162 // Used to indicate that lodash is in strict mode.
163 ui.isStrict = /\bes\b/.test([location.pathname, location.search]);
165 ui.urlParams = { 'build': build, 'loader': loader };
166 ui.timing = { 'loadEventEnd': 0 };