`;
$(".variable-comparison-popup .var-list").append(html);
}
$(".variable-comparison-popup .var-in-cart").html(data.length);
})
.fail(function() {
console.log("error");
})
}
//remove all variables
function compare_variable_clear(){
eraseCookie("variable-compare");
compare_variable_popup_update();
compare_variable_popup_toggle();
return;
}
function compare_variable_refresh_selection(){
vars=get_selected_variables();
//uncheck all
$(".compare").prop( "checked", false );
//check selected only
for(var i=0;i < vars.length;i++) {
$(".compare[value='"+vars[i]+"']").prop("checked",true);
}
compare_variable_popup_update();
}
//update selected variables on page/tab changes
$(document).on('visibilitychange', function() {
if(document.visibilityState == 'visible') {
compare_variable_refresh_selection();
}
});
$(document).ready(function(){
compare_variable_popup_update();
compare_variable_popup_toggle();
});
function toggle_clear(el){
console.log($(el).closest(".items-container").find(".chk:checked").length);
if ($(el).closest(".items-container").find(".chk:checked").length >0){
$(el).closest(".sidebar-filter").find(".clear-button-container").removeClass("clear-disabled").addClass("clear-enabled");
$(el).closest(".sidebar-filter").find(".clear-button-container").find(".selected-items").text($(el).closest(".items-container").find(".chk:checked").length);
}else{
$(el).closest(".sidebar-filter").find(".clear-button-container").removeClass("clear-enabled").addClass("clear-disabled");
}
}
function init_facet_stats(el){
let selected_items=$(el).find(".items-container").find(".chk:checked").length;
let total_items=$(el).find(".items-container").find(".chk").length;
if (selected_items >0){
$(el).closest(".sidebar-filter").find(".clear-button-container").removeClass("clear-disabled").addClass("clear-enabled");
$(el).closest(".sidebar-filter").find(".clear-button-container").find(".selected-items").text(selected_items);
$(el).closest(".sidebar-filter").find(".clear-button-container").find(".total-items").text(total_items);
}else{
$(el).closest(".sidebar-filter").find(".clear-button-container").removeClass("clear-enabled").addClass("clear-disabled");
}
}
//toggle checkboxes on page load
function refresh_facet_options(){
jQuery.each($(".sidebar-filter"), function( i, el ) {
init_facet_stats($(el));
});
}
$(function() {
refresh_facet_options();
});
//clear variable selection
$(document.body).on("click",".clear-variables", function(){
compare_variable_clear();
compare_variable_refresh_selection();
return false;
});
$(document.body).on("click",".var-remove", function(e){
let id=$(this).attr('data-value');
$(".compare[value='"+id+"']").trigger("click");
update_compare_variable_list("remove",id);
compare_variable_refresh_selection();
return false;
});
$(document).ready(function() {
var page_first_load=true;
toggle_reset_search_button();
var State=History.getState();
if(!State.data.page_state_data){
page_first_load=false;
let search_state=serialize_form();
let page_state_data={
'search_options': $("#catalog-search-form").serializeArray(),
'search_results': null
};
History.replaceState({state:search_state,page_state_data}, document.title, "?"+search_state);
}else{
load_current_state();
toggle_reset_search_button();
}
function reset_page(){
$("#page").val(1);
}
//submit search form
$(document.body).on("click","#submit_search", function(){
$("#sort_by").val("");
reset_page();
change_state();
return false;
});
//change page size
$(document.body).on("click",".change-page-size", function(){
ps=$(this).attr("data-value");
console.log(ps);
$("#page").val(1);
$("#ps").val(ps);
change_state();
});
$(document.body).on("click",".remove-filter", function(){
name=$(this).attr("data-type");
value=$(this).attr("data-value");
el_name="[name='" + name + "']," + "[name='" + name + "[]']";
elements=$(el_name);
console.log(elements);
if (name=="sid"){
$("#sid").val("");
}
if (name=='years'){
$("#from").val("");
$("#to").val("");
}
if (elements.length>0){
if (elements.prop("type")=='checkbox'){
named_el=$("[name='" + name + "'][value='"+value+"']");
console.log(named_el);
named_el.trigger('click');
console.log(named_el);
}
else if(elements.prop("type")=='text' || elements.prop("tagName").toLowerCase()=='select'){
elements.prop("value",'');
}
}
$(this).hide();
change_state();
});
function search(){
search_state=$("#catalog-search-form").serialize();
$( "#search-result-container" ).html('Loading, please wait...');
$.get('https://microdata.worldbank.org/index.php/catalog/search?'+search_state, function( data ) {
$( "#search-result-container" ).html( data );
let page_state_data={
'search_options': $("#catalog-search-form").serializeArray(),
'search_results': null
};
//reset nav-tabs
$(".dataset-type-tab").find(".type-count").html("0");
//update nav-tabs
let types_summary=$(".type-summary").attr("data-types");
if(types_summary){
types_summary=JSON.parse(types_summary);
jQuery.each(types_summary, function(data_type, counts ) {
$(".dataset-type-tab-"+data_type).find(".type-count").html(parseInt(counts).toLocaleString());
});
}
});
}
//call this for search
function change_state(){
console.log("change_state called");
let search_state=serialize_form(); //don't include empty elements
let page_state_data={
'search_options': $("#catalog-search-form").serializeArray(),
'search_results': null
};
History.pushState({state:search_state,page_state_data}, document.title + '/search - ' + search_state, "?"+search_state);
}
function serialize_form(){
return $("#catalog-search-form :input").filter(function(index, element) {
return $(element).val() != '';
}).serialize();
}
//sort dropdown
$(document.body).on("change","#sort-by-select", function(){
let sort_order=$(this).find(':selected').data('sort');
let sort_by=$(this).val();
$("#sort_by").val(sort_by);
$("#sort_order").val(sort_order);
change_state();
});
$(document.body).on("click",".dataset-type-tab", function(){
$( ".chk-type").prop("checked",false);
el=$("[name='type[]'][value='"+ $(this).attr("data-value") +"']");
el.prop("checked",true);
reset_page();
$( "#tab_type" ).val($(this).attr("data-value"));
window.location.href='https://microdata.worldbank.org/index.php/catalog/?'+serialize_form();
return false;
});
//pagination link
$(document.body).on("click",".pagination .page-link", function(){
$( "#page" ).val($(this).attr("data-page"));
change_state();
return false;
});
//check/select filter
$(document.body).on("change",".filters-container .chk, .filters-container select", function(){
reset_page();
change_state();
toggle_clear(this);
});
//clear filter
$(document.body).on("click",".filters-container .lnk-filter-reset", function(){
$(this).closest(".filter-box").find(".chk").prop("checked",false);
change_state();
toggle_clear(this);
});
$(document.body).on("keypress",".search-keywords", function(e){
var code = e.keyCode;
toggle_reset_search_button();
if(code==13){
$('#submit_search').trigger("click");
return false;
}
});
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
var State = History.getState(); // Note: We are using History.getState() instead of event.state
//$( "#catalog-search-form" ).html( State.data.data );
window.data=State.data;
console.log("loading state");
console.log(State);
//$( "#search-result-container" ).html(State.data.search_results);
load_current_state();
});
function load_current_state(){
if(page_first_load==true){
page_first_load=false;
return;
}
var State=History.getState();
if(!State.data.page_state_data){
return false;
}
reset_all_filters();
jQuery.each(State.data.page_state_data.search_options, function( i, field ) {
elements=$("[name='" + field.name + "']");
if (elements.prop("type")=='checkbox'){
named_el=$("[name='" + field.name + "'][value='"+field.value+"']");
named_el.prop("checked",true);
}
else if(elements.prop("type")=='text' || elements.prop("tagName").toLowerCase()=='select'){
elements.prop("value",field.value);
}
});
//only time search function should be called
search();
}
function reset_all_filters(){
//uncheck all checkboxes
$(".filters-container .chk").prop("checked",false);
//reset select
$(".filter-container .form-control").prop("value",'');
}
function toggle_reset_search_button(){
if (!$("#search-keywords").val()){
$(".clear-search-button").hide();
}
else{
$(".clear-search-button").show();
}
}
//show/hide study sub-variable search
$(document.body).on("click",".vsearch", function(event){
event.stopPropagation();
$(this).parent().toggleClass("expand");
var result=$(this).parent().find(".vsearch-result");
if (result.html()!='' ){
result.empty().hide();
}
else{
result.show().html('Loading').load($(this).prop("href"), function(data){
//attach compare handlers
//variable_compare_handlers();
});
//result.parent().find(".open-close").prop("src",'images/arrow_down.gif');
}
//compare_var_summary();
return false;
})
//show variable details in a modal dialog
$(document.body).on("click",".variable-list .vrow .link", function(event){
event.stopPropagation();
var vrow=$(this).closest(".vrow");
var target='';
if(typeof $(vrow).attr("data-url-target") != 'undefined'){
target=$(vrow).attr("data-url-target");
}
if(target==''){
window.location=$(vrow).attr("data-url");
}
else{
window.simple_dialog("dialog_id",$(vrow).attr("data-title"),$(vrow).attr("data-url"));return false;
}
});
//variable info for compare variable
$(document.body).on("click",".var-box .var-name", function(event){
event.stopPropagation();
window.simple_dialog("dialog_id",$(this).text(),$(this).attr("href"));return false;
});
/////////////////////////////////////////////////////////////////////////////////////////////
// simple dialog
/////////////////////////////////////////////////////////////////////////////////////////////
window.simple_dialog=function simple_dialog(dialog_id,title,data_url){
if($("#"+dialog_id).length ==0) {
$("body").append('
\
\
\
\
'+title+'
\
\
\
\
\
\
\
\
');
}
else
{
/********* for jQuery ui modal *******/
/*dialog= $("#"+dialog_id);
dialog.html("loading...");
dialog.dialog({ title: title});*/
/********* for Bootstrap modal *********/
$('#'+dialog_id+' h5.modal-title').html(title);
$('#'+dialog_id+' div.modal-body').html("loading...");
}
// for jQuery ui modal
/*
dialog.dialog( "open" ); // for jQuery ui modal
//$('#'+dialog_id).load(data_url+'?ajax=1');//load content
*/
// for Bootstrap modal
$('#'+dialog_id).modal('show');// for Bootstrap modal
$('#'+dialog_id+' div.modal-body').load(data_url+'?ajax=1');//load content
}//end function
//compare checkbox click
//compare button
$(document.body).on("click",".btn-compare-var", function(event){
event.stopPropagation();
var sel_items=readCookie("variable-compare");
if(sel_items==null){
sel_items=Array();
}
else{
sel_items=sel_items.split(",");
}
if(sel_items.length>1){
window.open(CI.base_url+'/catalog/compare','compare');
}
else{
alert(i18n.js_compare_variable_select_atleast_2);return false;
}
return false;
});
$(document.body).on("click",".compare", function(event){
var sel_items=readCookie("variable-compare");
if(sel_items==null){
sel_items=Array();
}
else{
sel_items=sel_items.split(",");
}
if ($(this).prop("checked")){
update_compare_variable_list('add',$(this).val());
}
else{
update_compare_variable_list('remove',$(this).val());
}
compare_var_summary();
compare_variable_popup_update();
compare_variable_popup_toggle();
});
//disable even propogations for compare link
$(document.body).on("click",".var-quick-list .compare-variable", function(event){
event.stopPropagation();
});
//search facet options
$(document.body).on("keyup",".facet-filter-values", function(event){
var keywords=$(this).val().toLowerCase();
if (keywords.length>0){
console.log("showing...");
$(this).parent().find(".facet-filter-values-clear").show();
}else{
console.log("hiding...");
$(this).parent().find(".facet-filter-values-clear").hide();
}
$(this).closest(".items-container").find(".chk").each(function(){
if ($(this).data("title").toLowerCase().indexOf(keywords) >-1){
$(this).parent().show();
}else{
$(this).parent().hide();
}
});
});
//facet search clear button
$(document.body).on("click",".facet-filter-values-clear", function(event){
$(this).parent().parent().find('.facet-filter-values').val("").trigger('keyup');
});
});
This site uses cookies to optimize functionality and give you the best possible experience. If you continue to navigate this website beyond this page, cookies will be placed on your browser. To learn more about cookies, click here.