OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function() { | 5 (function() { |
6 function redirectToBranch() { | 6 function redirectToBranch() { |
7 var value = event.target.value; | 7 var value = event.target.value; |
8 if (!value) | 8 if (!value) |
9 return; | 9 return; |
10 var current_branch = window.bootstrap.branchInfo.current; | 10 var current_branch = window.bootstrap.branchInfo.current; |
11 var path = window.location.pathname.split('/'); | 11 var path = window.location.pathname.split('/'); |
| 12 if (path[0] == '') |
| 13 path = path.slice(1); |
12 var index = path.indexOf(current_branch); | 14 var index = path.indexOf(current_branch); |
13 if (index != -1) | 15 if (index != -1) |
14 path[index] = value; | 16 path[index] = value; |
15 else | 17 else |
16 path.splice(path.length - 1, 0, value); | 18 path.splice(0, 0, value); |
17 window.location = path.join('/'); | 19 window.location = '/' + path.join('/'); |
18 } | 20 } |
19 | 21 |
20 document.getElementById('branchChooser').addEventListener( | 22 document.getElementById('branchChooser').addEventListener( |
21 'change', | 23 'change', |
22 redirectToBranch); | 24 redirectToBranch); |
23 })() | 25 })() |
OLD | NEW |