124 facet.find('div.facetCheckBox').each(function (i) { |
124 facet.find('div.facetCheckBox').each(function (i) { |
125 this.setAttribute('cubicweb:idx', i); |
125 this.setAttribute('cubicweb:idx', i); |
126 }); |
126 }); |
127 facet.find('div.facetCheckBox').click(function () { |
127 facet.find('div.facetCheckBox').click(function () { |
128 var $this = jQuery(this); |
128 var $this = jQuery(this); |
|
129 if ($this.hasClass('facetValueDisabled')){ |
|
130 return |
|
131 } |
129 if ($this.hasClass('facetValueSelected')) { |
132 if ($this.hasClass('facetValueSelected')) { |
130 $this.removeClass('facetValueSelected'); |
133 $this.removeClass('facetValueSelected'); |
131 $this.find('img').each(function (i){ |
134 $this.find('img').each(function (i){ |
132 if (this.getAttribute('cubicweb:unselimg')){ |
135 if (this.getAttribute('cubicweb:unselimg')){ |
133 this.setAttribute('src', UNSELECTED_BORDER_IMG); |
136 this.setAttribute('src', UNSELECTED_BORDER_IMG); |
|
137 this.setAttribute('alt', (_('not selected'))); |
134 } |
138 } |
135 else{ |
139 else{ |
136 this.setAttribute('src', UNSELECTED_IMG); |
140 this.setAttribute('src', UNSELECTED_IMG); |
|
141 this.setAttribute('alt', (_('not selected'))); |
137 } |
142 } |
138 }); |
143 }); |
139 var index = parseInt($this.attr('cubicweb:idx')); |
144 var index = parseInt($this.attr('cubicweb:idx')); |
140 var shift = jQuery.grep(facet.find('.facetValueSelected'), function (n) { |
145 // we dont need to move the element when cubicweb:idx == 0 |
141 var nindex = parseInt(n.getAttribute('cubicweb:idx')); |
146 if (index > 0){ |
142 return nindex > index; |
147 var shift = jQuery.grep(facet.find('.facetValueSelected'), function (n) { |
143 }).length; |
148 var nindex = parseInt(n.getAttribute('cubicweb:idx')); |
144 index += shift; |
149 return nindex > index; |
145 var parent = this.parentNode; |
150 }).length; |
146 var $insertAfter = jQuery(parent).find('.facetCheckBox:nth('+index+')'); |
151 index += shift; |
147 if ( ! ($insertAfter.length == 1 && index == 0) ) { |
152 var parent = this.parentNode; |
148 // only rearrange element if necessary |
153 var $insertAfter = jQuery(parent).find('.facetCheckBox:nth('+index+')'); |
149 $insertAfter.after(this); |
154 if ( ! ($insertAfter.length == 1 && shift == 0) ) { |
|
155 // only rearrange element if necessary |
|
156 $insertAfter.after(this); |
|
157 } |
150 } |
158 } |
151 } else { |
159 } else { |
152 var lastSelected = facet.find('.facetValueSelected:last'); |
160 var lastSelected = facet.find('.facetValueSelected:last'); |
153 if (lastSelected.length) { |
161 if (lastSelected.length) { |
154 lastSelected.after(this); |
162 lastSelected.after(this); |
155 } else { |
163 } else { |
156 var parent = this.parentNode; |
164 var parent = this.parentNode; |
157 jQuery(parent).prepend(this); |
165 jQuery(parent).prepend(this); |
158 } |
166 } |
159 jQuery(this).addClass('facetValueSelected'); |
167 jQuery(this).addClass('facetValueSelected'); |
160 jQuery(this).find('img').attr('src', SELECTED_IMG); |
168 var $img = jQuery(this).find('img'); |
|
169 $img.attr('src', SELECTED_IMG).attr('alt', (_('selected'))); |
161 } |
170 } |
162 buildRQL.apply(null, evalJSON(form.attr('cubicweb:facetargs'))); |
171 buildRQL.apply(null, evalJSON(form.attr('cubicweb:facetargs'))); |
163 facet.find('.facetBody').animate({scrollTop: 0}, ''); |
172 facet.find('.facetBody').animate({scrollTop: 0}, ''); |
164 }); |
173 }); |
165 facet.find('select.facetOperator').change(function() { |
174 facet.find('select.facetOperator').change(function() { |