mirror of https://github.com/KaiserY/trpl-zh-cn
parent
2915a218b8
commit
820474537f
@ -0,0 +1,33 @@
|
||||
body.light .does_not_compile,
|
||||
body.light .panics,
|
||||
body.light .not_desired_behavior,
|
||||
body.rust .does_not_compile,
|
||||
body.rust .panics,
|
||||
body.rust .not_desired_behavior {
|
||||
background: #fff1f1;
|
||||
}
|
||||
|
||||
body.coal .does_not_compile,
|
||||
body.coal .panics,
|
||||
body.coal .not_desired_behavior,
|
||||
body.navy .does_not_compile,
|
||||
body.navy .panics,
|
||||
body.navy .not_desired_behavior,
|
||||
body.ayu .does_not_compile,
|
||||
body.ayu .panics,
|
||||
body.ayu .not_desired_behavior {
|
||||
background: #501f21;
|
||||
}
|
||||
|
||||
.ferris {
|
||||
position: absolute;
|
||||
z-index: 99;
|
||||
right: 5px;
|
||||
top: 30px;
|
||||
width: 10%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.ferris-explain {
|
||||
width: 100px;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
var ferrisTypes = [
|
||||
{
|
||||
attr: 'does_not_compile',
|
||||
title: 'This code does not compile!'
|
||||
},
|
||||
{
|
||||
attr: 'panics',
|
||||
title: 'This code panics!'
|
||||
},
|
||||
{
|
||||
attr: 'unsafe',
|
||||
title: 'This code block contains unsafe code.'
|
||||
},
|
||||
{
|
||||
attr: 'not_desired_behavior',
|
||||
title: 'This code does not produce the desired behavior.'
|
||||
}
|
||||
]
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
for (var ferrisType of ferrisTypes) {
|
||||
attachFerrises(ferrisType)
|
||||
}
|
||||
})
|
||||
|
||||
function attachFerrises (type) {
|
||||
var elements = document.getElementsByClassName(type.attr)
|
||||
|
||||
for (var codeBlock of elements) {
|
||||
var lines = codeBlock.textContent.split(/\r|\r\n|\n/).length - 1;
|
||||
|
||||
if (lines >= 4) {
|
||||
attachFerris(codeBlock, type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function attachFerris (element, type) {
|
||||
var a = document.createElement('a')
|
||||
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
|
||||
a.setAttribute('target', '_blank')
|
||||
|
||||
var img = document.createElement('img')
|
||||
img.setAttribute('src', 'img/ferris/' + type.attr + '.svg')
|
||||
img.setAttribute('title', type.title)
|
||||
img.className = 'ferris'
|
||||
|
||||
a.appendChild(img)
|
||||
|
||||
element.parentElement.insertBefore(a, element)
|
||||
}
|
Loading…
Reference in new issue