/** * Load topics */ var Topics = {}; /** * get topics as JSON and return the topics grouped by category * * [ * { * title: , * topics: [ * * ] * } * ] */ Topics.loadTopics = function(url, callback) { $.getJSON(url, function(data) { // sort by categorysort and categorytitle var gbtopics = data.gbtopics.sort(function(a, b) { var res = a.categorysort - b.categorysort; if (res === 0) { res = a.categorytitle.localeCompare(b.categorytitle); } else if (a.categorysort === null || b.categorysort === null) { // null values have lowest priority res = -res; } return res; }); // group by category categories = {}; for (var i=0;i