/*global htmlEncode, VuFind */ /*exported initFacetTree */ function buildFacetNodes(data, currentPath, allowExclude, excludeTitle, counts) { var json = []; $(data).each(function facetNodesEach() { var html = ''; if (!this.isApplied && counts) { html = '' + this.count.toString().replace(/\B(?=(\d{3})+\b)/g, VuFind.translate('number_thousands_separator')); if (allowExclude) { var excludeURL = currentPath + this.exclude; excludeURL.replace("'", "\\'"); // Just to be safe html += ' '; } html += ''; } var url = currentPath + this.href; // Just to be safe url.replace("'", "\\'"); html += ''; if (this.operator === 'OR') { if (this.isApplied) { html += ''; } else { html += ''; } } else if (this.isApplied) { html += ''; } html += ' ' + this.displayText; html += ''; var children = null; if (typeof this.children !== 'undefined' && this.children.length > 0) { children = buildFacetNodes(this.children, currentPath, allowExclude, excludeTitle, counts); } json.push({ 'text': html, 'children': children, 'applied': this.isApplied, 'state': { 'opened': this.hasAppliedChildren }, 'li_attr': this.isApplied ? { 'class': 'active' } : {} }); }); return json; } function initFacetTree(treeNode, inSidebar) { var loaded = treeNode.data('loaded'); if (loaded) { return; } treeNode.data('loaded', true); var facet = treeNode.data('facet'); var operator = treeNode.data('operator'); var currentPath = treeNode.data('path'); var allowExclude = treeNode.data('exclude'); var excludeTitle = treeNode.data('exclude-title'); var sort = treeNode.data('sort'); var query = window.location.href.split('?')[1]; if (inSidebar) { treeNode.prepend('