var sheet = []; var index = -1; $(document).ready(function() { hash = window.location.hash; if(hash === "") { window.location.hash = "#0,en"; hash = "#0,en"; } $(hash.split(",")).each(function(i,e) { if(! e.startsWith('#')) { $('#'+e).parent().addClass("active"); document.querySelector('#'+e).parentElement.control.checked = true; } }); $.getJSON(data_url, function(data) { $($(data)[0].feed.entry).each(function(i,e) { content = e.content.$t; content = '{' + content.replace(/, (bg|en|ro|rs|hr|de): /g, '", "$1": "').replace(/^(bg|en|ro|rs|hr|de): /g, '"$1": "') + '"}'; if(content.startsWith('{"en": "# ')) { dict = {}; dict['translations'] = JSON.parse(content); dict['translations']['en'] = dict['translations']['en'].replace(/^# /, ''); dict['vocabulary'] = []; sheet.push(dict); index += 1; } else { vocab = JSON.parse(content); sheet[index]['vocabulary'].push(vocab); } }); var mysource = $('#categoryTemplate').html(); var mytemplate = Handlebars.compile(mysource); var myresult = mytemplate(sheet) $('#category').html(myresult); hashtag(-1); }); } ); function hashtag(index) { var hash = window.location.hash; if(hash === "") { if (typeof(index) !== undefined && index !== -1) window.location.hash = "#" + index; } else { if(typeof(index) !== undefined && index !== -1) { tmp = hash.substr(1).split(","); tmp[0] = index.toString(); window.location.hash = "#" + tmp.join(); } else { tmp = [ hash.substr(1).split(",")[0] ]; $('#languages input').each(function(i,e) { if(e.parentElement.control.checked === true) { tmp.push($(e).attr('id')); } }); window.location.hash = "#" + tmp.join(); } } i = parseInt(window.location.hash.substr(1).split(",")[0]); $('#category a.btn').each(function(i,e) { $(e).removeClass("active"); }); $($('#category a.btn')[i]).addClass('active'); renderTable(); } function renderTable() { var src = $('#keywordsTemplate').html(); var tmp = Handlebars.compile(src); var hash = window.location.hash.substr(1).split(',') var category = hash[0]; var modified = sheet[parseInt(category)]; modified['activeLanguages'] = {}; for(i = 1; i < hash.length; ++i) modified['activeLanguages'][hash[i]] = true; var res = tmp(modified); console.log(modified); $('#keywordsTable').html(res); }