Commit: c251f3f393baaab6f9205d0d164b60ccd3e8e24b Author: Hannes Magnusson <[email protected]> Sat, 28 Dec 2013 15:38:18 -0800 Parents: d2420e89bf486b3e66271e4a142d8f4f1e89985c Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=c251f3f393baaab6f9205d0d164b60ccd3e8e24b Log: Implement cycling through headers Changed paths: M js/common.js M styles/theme-base.css Diff: diff --git a/js/common.js b/js/common.js index 97abbbd..d370169 100755 --- a/js/common.js +++ b/js/common.js @@ -94,22 +94,65 @@ Mousetrap.bind("g n", function() { window.location.href = link; } }); + +var FIXED_HEADER_HEIGHT = 50; +function cycle(to, from) { + from.removeClass("current"); + to.addClass("current"); + $.scrollTo(to.offset().top-FIXED_HEADER_HEIGHT); +} +function getNextOrPreviousSibling(node, forward) { + if (forward) { + return node.next(); + } + return node.prev(); +} +function cycleMenuItems(current, forward) { + if (getNextOrPreviousSibling(current, forward).length) { + cycle(getNextOrPreviousSibling(current, forward), current); + curr.children("a").first().focus().css({outline: "none"}); + } +} +function cycleHeaders(matches, forward) { + /* forward=1 next match + * forward=0 previous match + */ + var gotmatch = 0; + + matches.each(function(k, item) { + if ($(item).hasClass("current")) { + if ($(matches[forward ? k+1 : k-1]).length) { + cycle($(matches[forward ? k+1 : k-1]), $(item)); + gotmatch = 1; + return false; + } + } + }); + if (!gotmatch) { + cycle($(matches[forward ? 0 : matches.length-1]), $(matches[forward ? matches.length-1 : 0])); + } +} 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"}); + if (node.length) { + cycleMenuItems(node, 1); + } + else { + /* Cycle through headers on normal pages */ + var matches = $("#layout-content h1, #layout-content h2, #layout-content h3"); + cycleHeaders(matches, 1); } }); Mousetrap.bind("k", function() { - var fixedheader = 50; var node = $(".layout-menu .current"); - if (node.prev().length) { - var curr = node.toggleClass("current").prev().toggleClass("current"); - $.scrollTo(curr.offset().top-fixedheader); - curr.children("a").first().focus().css({outline: "none"}); + if (node.length) { + cycleMenuItems(node, 0); + } + else { + /* Cycle through headers on normal pages */ + var matches = $("#layout-content h1, #layout-content h2, #layout-content h3"); + cycleHeaders(matches, 0); } }); Mousetrap.bind("/", function(e) { 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; -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
