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 /** | |
6 * Redirects to the same page on a different branch. | |
7 * | |
8 * @param {String} The path to redirect to. | |
9 */ | |
10 (function() { | 5 (function() { |
11 function redirectToBranch(value) { | 6 function redirectToBranch() { |
| 7 var value = event.target.value; |
12 if (!value) | 8 if (!value) |
13 return; | 9 return; |
14 var path = window.location.pathname.split('/') | 10 var current_branch = window.bootstrap.branchInfo.current; |
15 window.location = value + '/' + path[path.length - 1]; | 11 var path = window.location.pathname.split('/'); |
| 12 var index = path.indexOf(current_branch); |
| 13 if (index != -1) |
| 14 path[index] = value; |
| 15 else |
| 16 path.splice(path.length - 1, 0, value); |
| 17 window.location = path.join('/'); |
16 } | 18 } |
17 | 19 |
18 window.redirectToBranch = redirectToBranch; | 20 document.getElementById('branchChooser').addEventListener( |
| 21 'change', |
| 22 redirectToBranch); |
19 })() | 23 })() |
OLD | NEW |