forked from jeffThompson/Recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (53 loc) · 1.64 KB
/
index.js
File metadata and controls
63 lines (53 loc) · 1.64 KB
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
'use strict'
+function() {
if (!('serviceWorker' in navigator)) {
alert('This Browser does not support ServiceWorkers.')
return
}
if (navigator.serviceWorker.controller) {
console.info('ServiceWorker runs')
return
}
console.info('Registering ServiceWorker ...')
navigator.serviceWorker
.register('./serviceworker.js')
.catch(function(err) {
console.error('ServiceWorker has not been registered!', err)
})
}()
// once document is loaded, load list of markdown files
// and generate table of contents, plus a quick-nav list
// at the top
$(document).ready(function() {
let listOfRecipes = '';
let listOfLetters = '';
let prevLetter = '';
// create list of recipes
for (let i in files) {
let url = files[i];
// skip files that start with underscore
// (such as the _template.md file)
if (url[0] === '_') {
continue;
}
// create anchor and name from url
let anchor = url.replace('.md', '');
let name = anchor.split('-').join(' ');
// if the first letter of the recipe hasn't been
// seen yet, add to list of letters and put an achor in
let firstLetter = name.charAt(0).toUpperCase();
if (firstLetter !== prevLetter) {
listOfRecipes += '<li id="' + firstLetter + '">';
listOfLetters += '<a href="#' + firstLetter + '">' + firstLetter + ' </a>';
}
else {
listOfRecipes += '<li>';
}
listOfRecipes += '<a href="recipe.php#' + anchor + '">' + name + '</a></li>';
prevLetter = firstLetter;
}
// add recipes to page...
$('#toc ul').html(listOfRecipes);
// ...and the list of first-letters for quick nav
$('#navigation').html(listOfLetters);
});