Skip to content

Commit 595c704

Browse files
author
Mike Taylor
committed
Issue #577 - Add anchors for sections and some code to know when to open
1 parent 1ae56a4 commit 595c704

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

webcompat/templates/contributors.html

+17-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ <h1 class="wc-Hero-title wc-Title--xl">Welcome aboard!<br/>Get started below...<
1717
<div class="contributors__item">
1818
<div class="contributors__item__header">
1919
<div class="wc-content contributors__item__title">
20-
<h2>
20+
<h2 id="reproduce">
2121
<button class="contributors__item__btn is-active" type="button">
2222
How to Reproduce a Bug
2323
<span class="wc-Icon wc-Icon--contributors wc-Icon--contributors--disabled wc-Icon--minus" aria-hidden="true"></span>
@@ -31,7 +31,7 @@ <h2>
3131
<div class="contributors__item">
3232
<div class="contributors__item__header">
3333
<div class="wc-content contributors__item__title">
34-
<h2>
34+
<h2 id="diagnose">
3535
<button class="contributors__item__btn" type="button">
3636
How to Diagnose a Bug
3737
<span class="wc-Icon wc-Icon--contributors wc-Icon--contributors--disabled wc-Icon--minus" aria-hidden="true"></span>
@@ -45,7 +45,7 @@ <h2>
4545
<div class="contributors__item">
4646
<div class="contributors__item__header">
4747
<div class="wc-content contributors__item__title">
48-
<h2>
48+
<h2 id="outreach">
4949
<button class="contributors__item__btn" type="button">
5050
How to Do Site Outreach
5151
<span class="wc-Icon wc-Icon--contributors wc-Icon--contributors--disabled wc-Icon--minus" aria-hidden="true"></span>
@@ -59,7 +59,7 @@ <h2>
5959
<div class="contributors__item">
6060
<div class="contributors__item__header">
6161
<div class="wc-content contributors__item__title">
62-
<h2>
62+
<h2 id="contribute">
6363
<button class="contributors__item__btn" type="button">
6464
Contribute to this site
6565
<span class="wc-Icon wc-Icon--contributors wc-Icon--contributors--disabled wc-Icon--minus" aria-hidden="true"></span>
@@ -77,16 +77,26 @@ <h2>
7777
{%- block extrascripts -%}
7878
<script>
7979
$(function(){
80-
var lightElm = $('.wc-Hero-img');
81-
var sections = $('.contributors__item__content');
80+
var lightElm = $('.wc-Hero-img');
81+
var sections = $('.contributors__item__content');
8282
var ACTIVE_CLASS = 'is-active';
83-
var OPEN_CLASS = 'is-open';
83+
var OPEN_CLASS = 'is-open';
8484
$('.contributors__item__title').click(function(){
8585
$(this).find('.contributors__item__btn').toggleClass(ACTIVE_CLASS)
8686
.closest('.contributors__item').find('.contributors__item__content')
8787
.toggleClass(OPEN_CLASS)
8888
lightElm.toggleClass(ACTIVE_CLASS, sections.hasClass('is-open'));
8989
});
90+
91+
// if the page was loaded with a hash, it's probably an id for linking so let's
92+
// try to open the right section and scroll there.
93+
var id;
94+
if (id = location.hash) {
95+
if (!$(id).find('.contributors__item__btn').hasClass(ACTIVE_CLASS)) {
96+
$(id).parent().trigger('click');
97+
}
98+
window.scrollTo(0, $(id).offset().top);
99+
}
90100
});
91101
</script>
92102
{%- endblock %}

0 commit comments

Comments
 (0)