summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/static/js/branch.js
blob: bd214975f8b1de58cb21d8c93fa9053f99eda7a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

(function() {

function init() {
  var branchChooser = document.getElementById('branch-chooser-popup');
  Array.prototype.forEach.call(branchChooser.getElementsByTagName('button'),
                               function(button) {
    button.addEventListener('click', function(event) {
      choose(button.className);
      event.stopPropagation();
    });
  });
}

function choose(branch) {
  var currentBranch = window.bootstrap.branchInfo.current;
  var path = window.location.pathname.split('/');
  if (path[0] == '')
    path = path.slice(1);
  var index = path.indexOf(currentBranch);
  if (index != -1)
    path[index] = branch;
  else
    path.splice(0, 0, branch);
  window.location.pathname = '/' + path.join('/');
}

init();

})()