-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjekyll_outline.js
31 lines (29 loc) · 1014 Bytes
/
jekyll_outline.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
// jekyll_img generates picture tags wrapped within divs
// We move the entire div, not just the picture tag
// If an image does not correspond to a heading, delete it
function position_outline_image(picture, before_id) {
var img = picture.parentElement;
var before_element = document.getElementById(before_id);
if (before_element) {
var parent = before_element.parentElement;
parent.insertBefore(img, before_element);
} else {
img.remove();
}
}
function getElementsByIdPrefix(selectorTag, prefix) {
var items = [];
var myPosts = document.getElementsByTagName(selectorTag);
for (var i = 0; i < myPosts.length; i++) {
//omitting undefined null check for brevity
if (myPosts[i].id.lastIndexOf(prefix, 0) === 0)
items.push(myPosts[i]);
}
return items;
}
window.onload = (event) => {
getElementsByIdPrefix("picture", "outline_").forEach(picture => {
num = picture.id.substring("outline_".length)
position_outline_image(picture, `posts_wrapper_${num}`)
});
}