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 other library to load. */
11  var other = (other = /other=([^&]+)/.exec(location.search)) && decodeURIComponent(other[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          otherIndex = otherList.selectedIndex,
23          search = location.search.replace(/^\?|&?(?:build|other)=[^&]*&?/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        'other=' + (otherIndex < 0 ? other : otherList[otherIndex].value);
35    }
36
37    var span1 = document.createElement('span');
38    span1.style.cssText = 'float:right';
39    span1.innerHTML =
40      '<label for="perf-build">Build: </label>' +
41      '<select id="perf-build">' +
42      '<option value="lodash">lodash (production)</option>' +
43      '</select>';
44
45    var span2 = document.createElement('span');
46    span2.style.cssText = 'float:right';
47    span2.innerHTML =
48      '<label for="perf-other">Other Library: </label>' +
49      '<select id="perf-other">' +
50      '<option value="underscore-dev">Underscore (development)</option>' +
51      '<option value="underscore">Underscore (production)</option>' +
52      '<option value="lodash">lodash</option>' +
53      '</select>';
54
55    var buildList = span1.lastChild,
56        otherList = span2.lastChild,
57        toolbar = document.getElementById('perf-toolbar');
58
59    toolbar.appendChild(span2);
60    toolbar.appendChild(span1);
61
62    buildList.selectedIndex = (function() {
63      switch (build) {
64        case 'lodash':
65        case null:                return 0;
66      }
67      return -1;
68    }());
69
70    otherList.selectedIndex = (function() {
71      switch (other) {
72        case 'underscore-dev':    return 0;
73        case 'lodash':            return 2;
74        case 'underscore':
75        case null:                return 1;
76      }
77      return -1;
78    }());
79
80    buildList.addEventListener('change', eventHandler);
81    otherList.addEventListener('change', eventHandler);
82  });
83
84  // The lodash build file path.
85  ui.buildPath = (function() {
86    var result;
87    switch (build) {
88      case null:                build  = 'lodash';
89      case 'lodash':            result = 'dist/lodash.min.js'; break;
90      default:                  return build;
91    }
92    return basePath + result;
93  }());
94
95  // The other library file path.
96  ui.otherPath = (function() {
97    var result;
98    switch (other) {
99      case 'lodash':            result = 'dist/lodash.min.js'; break;
100      case 'underscore-dev':    result = 'vendor/underscore/underscore.js'; break;
101      case null:                other  = 'underscore';
102      case 'underscore':        result = 'vendor/underscore/underscore-min.js'; break;
103      default:                  return other;
104    }
105    return basePath + result;
106  }());
107
108  ui.urlParams = { 'build': build, 'other': other };
109
110  window.ui = ui;
111
112}(this));
113