-
Notifications
You must be signed in to change notification settings - Fork 0
/
5about.html
65 lines (57 loc) · 1.68 KB
/
5about.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
layout: page
title: "About"
description: "Who AM I?"
header-img: "img/about-bg.jpg"
permalink: /about/
---
<!-- Language Selector -->
<select class="sel-lang" onchange= "onLanChange(this.options[this.options.selectedIndex].value)">
<option value="0" selected> 中文 Chinese </option>
<option value="1"> 英文 English </option>
</select>
<!-- Chinese Version -->
<div class="zh post-container">
{% capture about_zh %}{% include about/zh.md %}{% endcapture %}
{{ about_zh | markdownify }}
</div>
<!-- English Version -->
<div class="en post-container">
{% capture about_en %}{% include about/en.md %}{% endcapture %}
{{ about_en | markdownify }}
</div>
<!-- Handle Language Change -->
<script type="text/javascript">
// get nodes
var $zh = document.querySelector(".zh");
var $en = document.querySelector(".en");
var $select = document.querySelector("select");
// bind hashchange event
window.addEventListener('hashchange', _render);
// handle render
function _render(){
var _hash = window.location.hash;
// en
if(_hash == "#en"){
$select.selectedIndex = 1;
$en.style.display = "block";
$zh.style.display = "none";
// zh by default
}else{
// not trigger onChange, otherwise cause a loop call.
$select.selectedIndex = 0;
$zh.style.display = "block";
$en.style.display = "none";
}
}
// handle select change
function onLanChange(index){
if(index == 0){
window.location.hash = "#zh"
}else{
window.location.hash = "#en"
}
}
// init
_render();
</script>