# HG changeset patch # User Sylvain Thénault # Date 1366897538 -7200 # Node ID 57f8a02550cc4ec54ff79777128ba6fc35682b2f # Parent 8666438778c72f792af41c6ef2eb258aaf97d695# Parent acff6dfcb9f4119fc8860a07136abea028e038cd merge default heads diff -r 8666438778c7 -r 57f8a02550cc web/data/cubicweb.facets.js --- a/web/data/cubicweb.facets.js Fri Apr 05 14:44:03 2013 +0200 +++ b/web/data/cubicweb.facets.js Thu Apr 25 15:45:38 2013 +0200 @@ -174,44 +174,34 @@ $($('#'+divid).get(0).parentNode).append($loadingDiv); } form.find('div.facet').each(function() { - var facet = $(this); - facet.find('div.facetCheckBox').each(function(i) { + var $facet = $(this); + $facet.find('div.facetCheckBox').each(function(i) { this.setAttribute('cubicweb:idx', i); }); - facet.find('div.facetCheckBox').click(function() { + $facet.find('div.facetCheckBox').click(function() { var $this = $(this); // NOTE : add test on the facet operator (i.e. OR, AND) // if ($this.hasClass('facetValueDisabled')){ // return // } if ($this.hasClass('facetValueSelected')) { - $this.removeClass('facetValueSelected'); - $this.find('img').each(function(i) { - if (this.getAttribute('cubicweb:unselimg')) { - this.setAttribute('src', UNSELECTED_BORDER_IMG); - } - else { - this.setAttribute('src', UNSELECTED_IMG); - } - this.setAttribute('alt', (_("not selected"))); - }); + facetCheckBoxUnselect($this); } else { - $(this).addClass('facetValueSelected'); - var $img = $(this).find('img'); - $img.attr('src', SELECTED_IMG).attr('alt', (_("selected"))); + facetCheckBoxSelect($this); } - facetCheckBoxReorder(facet); + facetCheckBoxReorder($facet); buildRQL.apply(null, jsfacetargs); }); - facet.find('select.facetOperator').change(function() { - var nbselected = facet.find('div.facetValueSelected').length; + $facet.find('select.facetOperator').change(function() { + var nbselected = $facet.find('div.facetValueSelected').length; if (nbselected >= 2) { buildRQL.apply(null, jsfacetargs); } }); - facet.find('div.facetTitle.hideFacetBody').click(function() { - facet.find('div.facetBody').toggleClass('hidden').toggleClass('opened'); + $facet.find('div.facetTitle.hideFacetBody').click(function() { + $facet.find('div.facetBody').toggleClass('hidden').toggleClass('opened'); $(this).toggleClass('opened'); + }); }); @@ -219,6 +209,28 @@ }); } +// facetCheckBoxSelect: select the given facet checkbox item (.facetValue +// class) +function facetCheckBoxSelect($item) { + $item.addClass('facetValueSelected'); + $item.find('img').attr('src', SELECTED_IMG).attr('alt', (_("selected"))); +} + +// facetCheckBoxUnselect: unselect the given facet checkbox item (.facetValue +// class) +function facetCheckBoxUnselect($item) { + $item.removeClass('facetValueSelected'); + $item.find('img').each(function(i) { + if (this.getAttribute('cubicweb:unselimg')) { + this.setAttribute('src', UNSELECTED_BORDER_IMG); + } + else { + this.setAttribute('src', UNSELECTED_IMG); + } + this.setAttribute('alt', (_("not selected"))); + }); +} + // facetCheckBoxReorder: reorder all items according to cubicweb:idx attribute function facetCheckBoxReorder($facet) { var sortfunc = function (a, b) {