Skip to content

Instantly share code, notes, and snippets.

@bjori
Created December 28, 2013 22:28
Show Gist options
  • Save bjori/8165044 to your computer and use it in GitHub Desktop.
Save bjori/8165044 to your computer and use it in GitHub Desktop.
Cycle through header using keyboard shortcuts
diff --git a/js/common.js b/js/common.js
index 97abbbd..63726bb 100755
--- a/js/common.js
+++ b/js/common.js
@@ -96,11 +96,37 @@ Mousetrap.bind("g n", function() {
});
Mousetrap.bind("j", function() {
var fixedheader = 50;
+ /* Doc page */
var node = $(".layout-menu .current");
if (node.next().length) {
var curr = node.toggleClass("current").next().toggleClass("current");
$.scrollTo(curr.offset().top-fixedheader);
curr.children("a").first().focus().css({outline: "none"});
+ } else {
+ /* Cycle through headers on normal pages */
+ var matches = $("#layout-content h1 a, #layout-content h2 a, #layout-content h3 a");
+ var gotmatch = 0;
+ matches.each(function(k, item) {
+ if ($(item).parent().hasClass("current")) {
+ if ($(matches[k+1]).length) {
+ /* If a header has two or more links in the header, skip the later ones */
+ if ($(item).parent()[0] == $(matches[k+1]).parent()[0]) {
+ return true;
+ }
+
+ $(item).parent().toggleClass("current");
+ $(matches[k+1]).parent().toggleClass("current");
+ gotmatch = 1;
+ $.scrollTo($(matches[k+1]).offset().top-fixedheader);
+ return false;
+ }
+ }
+ });
+ if (!gotmatch) {
+ $(matches[matches.length-1]).parent().removeClass("current");
+ $.scrollTo($(matches[0]).parent().offset().top-fixedheader);
+ $(matches[0]).parent().toggleClass("current");
+ }
}
});
Mousetrap.bind("k", function() {
diff --git a/styles/theme-base.css b/styles/theme-base.css
index 48e1bf5..3fbd6b2 100755
--- a/styles/theme-base.css
+++ b/styles/theme-base.css
@@ -1458,6 +1458,9 @@ ul.chunklist_children {
.docs .layout-menu ul.child-menu-list .current {
position:relative;
}
+#layout-content .current:before {
+ content:"\bb \20";
+}
.docs .layout-menu ul.child-menu-list .current a:before {
content:"\bb \20";
position:absolute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment