0) { folderSwitchStartup.first().click(); var majorSwitchStartup = $("#MajorGroupSwitches").children("[activeOnStartup=true]"); if (folderSwitchStartup.length > 0) { majorSwitchStartup.first().click(); } } else { //Active first button $("#FolderSwitches").children("div").first().click(); } }); function createFilterToggles() { for (index in filesArray) { var folder = filesArray[index]["Folder"]; var folderDisplay = filesArray[index]["FolderDisplay"]; var folderHeaderHTML = filesArray[index]["FolderHeaderHTML"]; var majorGroup = filesArray[index]["MajorGroup"]; var majorGroupHeaderHTML = filesArray[index]["MajorGroupHeaderHTML"]; var majorGroupFooterHTML = filesArray[index]["MajorGroupFooterHTML"]; var folderActiveOnStartup = filesArray[index]["FolderActiveOnStartup"]; var majorGroupActiveOnStartup = filesArray[index]["MajorGroupActiveOnStartup"]; var folderRouteURL = filesArray[index]["FolderRouteURL"]; var majorGroupRouteURL = filesArray[index]["MajorGroupRouteURL"]; //Check if button for this Folder already exists (add if it doesn't) var folderSwitch = $("#FolderSwitches").children("[folder='" + folder + "']"); if (folderSwitch.length == 0) { $("
").attr({ "class": "btn_switch FolderSwitch off", "onclick": "toggle(this)", "folder": folder, "activeOnStartup": folderActiveOnStartup, "headerHTML": folderHeaderHTML, "routeURL": folderRouteURL }).html(folderDisplay).appendTo("#FolderSwitches"); } else { if (folderActiveOnStartup && folderSwitch.attr("activeOnStartup") == false) { //Because the current filter is enabled by default, also update Folder Switch folderSwitch.attr("activeOnStartup", folderActiveOnStartup); } } //Check if button for this Major Group already exists (add if it doesn't) if ($("#MajorGroupSwitches").children("[folder='" + folder + "'][majorGroup='" + majorGroup + "']").length == 0) { $("
").attr({ "class": "btn_switch MajorGroupSwitch off", "onclick": "toggle(this)", "folder": folder, "majorGroup": majorGroup, "activeOnStartup": majorGroupActiveOnStartup, "headerHTML": majorGroupHeaderHTML, "footerHTML": majorGroupFooterHTML, "routeURL": majorGroupRouteURL }).html(majorGroup).appendTo("#MajorGroupSwitches"); } } } function clearGridSearchBox() { $("#searchBox").val(''); updateGridWithFilter(); } function toggle(btn) { //Only perform toggle if current button is off if ($(btn).hasClass("off")) { //Toggle everything off (only one selection at a time is allowed) var divWrapper = $(btn).parent(); divWrapper.children("div").removeClass('on'); divWrapper.children("div").addClass('off'); //Toggle clicked button to on $(btn).toggleClass('off on'); //Update the URL (if browser supports) if (window.history) { if (window.history.replaceState) { var routeURL = $(btn).attr("routeURL"); window.history.replaceState(null, document.title, routeURL); } } if ($(btn).hasClass("FolderSwitch")) { //Clicked button is a Folder switch //Update header html for the folder updateFolderHeaderHTML($(btn).attr("headerHTML")); //Update Major Group options that are available for this Folder updateMajorGroupOptions(); } else { //Update header html for the major group updateMajorGroupHeaderHTML($(btn).attr("headerHTML")); updateMajorGroupFooterHTML($(btn).attr("footerHTML")); } updateGridWithFilter(); } } function updateMajorGroupOptions() { var buttonsShowing = new Array(); //Show/hide major group switches for (index in filesArray) { var folder = filesArray[index]["Folder"]; var majorGroup = filesArray[index]["MajorGroup"]; var btnMajorGroup = $("#MajorGroupSwitches").children("[folder='" + folder + "'][majorGroup='" + majorGroup + "']"); if (isFolderSelected(folder)) { //Show button btnMajorGroup.show(); buttonsShowing.push(btnMajorGroup); } else { //Major group not available with current filter settings, so hide it btnMajorGroup.hide(); } } //(Re)activate the first major group button inside current folder that was already visible var buttonActive = false; for (index in buttonsShowing) { var btnMajorGroup = buttonsShowing[index]; if (btnMajorGroup.hasClass("on")) { btnMajorGroup.click(); buttonActive = true; break; } } //If no previous button is found (i.e. first time in this Folder), then enable the default one if (!buttonActive) { //Enable the ones that should be enabled by default for (index in buttonsShowing) { var btnMajorGroup = buttonsShowing[index]; if (btnMajorGroup.attr("activeOnStartUp") == true) { btnMajorGroup.click(); buttonActive = true; break; } } } //There is no button that should be enabled by default, so activate the first one if (!buttonActive) { //Enable the ones that should be enabled by default var btnMajorGroup = buttonsShowing[0]; btnMajorGroup.click(); } } function isFolderSelected(folderName) { var result = false; //For each folder $('#FolderSwitches').children("div").each(function () { if ($(this).attr("folder") === folderName && $(this).hasClass("on")) { result = true; return; } }); return result; } function updateFolderHeaderHTML(html) { $(FolderHeader).html(html); } function updateMajorGroupHeaderHTML(html) { $(MajorGroupHeader).html(html); } function updateMajorGroupFooterHTML(html) { $(MajorGroupFooter).html(html); } function updateGridWithFilter() { //Build the filter array var filters = new Array(); //Disabled, search by terms no longer available since table is not that big and could confuse more than help! //addFiltersBasedOnTerms(filters); addFiltersBasedOnSwitches(filters); //Apply filter (at least one condition of each term must be satisfied: 'and') $("#kgrData").data("kendoGrid").dataSource.filter({ logic: "and", filters: filters }); //Add Google Analytics tracking for each link (links are dynamically created everytime grid is updated, that's why this has to be done here) $('a[download]').on('click', function () { ga('send', 'event', { eventCategory: 'manual_push', eventAction: 'download', eventLabel: this.href }); }); //To help user avoid missing results, scroll to top $("#kgrData").children(".k-grid-content").scrollTop(0); } function addFiltersBasedOnTerms(filters) { //Get what user typed var val = $('#searchBox').val(); //Separate values by comma var terms = val.split(','); //For each value for (i in terms) { //Get the term and remove any spaces (left/right) var term = terms[i]; term = term.trim() //If term is valid if (term !== "") { //Create filter for this specific term var filter = { logic: "or", filters: [ { field: "folder", operator: "contains", value: term }, { field: "MajorGroup", operator: "contains", value: term }, { field: "SubGroup", operator: "contains", value: term }, { field: "Files", operator: "contains", value: term }, { field: "Description", operator: "contains", value: term + ' ' }, { field: "Description", operator: "contains", value: ' ' + term }, { field: "Description", operator: "eq", value: term } ] }; //Add this term's filter to the filter collection filters.push(filter); } } } function addFiltersBasedOnSwitches(filters) { //For each folder $('#FolderSwitches').children("div").each(function () { if ($(this).hasClass("on")) { var filter = { field: "Folder", operator: "equals", value: $(this).attr("folder") } //Add this term's filter to the filter collection filters.push(filter); } }); //For each major group $('#MajorGroupSwitches').children("div").each(function () { if ($(this).hasClass("on")) { var filter = { field: "MajorGroup", operator: "equals", value: $(this).attr("majorGroup") } //Add this term's filter to the filter collection filters.push(filter); } }); }
File type
Major topic / Special groupings
Disclaimer: This web site contains data tables, figures, maps, analyses and technical notes from the current revision of the World Population Prospects. These documents do not imply the expression of any opinion whatsoever on the part of the Secretariat of the United Nations concerning the legal status of any country, territory, city or area or of its authorities, or concerning the delimitation of its frontiers or boundaries.