Add config.json to make it even easier to configure things
This commit is contained in:
parent
f86f965e98
commit
1ce9f5bbe4
4
config.json
Normal file
4
config.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"customStylesheetURL": null,
|
||||
"yearLength": 120
|
||||
}
|
26
index.html
26
index.html
@ -99,12 +99,30 @@ h1{
|
||||
$el: document.getElementById('life'),
|
||||
yearLength: 120, // 120px per year
|
||||
start: function(){
|
||||
life.fetch(function(response){
|
||||
var data = life.parse(response);
|
||||
var title = life.parseTitle(response);
|
||||
life.render(title, data);
|
||||
life.loadConfig(function(config){
|
||||
if (config.yearLength) life.yearLength = config.yearLength;
|
||||
if (config.customStylesheetURL) life.injectStylesheet(config.customStylesheetURL);
|
||||
|
||||
life.fetch(function(response){
|
||||
var data = life.parse(response);
|
||||
var title = life.parseTitle(response);
|
||||
life.render(title, data);
|
||||
});
|
||||
});
|
||||
},
|
||||
loadConfig: function(fn){
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'config.json', true);
|
||||
xhr.onload = function(){
|
||||
if (xhr.status == 200) fn(JSON.parse(xhr.responseText));
|
||||
};
|
||||
xhr.send();
|
||||
},
|
||||
injectStylesheet: function(url){
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
document.body.appendChild(link);
|
||||
},
|
||||
fetch: function(fn){
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'life.md', true);
|
||||
|
Loading…
Reference in New Issue
Block a user