(function($) {
// plugin init
$.fn.filterFacets = function(options) {
$.fn.filterFacets.opts = $.extend({}, $.fn.filterFacets.defaults, options);
return this.each(function() {
var $this = $(this);
$this.initial_run = true;
// event handling
$.fn.filterFacets.bind_events($this);
$.fn.filterFacets.load_data($this, $.fn.filterFacets.opts.url, $.fn.filterFacets.build_ui);
});
};
// load json data
$.fn.filterFacets.load_data = function($this, url, callback) {
// loader...
//$(".loader").show();
$("#sort_options").attr("disabled", true);
$this.find("input[type=checkbox]").attr("disabled", true);
$this.find("li").css("color", "grey");
$("#filter-count").html("
");
// build params
var params = {reistype:$.fn.filterFacets.opts.reistype};
var facets = $("div.facet");
if($this.initial_run) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i
';
$(datefield_tpl).data("facet-name", value.facet_name).appendTo($this);
$.datepicker.setDefaults($.datepicker.regional['nl']);
var depdate = $("#depdate");
depdate.datepicker({
dateFormat: 'd-m-yy',
onSelect: function () {
$.fn.filterFacets.load_data($this, $.fn.filterFacets.opts.url, $.fn.filterFacets.build_ui);
},
beforeShowDay: function(date) {
el = new Array();
temp = $.datepicker.formatDate('yy-mm-dd',date)+"T00:00:00Z";
if(jQuery.inArray(temp, datearr) > -1){
el[0] = true;
} else {
el[0] = false;
}
return el;
}
});
} else {
$this.append($.tmpl(facet_tpl, value).data("facet-name", value.facet_name));
}
//$(".loader").hide();
$("#sort_options").removeAttr("disabled");
});
$("#filter-count").text("("+data.results.length+")");
$(".item").hide().removeClass("light").removeClass("dark");
for(var i=0; i").width($this.width()).height($this.height());
$this.append(loader);
// clear
$this.append($(""));
// refresh
$.fn.filterFacets.refresh_ui($this);
};
// bind ui events
$.fn.filterFacets.bind_events = function($this) {
$this.find("input[type=checkbox]").live('click.filter-facets', function () {
$.fn.filterFacets.load_data($this, $.fn.filterFacets.opts.url, $.fn.filterFacets.build_ui);
});
$this.find("input[type=radio]").live('click.filter-facets', function () {
$.fn.filterFacets.load_data($this, $.fn.filterFacets.opts.url, $.fn.filterFacets.build_ui);
});
$("#sort_options").live('change.filter-facets', function () {
$.fn.filterFacets.load_data($this, $.fn.filterFacets.opts.url, $.fn.filterFacets.build_ui);
});
$this.find("div.modified h1").live('click.filter-facets', function () {
$("div.facet").has($(this)).find("input:checked").attr("checked", "");
$("div.facet").has($(this)).find("input[type=text]").val("");
$.fn.filterFacets.load_data($this, $.fn.filterFacets.opts.url, $.fn.filterFacets.build_ui);
});
$("#refine").live('click', function() {
$("#filter-facets").toggle();
$("#filter-toggle").toggleClass("toggled");
$("#filter-toggle").toggleClass("untoggled");
if($("#filter-toggle").hasClass("toggled")){
jQuery.scrollTo($("#filter-toggle"));
}
return false;
});
}
// refresh ui
$.fn.filterFacets.refresh_ui = function($this) {
var data = $this.data('filter-facets');
$this.find(".facet").each(function(i, value) {
var facet = $(this);
if(facet.find("input[type=checkbox]:checked").length || (facet.find("#depdate").length && facet.find("#depdate").val().strip())) {
facet.addClass("modified");
} else {
facet.removeClass("modified");
}
});
}
// plugin defaults
$.fn.filterFacets.defaults = {
url: 'http://dipsy.egypte.nl/reisfilter/?callback=?',
reistype: 5
};
})(jQuery);