PageSourceSearch

https://www.jhrl.com/sites/all/themes/custom/vrweb_foundation/riottags/build/riot_solr_facet_select.js?tlse4v

js jhrl.com collected 2026-10-06 13:18:31 UTC 5,772 bytes, 174 lines download raw bytes

1riot.tag2('riot-solr-facet-select', '<h5 if="{opts.label}">{opts.label}</h5> <select __multiple="{isMultiSelect}" class="{chosen: isMultiSelect}" data-facetid="{instance.id}"> <option each="{items}" __selected="{active}" id="RiotSolrFacetSelect-{facet}" data-facetvalue="{facet}" value="{facet}"> {facet ? (facet < 1 ? \'Studio\' : Math.floor(facet)) : facetLabel} </option> </select>', ':scope ul.chosen-choices input { min-height: 36px; }', 'data-facetid="{instance.id}"', function(opts) {
2    var processItems,
3      tag = this,
4      def;
5    this.mixin('RiotSolrFacetProvider');
6
7    def = this.FacetGetDefinition();
8
9    this.isMultiSelect = def.definition
10      && def.definition.settings.settings['riot_solr'].hasOwnProperty('facet_multiselect')
11      && def.definition.settings.settings['riot_solr']['facet_multiselect'] ? 'multiple' : null;
12
13    this.selectPlaceholder = def.definition && def.definition.settings.settings['riot_solr'].hasOwnProperty('facet_select_placeholder') ? def.definition.settings.settings['riot_solr']['facet_select_placeholder'] : false;
14
15    this.optionPrefix = def.definition && def.definition.settings.settings['riot_solr'].hasOwnProperty('facet_select_option_prefix') ? def.definition.settings.settings['riot_solr']['facet_select_option_prefix'] : false;
16
17    this.optionSuffix = def.definition && def.definition.settings.settings['riot_solr'].hasOwnProperty('facet_select_option_suffix') ? def.definition.settings.settings['riot_solr']['facet_select_option_suffix'] : false;
18
19    (function ($, tag) {
20      tag.on('updated', function() {
21        var $chosen = $('select.chosen', tag.root).not('.chosen-processed');
22        if ($chosen.length && $chosen.find('option').length) {
23          $chosen.each(attachChosen);
24        }
25
26        $('select:not(".chosen")', tag.root).each(attachListener);
27
28        $('select.chosen').trigger('chosen:updated');
29      });
30
31      tag.on('removed', function() {
32        var $chosen = $('select.chosen-processed', tag.root);
33        $chosen.each(detachChosen);
34
35        $('select:not(".chosen")', tag.root).each(detachListener);
36      });
37
38      tag.on('RiotSolrUpdate', function() {
39        $('select.chosen').trigger('chosen:updated');
40      });
41
42      function attachChosen() {
43        $(this)
44          .chosen({
45            width: '100%',
46            placeholder_text_multiple: this.selectPlaceholder || tag.instance.label
47          })
48          .addClass('chosen-processed')
49          .on('change', tag.FacetClickHandlerMulti);
50      }
51
52      function detachChosen() {
53        $(this)
54          .chosen('destroy')
55          .removeClass('chosen-processed')
56          .off('change', tag.FacetClickHandlerMulti);
57      }
58
59      function attachListener() {
60        $(this)
61          .not('.listener-attached')
62          .addClass('listener-attached')
63          .on('change', tag.FacetClickHandlerSingle);
64      }
65
66      function detachListener() {
67        $(this)
68          .removeClass('listener-attached')
69          .off('change', tag.FacetClickHandlerSingle);
70      }
71    })(jQuery, this);
72
73    processItems = this.FacetProcessItems;
74
75    this.FacetProcessItems = function(results) {
76      var items = processItems.apply(tag, [results]),
77        i,
78        emp = {
79          facetLabel: this.selectPlaceholder || tag.instance.label,
80          active: true,
81          count: false,
82          default: true
83        };
84
85      if (!tag.isMultiSelect) {
86        items.unshift(emp);
87      }
88
89      var firstItem = items.shift();
90      items = this.applySort(items, 'facet', opts.sort_type, opts.sort_order);
91      items.unshift(firstItem);
92
93      for(i in items) {
94
95        if(items[i].facet) {
96          items[i].active = this.instance.isActive(items[i].facet);
97        }
98
99        if(!isNaN(items[i].count) && items[i].count !== false) {
100          var labeltxt;
101          labeltxt = (opts.remove_count ? items[i].facet : items[i].facet + ' (' + items[i].count + ')');
102          labeltxt = this.optionPrefix ? this.optionPrefix + labeltxt : labeltxt;
103          labeltxt = this.optionSuffix ? labeltxt + this.optionSuffix : labeltxt;
104
105          items[i].facetLabel = labeltxt;
106        }
107
108        if(items[i].active == true && !items[i].default) {
109          emp.active = false;
110        }
111
112      }
113      return items;
114    };
115
116    this.applySort = function(items, field, type, order) {
117      if (type === 'string') {
118        if(order === 'desc') {
119          items.sort(function(a, b) {
120            if (a[field] > b[field])
121              return -1;
122            if (a[field] < b[field])
123              return 1;
124            return 0;
125          });
126        }
127      }
128      else if (type === 'numeric') {
129        var r = order === 'asc' ? 1 : -1;
130        items.sort(function(a, b) {
131          return (a = parseFloat(a[field])), (b = parseFloat(b[field])), r * ((a > b) - (b > a));
132        });
133      }
134      else if (type === 'results') {
135        items.sort(function(a, b) {
136          return order === 'asc' ? (a.count - b.count) : (b.count - a.count);
137        });
138      }
139
140      return items;
141    }
142
143    this.FacetClickHandlerSingle = function(value) {
144      var v = value.target.value,
145        obj = {
146          item: {
147            facet: v
148          }
149        },
150        anyVal = tag.selectPlaceholder || tag.instance.label;
151
152      tag.FacetReset();
153
154      if (v !== anyVal) {
155        tag.FacetAdd(obj);
156      }
157    };
158
159    this.FacetClickHandlerMulti = function(value, params) {
160      if (params.hasOwnProperty('selected')) {
161        tag.FacetAdd({
162          item: {
163            facet: params.selected
164          }
165        });
166      } else if (params.hasOwnProperty('deselected')) {
167        tag.FacetRemove({
168          item: {
169            facet: params.deselected
170          }
171        });
172      }
173    }
174});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.