@xiee/utils 1.1.6 → 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/faq.css +3 -6
- package/js/custom-disqus.js +89 -0
- package/js/fix-footnote.js +7 -3
- package/js/hash-notes.js +1 -1
- package/js/load-typekit.js +16 -0
- package/js/toggle-notes.js +12 -0
- package/package.json +1 -1
package/css/faq.css
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
.faq-list > li > :first-child {
|
|
5
5
|
display: block;
|
|
6
6
|
cursor: pointer;
|
|
7
|
+
background: #fafafa;
|
|
8
|
+
margin: -.5em;
|
|
9
|
+
padding: .5em;
|
|
7
10
|
}
|
|
8
11
|
.faq-list > :not(.faq-clicked) > * {
|
|
9
12
|
display: none;
|
|
@@ -20,11 +23,5 @@
|
|
|
20
23
|
}
|
|
21
24
|
.faq-list > li {
|
|
22
25
|
border: 1px solid #eee;
|
|
23
|
-
}
|
|
24
|
-
.faq-list > li > :first-child {
|
|
25
|
-
background: #fafafa;
|
|
26
|
-
margin: 0;
|
|
27
|
-
}
|
|
28
|
-
.faq-list > li > * {
|
|
29
26
|
padding: .5em;
|
|
30
27
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// lazyload Disqus on my personal site
|
|
2
|
+
(function(d) {
|
|
3
|
+
var inIFrame = function() {
|
|
4
|
+
var iframe = true;
|
|
5
|
+
try { iframe = window.self !== window.top; } catch (e) {}
|
|
6
|
+
return iframe;
|
|
7
|
+
};
|
|
8
|
+
if (inIFrame()) return;
|
|
9
|
+
var t = d.getElementById('disqus_thread'), s = t.nextElementSibling,
|
|
10
|
+
a = d.querySelector('section.comments'),
|
|
11
|
+
rads = a.querySelectorAll('input[type="radio"]');
|
|
12
|
+
s.setAttribute('data-timestamp', +new Date());
|
|
13
|
+
var inputValues = function() {
|
|
14
|
+
var v = {};
|
|
15
|
+
rads.forEach(function(el) { v[el.id] = el.checked; });
|
|
16
|
+
return v;
|
|
17
|
+
}, selectTab2 = function() {
|
|
18
|
+
a.querySelector('#tab-2').checked = true;
|
|
19
|
+
return 'add';
|
|
20
|
+
}, showFullComment = function(el) {
|
|
21
|
+
if (el.name !== 'layout') return;
|
|
22
|
+
a.classList[el.id === 'layout-2' ? selectTab2() : 'remove']('comment-full');
|
|
23
|
+
}, inputRestore = function() {
|
|
24
|
+
var v = localStorage.getItem('comment-prefs');
|
|
25
|
+
if (!v) return;
|
|
26
|
+
v = JSON.parse(v);
|
|
27
|
+
rads.forEach(function(el) {
|
|
28
|
+
if (v[el.id]) {
|
|
29
|
+
el.checked = true;
|
|
30
|
+
showFullComment(el);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}, inputSave = function() {
|
|
34
|
+
showFullComment(this);
|
|
35
|
+
loadScript();
|
|
36
|
+
var v = JSON.stringify(inputValues());
|
|
37
|
+
try { localStorage.setItem('comment-prefs', v); } catch (e) {}
|
|
38
|
+
}, loadScript = function() {
|
|
39
|
+
var full = a.classList.contains('comment-full');
|
|
40
|
+
a.querySelectorAll('input[name="tabs"]').forEach(function(el, i) {
|
|
41
|
+
if (!full && !el.checked) return;
|
|
42
|
+
var p = a.querySelector('.panel:nth-of-type(' + (i + 1) + ') > script[data-src]');
|
|
43
|
+
if (!p || !p.dataset.src) return;
|
|
44
|
+
p.src = p.dataset.src;
|
|
45
|
+
p.removeAttribute('data-src');
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
// restore radio button values when opening page
|
|
49
|
+
inputRestore();
|
|
50
|
+
// save when radio button values change
|
|
51
|
+
rads.forEach(function(el) { el.addEventListener('change', inputSave); });
|
|
52
|
+
var b = false, l = function(scroll) {
|
|
53
|
+
if (b) return;
|
|
54
|
+
a.querySelector('.tabs').style.display = '';
|
|
55
|
+
loadScript();
|
|
56
|
+
b = true;
|
|
57
|
+
if (scroll) t.scrollIntoView();
|
|
58
|
+
}
|
|
59
|
+
s.onerror = function(e) {
|
|
60
|
+
// try to load Disqus in the read-only mode
|
|
61
|
+
var s2 = d.createElement('script');
|
|
62
|
+
s2.src = "//cdn.jsdelivr.net/gh/yihui/DisqusJS@1.3.3/src/disqus.min.js";
|
|
63
|
+
t.appendChild(s2);
|
|
64
|
+
try { localStorage.setItem('dsqjs_mode', 'dsqjs'); } catch (e) {}
|
|
65
|
+
s2.onload = function(e) {
|
|
66
|
+
var s3 = d.createElement('link');
|
|
67
|
+
s3.rel = 'stylesheet';
|
|
68
|
+
s3.href = '//cdn.jsdelivr.net/gh/yihui/DisqusJS@1.3.3/src/disqusjs.min.css';
|
|
69
|
+
d.head.appendChild(s3);
|
|
70
|
+
disqus_config.DisqusJSInit();
|
|
71
|
+
};
|
|
72
|
+
s2.onerror = function(e) {
|
|
73
|
+
t.innerText = 'Sorry, but you cannot make comments because Disqus failed to load for some reason. It is known to be blocked in certain regions. If you are sure it is not blocked in your region, please refresh the page. Alternatively, you can comment with Utterances. 您可能需要翻墙发表 Disqus 评论;若没有梯子,不妨尝试使用 Github 登录 Utterances 评论。';
|
|
74
|
+
t.style.border = '1px dashed';
|
|
75
|
+
t.style.padding = '.5em';
|
|
76
|
+
t.style.background = 'lightyellow';
|
|
77
|
+
selectTab2();
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
// show comments when the hash means to jump to a comment
|
|
81
|
+
if (location.hash.match(/^#comment-[0-9]+$/)) return l(true);
|
|
82
|
+
var c = function() {
|
|
83
|
+
if (b) return;
|
|
84
|
+
var rect = a.getBoundingClientRect();
|
|
85
|
+
if (rect.top < window.innerHeight && rect.bottom >= 0) l();
|
|
86
|
+
};
|
|
87
|
+
window.addEventListener('load', c);
|
|
88
|
+
d.addEventListener('scroll', c);
|
|
89
|
+
})(document);
|
package/js/fix-footnote.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function() {
|
|
1
|
+
(function(d) {
|
|
2
2
|
function fix_footnote(tagName) {
|
|
3
|
-
|
|
3
|
+
let tags = d.getElementsByTagName(tagName), i, tag, tag2, n = 1, href;
|
|
4
4
|
for (i = 0; i < tags.length; i++) {
|
|
5
5
|
tag = tags[i];
|
|
6
6
|
if (tagName === 'sup') {
|
|
@@ -25,4 +25,8 @@
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
fix_footnote('sup'); fix_footnote('li');
|
|
28
|
-
|
|
28
|
+
// move the return symbol into the previous <p>
|
|
29
|
+
d.querySelectorAll('.footnotes > ol > li > p ~ .footnote-return').forEach(el => {
|
|
30
|
+
el.previousElementSibling.lastChild.after(el);
|
|
31
|
+
});
|
|
32
|
+
})(document);
|
package/js/hash-notes.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
s.innerText = t.replace(r, '$1');
|
|
11
11
|
s.innerHTML = s.innerHTML
|
|
12
12
|
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank">$1</a>')
|
|
13
|
-
.replace(/(
|
|
13
|
+
.replace(/(^|[^"])(https?:\/\/)([-a-zA-Z0-9%._=/\+]+)(#)?([-a-zA-Z0-9%._=\+]+)?/g, '$1<a href="$2$3$4$5" target="_blank">$3$4</a>');
|
|
14
14
|
el.before(s);
|
|
15
15
|
el.remove();
|
|
16
16
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
(function(d) {
|
|
2
|
+
// https://www.kirupa.com/html5/detect_whether_font_is_installed.htm
|
|
3
|
+
var canvas = d.createElement("canvas");
|
|
4
|
+
var context = canvas.getContext("2d");
|
|
5
|
+
var text = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
6
|
+
context.font = "72px monospace";
|
|
7
|
+
var size = context.measureText(text).width;
|
|
8
|
+
var fonts = [' SC', ' CN', ' TC', ' TW', ''];
|
|
9
|
+
for (var i = 0; i < fonts.length; i++) {
|
|
10
|
+
context.font = "72px '" + 'Source Han Serif' + fonts[i] + "', monospace";
|
|
11
|
+
// no need to load TypeKit if Source Hans Serif has been installed
|
|
12
|
+
if (context.measureText(text).width != size) return;
|
|
13
|
+
}
|
|
14
|
+
var config = {kitId: 'kwz5xar', scriptTimeout: 3000, async: true},
|
|
15
|
+
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
|
|
16
|
+
})(document);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function(d) {
|
|
2
|
+
if (!d.body.classList.contains('has-notes')) return;
|
|
3
|
+
const h = d.querySelector('.title > hr');
|
|
4
|
+
if (!h) return;
|
|
5
|
+
h.classList.add('toggle-notes');
|
|
6
|
+
h.onclick = function(e) {
|
|
7
|
+
const s = d.body.classList.toggle('hide-notes');
|
|
8
|
+
try { sessionStorage.setItem('hide-notes', s); } catch (e) {};
|
|
9
|
+
};
|
|
10
|
+
const s = sessionStorage.getItem('hide-notes');
|
|
11
|
+
if (s !== null) d.body.classList.toggle('hide-notes', s === 'true');
|
|
12
|
+
})(document);
|