1;(function(window) {
2  'use strict';
3
4  /** The base path of the lodash builds. */
5  var basePath = '../';
6
7  /** The lodash build to load. */
8  var build = (build = /build=([^&]+)/.exec(location.search)) && decodeURIComponent(build[1]);
9
10  /** The module loader to use. */
11  var loader = (loader = /loader=([^&]+)/.exec(location.search)) && decodeURIComponent(loader[1]);
12
13  /** The `ui` object. */
14  var ui = {};
15
16  /*--------------------------------------------------------------------------*/
17
18  // Initialize controls.
19  addEventListener('load', function() {
20    function eventHandler(event) {
21      var buildIndex = buildList.selectedIndex,
22          loaderIndex = loaderList.selectedIndex,
23          search = location.search.replace(/^\?|&?(?:build|loader)=[^&]*&?/g, '');
24
25      if (event.stopPropagation) {
26        event.stopPropagation();
27      } else {
28        event.cancelBubble = true;
29      }
30      location.href =
31        location.href.split('?')[0] + '?' +
32        (search ? search + '&' : '') +
33        'build=' + (buildIndex < 0 ? build : buildList[buildIndex].value) + '&' +
34        'loader=' + (loaderIndex < 0 ? loader : loaderList[loaderIndex].value);
35    }
36
37    function init() {
38      var toolbar = document.getElementById('qunit-testrunner-toolbar');
39      if (!toolbar) {
40        setTimeout(init, 15);
41        return;
42      }
43      toolbar.insertBefore(span2, toolbar.lastChild);
44      toolbar.insertBefore(span1, span2);
45
46      buildList.selectedIndex = (function() {
47        switch (build) {
48          case 'lodash':            return 1;
49          case 'lodash-core-dev':   return 2;
50          case 'lodash-core':       return 3;
51          case 'lodash-dev':
52          case null:                return 0;
53        }
54        return -1;
55      }());
56
57      loaderList.selectedIndex = (function() {
58        switch (loader) {
59          case 'curl':      return 1;
60          case 'dojo':      return 2;
61          case 'requirejs': return 3;
62          case 'none':
63          case null:        return 0;
64        }
65        return -1;
66      }());
67
68      buildList.addEventListener('change', eventHandler);
69      loaderList.addEventListener('change', eventHandler);
70    }
71
72    var span1 = document.createElement('span');
73    span1.innerHTML =
74      '<label for="qunit-build">Build: </label>' +
75      '<select id="qunit-build">' +
76      '<option value="lodash-dev">lodash (development)</option>' +
77      '<option value="lodash">lodash (production)</option>' +
78      '<option value="lodash-core-dev">lodash-core (development)</option>' +
79      '<option value="lodash-core">lodash-core (production)</option>' +
80      '</select>';
81
82    var span2 = document.createElement('span');
83    span2.innerHTML =
84      '<label for="qunit-loader">Loader: </label>' +
85      '<select id="qunit-loader">' +
86      '<option value="none">None</option>' +
87      '<option value="curl">Curl</option>' +
88      '<option value="dojo">Dojo</option>' +
89      '<option value="requirejs">RequireJS</option>' +
90      '</select>';
91
92    span1.style.cssText =
93    span2.style.cssText = 'display:inline-block;float:right;line-height:2.1em;margin-left:1em;margin-top:0;';
94
95    span1.firstChild.style.cssText =
96    span2.firstChild.style.cssText = 'display:inline-block;margin-right:.5em;';
97
98    var buildList = span1.lastChild,
99        loaderList = span2.lastChild;
100
101    setTimeout(function() {
102      ui.timing.loadEventEnd = +new Date;
103    }, 1);
104
105    init();
106  });
107
108  // The lodash build file path.
109  ui.buildPath = (function() {
110    var result;
111    switch (build) {
112      case 'lodash':            result = 'dist/lodash.min.js'; break;
113      case 'lodash-core-dev':   result = 'dist/lodash.core.js'; break;
114      case 'lodash-core':       result = 'dist/lodash.core.min.js'; break;
115      case null:                build  = 'lodash-dev';
116      case 'lodash-dev':        result = 'lodash.js'; break;
117      default:                  return build;
118    }
119    return basePath + result;
120  }());
121
122  // The module loader file path.
123  ui.loaderPath = (function() {
124    var result;
125    switch (loader) {
126      case 'curl':      result = 'node_modules/curl-amd/dist/curl-kitchen-sink/curl.js'; break;
127      case 'dojo':      result = 'node_modules/dojo/dojo.js'; break;
128      case 'requirejs': result = 'node_modules/requirejs/require.js'; break;
129      case null:        loader = 'none'; return '';
130      default:          return loader;
131    }
132    return basePath + result;
133  }());
134
135  // Used to indicate testing a core build.
136  ui.isCore = /\bcore(\.min)?\.js\b/.test(ui.buildPath);
137
138  // Used to indicate testing a foreign file.
139  ui.isForeign = RegExp('^(\\w+:)?//').test(build);
140
141  // Used to indicate testing a modularized build.
142  ui.isModularize = /\b(?:amd|commonjs|es|node|npm|(index|main)\.js)\b/.test([location.pathname, location.search]);
143
144  // Used to indicate testing in Sauce Labs' automated test cloud.
145  ui.isSauceLabs = location.port == '9001';
146
147  // Used to indicate that lodash is in strict mode.
148  ui.isStrict = /\bes\b/.test([location.pathname, location.search]);
149
150  ui.urlParams = { 'build': build, 'loader': loader };
151  ui.timing = { 'loadEventEnd': 0 };
152
153  window.ui = ui;
154
155}(this));
156