Commit a3b059af authored by cduvall@chromium.org's avatar cduvall@chromium.org

Extensions Docs Server: use addEventListener with branch.js

Clean up branch.js to use addEventListener.

BUG=131095

Review URL: https://chromiumcodereview.appspot.com/10828027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148773 0039d316-1c4b-4281-b951-d872f2087c98
parent c856bd3a
...@@ -2,18 +2,22 @@ ...@@ -2,18 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/**
* Redirects to the same page on a different branch.
*
* @param {String} The path to redirect to.
*/
(function() { (function() {
function redirectToBranch(value) { function redirectToBranch() {
var value = event.target.value;
if (!value) if (!value)
return; return;
var path = window.location.pathname.split('/') var current_branch = window.bootstrap.branchInfo.current;
window.location = value + '/' + path[path.length - 1]; var path = window.location.pathname.split('/');
var index = path.indexOf(current_branch);
if (index != -1)
path[index] = value;
else
path.splice(path.length - 1, 0, value);
window.location = path.join('/');
} }
window.redirectToBranch = redirectToBranch; document.getElementById('branchChooser').addEventListener(
'change',
redirectToBranch);
})() })()
...@@ -13,10 +13,10 @@ def _MakeBranchDict(branch): ...@@ -13,10 +13,10 @@ def _MakeBranchDict(branch):
return { return {
'showWarning': branch != 'stable', 'showWarning': branch != 'stable',
'branches': [ 'branches': [
{ 'name': 'Stable', 'path': EXTENSIONS_URL + '/stable' }, { 'name': 'Stable', 'path': 'stable' },
{ 'name': 'Dev', 'path': EXTENSIONS_URL + '/dev' }, { 'name': 'Dev', 'path': 'dev' },
{ 'name': 'Beta', 'path': EXTENSIONS_URL + '/beta' }, { 'name': 'Beta', 'path': 'beta' },
{ 'name': 'Trunk', 'path': EXTENSIONS_URL + '/trunk' } { 'name': 'Trunk', 'path': 'trunk' }
], ],
'current': branch 'current': branch
} }
......
...@@ -55,5 +55,6 @@ ...@@ -55,5 +55,6 @@
}, true); }, true);
</script> </script>
<script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script> <script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script>
<script>window.bootstrap = { branchInfo: {{*branchInfo}} };</script>
</div> </div>
</div> </div>
{{?branchInfo.showWarning}} {{?branchInfo.showWarning}}
<div id="branchWarning" class="displayModeWarning"> <div id="branchWarning" class="displayModeWarning">
<span>WARNING: this is the {{branchInfo.current}} documentation. It may not work with the stable release of Chrome.</span> <span>WARNING: this is the {{branchInfo.current}} documentation. It may not work with the stable release of Chrome.</span>
<select id="branchChooser" onchange="redirectToBranch(this.value)"> <select id="branchChooser">
<option value="">Choose a different version...</option> <option value="">Choose a different version...</option>
{{#branchInfo.branches}} {{#branchInfo.branches}}
<option value="{{path}}">{{name}}</option> <option value="{{path}}">{{name}}</option>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment