Skip to content

Commit bb96d54

Browse files
committed
Add #work-history deep link for work history section
1 parent 3a22b04 commit bb96d54

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub(crate) const A: &str = "a";
3535
pub(crate) const CONTROLS: &str = "controls";
3636
pub(crate) const LINK: &str = "link";
3737
pub(crate) const WORK_HISTORY_SELECTOR: &str = ".work-history";
38+
pub(crate) const WORK_HISTORY_HASH: &str = "work-history";
3839
pub(crate) const POOP: &str = "💩";
3940
pub(crate) const CLASS: &str = "class";
4041
pub(crate) const HASH: &str = "#";

src/partials/cv.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<details class='work-history'>
1+
<details class='work-history' id='work-history'>
22
<summary class='link'>work history</summary>
33
<ul>
44
<li>

src/work_history.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use stdweb::unstable::TryInto;
33
use stdweb::web::{document, Element};
44
use stdweb::web::event::ClickEvent;
55

6-
use crate::constants::WORK_HISTORY_SELECTOR;
6+
use crate::constants::{WORK_HISTORY_HASH, WORK_HISTORY_SELECTOR};
7+
use crate::util::get_hash;
78

89
fn scroll_into_view(el: Element) {
910
js! { @(no_return)
@@ -17,11 +18,22 @@ fn scroll_into_view(el: Element) {
1718
pub(crate) struct WorkHistory;
1819

1920
impl WorkHistory {
21+
fn open_from_hash(details: Element) {
22+
if get_hash() == WORK_HISTORY_HASH {
23+
js! { @(no_return)
24+
let details = @{details};
25+
details.open = true;
26+
}
27+
self::scroll_into_view(details);
28+
}
29+
}
30+
2031
pub(crate) fn new() -> Self {
2132
let details = document()
2233
.query_selector(WORK_HISTORY_SELECTOR)
2334
.unwrap()
2435
.unwrap();
36+
Self::open_from_hash(details.clone());
2537
let click_event = enclose!( (details) move |_: ClickEvent| {
2638
let clone = details.clone();
2739
let is_open: bool = js!( return @{&details}.open; )

0 commit comments

Comments
 (0)