diff options
Diffstat (limited to 'public/assets/site.js')
| -rw-r--r-- | public/assets/site.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/public/assets/site.js b/public/assets/site.js new file mode 100644 index 0000000..ff109da --- /dev/null +++ b/public/assets/site.js @@ -0,0 +1,77 @@ +var site = {} + +$(function(){ + $.getJSON('/db.json', function(data){ + site = data + var entries = site.entries = {} + site.entry.forEach(function(entry){ + entries[entry.id] = entry + entry.tags = entry.tags.split('#').map(function(tag){ + return tag.trim() + }) + }) + ready() + }) +}) + +function ready() { + bind() + build() +} +function bind(){ + $('.cell').click( function(){ + var id = $(this).data().id + var entry = site.entries[id] + show_entry(entry) + }) + $('.close').click( function(){ + close_modals() + }) + $('.tag').click( function(){ + var tag = $(this).html() + filter_by_tag(tag) + }) +} +function build(){ + $('.cell').each( function(){ + var id = $(this).data().id + var entry = site.entries[id] + if (! entry) return + if (entry.media && entry.media.length) { + var media = entry.media[0] + switch (media.type) { + case 'youtube': + bg = media.thumb + break + case 'image': + bg = media.uri + break + } + $(this).css('background-image', 'url(' + bg + ')') + } + }) +} + +function show_entry(entry){ + console.log('showing', entry) + $('#entry h2').html(entry.title) + $('#entry .content').html(newlineToBr(entry.body)) + $('#entry .media').empty() + if (entry.gallery) { + + } + else { + + } + $('body').addClass('entry') +} +function hide_entry(){ + setTimeout(clear_entry, 500) +} +function clear_entry(){ +} +function close_modals(){ + $('body').removeClass('entry').removeClass('about') +} + +function newlineToBr(s){ return s.replace(/\n/g,'<br>') }
\ No newline at end of file |
