Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2004)

Unified Diff: chrome/common/extensions/docs/server2/static/js/sidebar.js

Issue 10827304: Extensions Docs Server: Highlight links on left nav (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean up and comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/docs/server2/static/css/site.css ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/server2/static/js/sidebar.js
diff --git a/chrome/common/extensions/docs/server2/static/js/sidebar.js b/chrome/common/extensions/docs/server2/static/js/sidebar.js
index da5ad4c273fc86b788d395ab593e9edb1095cfa5..b4661d165ed3c9bfbfb8ad3c7c5349194d24a834 100644
--- a/chrome/common/extensions/docs/server2/static/js/sidebar.js
+++ b/chrome/common/extensions/docs/server2/static/js/sidebar.js
@@ -58,31 +58,43 @@
var toc = document.getElementById('gc-toc');
if (!toc)
return;
- var items = toc.getElementsByTagName('li');
+
+ // Figure out which link matches the current page so it can be styled
+ // differently.
+ var links = toc.getElementsByTagName('a');
var selectedNode = null;
+ var path_parts = document.location.pathname.split('/')
not at google - send to devlin 2012/08/14 04:07:20 what about if the path ends with some number of /s
cduvall 2012/08/14 18:23:22 Done.
+ for (var i = 0; i < links.length; i++) {
+ if (links[i].getAttribute('href') != path_parts[path_parts.length - 1])
+ continue;
+ links[i].className = 'leftNavSelected';
+ links[i].removeAttribute('href');
+ selectedNode = links[i];
+ }
+
+ // Go through the items on the sidebar and add toggles.
+ var items = toc.getElementsByTagName('li');
for (var i = 0; i < items.length; i++) {
var item = items[i];
- if (item.className == 'leftNavSelected') {
- selectedNode = item;
- } else if (item.firstChild &&
- item.firstChild.tagName == 'SPAN') {
- // Only assign toggles to text nodes in the sidebar.
- var a = document.createElement('a');
- a.className = 'toggle selected';
- a.appendChild(document.createTextNode(' '));
- a.onclick = function() {
- toggleList(this.parentNode.getElementsByTagName('ul'));
- };
- item.firstChild.onclick = function() {
- toggleList(this.parentNode.getElementsByTagName('ul'));
- };
- item.insertBefore(a, item.firstChild);
- toggleList(item.getElementsByTagName('ul'));
- }
+ if (!item.firstChild || item.firstChild.tagName != 'SPAN')
+ continue;
+ // Only assign toggles to text nodes in the sidebar.
+ var a = document.createElement('a');
+ a.className = 'toggle selected';
+ a.appendChild(document.createTextNode(' '));
+ a.onclick = function() {
+ toggleList(this.parentNode.getElementsByTagName('ul'));
+ };
+ item.firstChild.onclick = function() {
+ toggleList(this.parentNode.getElementsByTagName('ul'));
+ };
+ item.insertBefore(a, item.firstChild);
+ toggleList(item.getElementsByTagName('ul'));
}
- if (selectedNode) {
+
+ // Reveal the selected link.
+ if (selectedNode)
revealAncestor(selectedNode);
- }
};
initSidebar();
« no previous file with comments | « chrome/common/extensions/docs/server2/static/css/site.css ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698