Skip to content

Commit aae6fa0

Browse files
committed
Added JS script that checks if Menlo font exists
1 parent 4095057 commit aae6fa0

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,5 +1757,7 @@ <h2 id="basicscripttemplate"><a href="#basicscripttemplate" name="basicscripttem
17571757
<br>
17581758
<br>
17591759
<br>
1760+
<script src="web/jquery-3.4.0.slim.min.js"></script>
1761+
<script src="web/script_2.js"></script>
17601762
</body>
17611763
</html>

web/jquery-3.4.0.slim.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/script_2.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const DIAGRAM_1_A =
2+
'+---------+-------------+\n' +
3+
'| classes | metaclasses |\n' +
4+
'+---------|-------------|\n' +
5+
'| MyClass > MyMetaClass |\n' +
6+
'| | v |\n' +
7+
'| object ---> type <+ |\n' +
8+
'| | ^ +---+ |\n' +
9+
'| str -------+ |\n' +
10+
'+---------+-------------+\n';
11+
12+
const DIAGRAM_1_B =
13+
'┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
14+
'┃ classes │ metaclasses ┃\n' +
15+
'┠─────────┼─────────────┨\n' +
16+
'┃ MyClass → MyMetaClass ┃\n' +
17+
'┃ │ ↓ ┃\n' +
18+
'┃ object ───→ type ←╮ ┃\n' +
19+
'┃ │ ↑ ╰───╯ ┃\n' +
20+
'┃ str ───────╯ ┃\n' +
21+
'┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
22+
23+
const DIAGRAM_2_A =
24+
'+---------+-------------+\n' +
25+
'| classes | metaclasses |\n' +
26+
'+---------|-------------|\n' +
27+
'| MyClass | MyMetaClass |\n' +
28+
'| v | v |\n' +
29+
'| object <--- type |\n' +
30+
'| ^ | |\n' +
31+
'| str | |\n' +
32+
'+---------+-------------+\n';
33+
34+
const DIAGRAM_2_B =
35+
'┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
36+
'┃ classes │ metaclasses ┃\n' +
37+
'┠─────────┼─────────────┨\n' +
38+
'┃ MyClass │ MyMetaClass ┃\n' +
39+
'┃ ↓ │ ↓ ┃\n' +
40+
'┃ object ←─── type ┃\n' +
41+
'┃ ↑ │ ┃\n' +
42+
'┃ str │ ┃\n' +
43+
'┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
44+
45+
46+
(function(d){function c(c){b.style.fontFamily=c;e.appendChild(b);f=b.clientWidth;e.removeChild(b);return f}var f,e=d.body,b=d.createElement("span");b.innerHTML=Array(100).join("wi");b.style.cssText=["position:absolute","width:auto","font-size:128px","left:-99999px"].join(" !important;");var g=c("monospace"),h=c("serif"),k=c("sans-serif");window.isFontAvailable=function(b){return g!==c(b+",monospace")||k!==c(b+",sans-serif")||h!==c(b+",serif")}})(document);
47+
48+
if (!isFontAvailable('Menlo')) {
49+
$(`code:contains(${DIAGRAM_1_B})`).html(DIAGRAM_1_A)
50+
$(`code:contains(${DIAGRAM_2_B})`).html(DIAGRAM_2_A)
51+
}
52+
53+
54+
55+

web/template.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,7 @@
159159
<br>
160160
<br>
161161
<br>
162+
<script src="web/jquery-3.4.0.slim.min.js"></script>
163+
<script src="web/script_2.js"></script>
162164
</body>
163165
</html>

0 commit comments

Comments
 (0)