-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
113 lines (87 loc) · 4.78 KB
/
script.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var switched = false;
function switch2zh () {
if (switched) { alert('Refresh the page, then click on this button again.'); return; }
var en = document.querySelectorAll('[data-lang=en]')
for (var i=0;i<en.length;i++) en[i].style.display='none'
document.getElementById('languageStyling').textContent=''
var zhHans = document.querySelectorAll('[data-lang=zh-hans]')
for (var i=0;i<zhHans.length;i++) zhHans[i].style.display='none'
document.getElementById('languageStyling').textContent=''
document.documentElement.lang = 'zh'
switched = true;
// change boilerplate text
document.getElementById('abstract-1').textContent = '摘要'
document.getElementById('h-sotd').textContent = '关于本文档'
document.getElementById('h-toc').textContent = '内容大纲'
var notes = document.querySelectorAll('.note-title')
for (i=0;i<notes.length;i++) notes[i].textContent = '注'
var figcaptions = document.querySelectorAll('figcaption')
for (i=0;i<figcaptions.length;i++) figcaptions[i].firstChild.textContent = '圖'
var figcaptions = document.querySelectorAll('.fig-ref')
for (i=0;i<figcaptions.length;i++) figcaptions[i].firstChild.textContent = '圖'
var dts = document.querySelectorAll('dt')
for (i=0;i<dts.length;i++) {
switch (dts[i].textContent) {
case 'This version:': dts[i].textContent = '本版本:'; break;
case 'Latest published version:': dts[i].textContent = '最新发布草稿:'; break;
case 'Latest editor\'s draft:': dts[i].textContent = '最新编辑草稿:'; break;
case 'Editors:': dts[i].textContent = '编辑:'; break;
case 'Bug tracker:': dts[i].textContent = '错误跟踪:';
dts[i].nextSibling.nextSibling.innerHTML = '<a href="https://github.com/w3c/clreq/issues">反馈错误</a>(<a href="https://github.com/w3c/clreq/issues">修正中的错误</a>)'; break;
}
}
}
function switch2zhHans () {
if (switched) { alert('Refresh the page, then click on this button again.'); return; }
var en = document.querySelectorAll('[data-lang=en]')
for (var i=0;i<en.length;i++) en[i].style.display='none'
document.getElementById('languageStyling').textContent=''
var zh = document.querySelectorAll('[data-lang=zh]')
for (var i=0;i<zh.length;i++) zh[i].style.display='none'
document.getElementById('languageStyling').textContent=''
document.documentElement.lang = 'zh-hans'
switched = true;
// change boilerplate text
document.getElementById('abstract-1').textContent = '摘要'
document.getElementById('h-sotd').textContent = '关于本文档'
document.getElementById('h-toc').textContent = '内容大纲'
var notes = document.querySelectorAll('.note-title')
for (i=0;i<notes.length;i++) notes[i].textContent = '注'
var figcaptions = document.querySelectorAll('figcaption')
for (i=0;i<figcaptions.length;i++) figcaptions[i].firstChild.textContent = '图 '
var figcaptions = document.querySelectorAll('.fig-ref')
for (i=0;i<figcaptions.length;i++) figcaptions[i].firstChild.textContent = '图'
var dts = document.querySelectorAll('dt')
for (i=0;i<dts.length;i++) {
switch (dts[i].textContent) {
case 'This version:': dts[i].textContent = '本版本:'; break;
case 'Latest published version:': dts[i].textContent = '最新发布草稿:'; break;
case 'Latest editor\'s draft:': dts[i].textContent = '最新编辑草稿:'; break;
case 'Editors:': dts[i].textContent = '编辑们:'; break;
case 'Bug tracker:': dts[i].textContent = '错误跟踪:';
dts[i].nextSibling.nextSibling.innerHTML = '<a href="https://github.com/w3c/clreq/issues">反馈错误</a>(<a href="https://github.com/w3c/clreq/issues">修正中的错误</a>)'; break;
}
}
}
function switch2en () {
if (switched) { alert('Refresh the page, then click on this button again.'); return; }
var zh = document.querySelectorAll('[data-lang=zh]')
for (var i=0;i<zh.length;i++) zh[i].style.display='none'
document.getElementById('languageStyling').textContent=''
var zhHans = document.querySelectorAll('[data-lang=zh-hans]')
for (var i=0;i<zhHans.length;i++) zhHans[i].style.display='none'
document.getElementById('languageStyling').textContent=''
document.documentElement.lang = 'en'
switched = true;
}
function addLangAttrs () {
// adds lang attributes wherever there is a data-lang attribute
// this is done by js to reduce burden on editors
// if there's already a lang attribute in the tag, that tag is skipped
// note that this may still produce temporarily incorrect labelling where text is awaiting translation
var zh = document.querySelectorAll('[data-lang=zh]')
for (i=0;i<zh.length;i++) { if (zh[i].lang == '') { zh[i].lang='zh'} }
var zhHans = document.querySelectorAll('[data-lang=zh-hans]')
for (i=0;i<zhHans.length;i++) { if (zhHans[i].lang == '') { zhHans[i].lang='zh-hans'} }
}
document.addEventListener( 'DOMContentLoaded', addLangAttrs );