From 1ce9f5bbe4087fd54e1d482e67f0b5d6d38fc998 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 27 Nov 2013 23:13:33 +0800 Subject: [PATCH] Add config.json to make it even easier to configure things --- config.json | 4 ++++ index.html | 26 ++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 0000000..2f358cc --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "customStylesheetURL": null, + "yearLength": 120 +} \ No newline at end of file diff --git a/index.html b/index.html index 83aa3ad..f4fd319 100644 --- a/index.html +++ b/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);