do nothing if the clicked facet has facetValueDisabled class; do not move facet when cubicweb:idx == 0 stable
authorKatia Saurfelt <katia.saurfelt@logilab.fr>
Thu, 09 Jul 2009 11:17:04 +0200
branchstable
changeset 2342 923111e6ab33
parent 2341 6db26d081c37
child 2343 5f5259e838cb
do nothing if the clicked facet has facetValueDisabled class; do not move facet when cubicweb:idx == 0
web/data/cubicweb.formfilter.js
--- a/web/data/cubicweb.formfilter.js	Thu Jul 09 09:42:44 2009 +0200
+++ b/web/data/cubicweb.formfilter.js	Thu Jul 09 11:17:04 2009 +0200
@@ -126,6 +126,9 @@
 		});
 		facet.find('div.facetCheckBox').click(function () {
 		    var $this = jQuery(this);
+		    if ($this.hasClass('facetValueDisabled')){
+		     	    return
+		    }
 		    if ($this.hasClass('facetValueSelected')) {
 			$this.removeClass('facetValueSelected');
 			$this.find('img').each(function (i){
@@ -139,16 +142,19 @@
 			    }
 			});
 			var index = parseInt($this.attr('cubicweb:idx'));
-			var shift = jQuery.grep(facet.find('.facetValueSelected'), function (n) {
-			    var nindex = parseInt(n.getAttribute('cubicweb:idx'));
-			    return nindex > index;
-			}).length;
-			index += shift;
-			var parent = this.parentNode;
-			var $insertAfter = jQuery(parent).find('.facetCheckBox:nth('+index+')');
-			if ( ! ($insertAfter.length == 1 && shift == 0) ) {
-			    // only rearrange element if necessary
-			    $insertAfter.after(this);
+			// we dont need to move the element when cubicweb:idx == 0
+			if (index > 0){
+			    var shift = jQuery.grep(facet.find('.facetValueSelected'), function (n) {
+				    var nindex = parseInt(n.getAttribute('cubicweb:idx'));
+				    return nindex > index;
+				}).length;
+			    index += shift;
+			    var parent = this.parentNode;
+			    var $insertAfter = jQuery(parent).find('.facetCheckBox:nth('+index+')');
+			    if ( ! ($insertAfter.length == 1 && shift == 0) ) {
+				// only rearrange element if necessary
+				$insertAfter.after(this);
+			    }
 			}
 		    } else {
 			var lastSelected = facet.find('.facetValueSelected:last');