1(function($) { 2 3 var facetsInUse = function() { 4 var in_use = false; 5 6 $.each(FWP.facets, function(val, name) { 7 if (0 < val.length && 'paged' !== name) { 8 in_use = true; 9 return false; // exit loop 10 } 11 }); 12 13 return in_use; 14 } 15 16 var evaluateCondition = function(cond) { 17 var is_valid = false; 18 var compare_field; 19 var compare_value = cond.value; 20 21 if ('facets-empty' == cond.object) { 22 return false === facetsInUse(); 23 } 24 else if ('facets-not-empty' == cond.object) { 25 return true === facetsInUse(); 26 } 27 else if ('uri' == cond.object) { 28 compare_field = FWP_HTTP.uri; 29 if ('*' === cond.value.slice(-1)) { 30 var len = cond.value.length - 1; // minus the "*" 31 var temp_val = cond.value.substr(0, len); 32 if (temp_val === compare_field.substr(0, len)) { 33 compare_field = compare_value = temp_val; 34 } 35 } 36 } 37 else if ('total-rows' == cond.object) { 38 if ('undefined' === typeof FWP.settings.pager) { 39 return false; 40 } 41 compare_field = FWP.settings.pager.total_rows; 42 } 43 else if ('facet-' == cond.object.substr(0, 6)) { 44 var facet_name = cond.object.substr(6); 45 if ('undefined' === typeof FWP.facets[facet_name]) { 46 return false; 47 } 48 compare_field = FWP.facets[facet_name]; 49 } 50 else if ('template-' == cond.object.substr(0, 9)) { 51 compare_field = FWP.template; 52 compare_value = cond.object.substr(9); 53 } 54 55 // operators 56 if ('is' == cond.compare) { 57 if (isIntersect(compare_value, compare_field)) { 58 is_valid = true; 59 } 60 } 61 else if ('not' == cond.compare) { 62 if (! isIntersect(compare_value, compare_field)) { 63 is_valid = true; 64 } 65 } 66 67 return is_valid; 68 } 69 70 var isIntersect = function(arr1, arr2) { 71 72 arr1 = ("string" == typeof arr1 ) ? arr1.split(/\s*(?:,|$)\s*/) : arr1; 73 arr2 = ("string" == typeof arr2 ) ? arr2.split(/\s*(?:,|$)\s*/) : arr2; 74 75 // force arrays 76 arr1 = [].concat(arr1); 77 arr2 = [].concat(arr2); 78 79 // exact match 80 if (arr1.toString() === arr2.toString()) { 81 return true; 82 } 83 84 var result = arr1.filter(function(n) { 85 return arr2.indexOf(n) != -1; 86 }); 87 88 return result.length > 0; 89 } 90 91 var buildAliases = function() { 92 93 $.each(FWP.settings.num_choices, function(val, key) { 94 if (0 === val) { 95 $('.facetwp-facet-' + key).addClass('is-empty').removeClass('not-empty'); 96 } 97 else { 98 $('.facetwp-facet-' + key).addClass('not-empty').removeClass('is-empty'); 99 } 100 }); 101 102 $.each(FWP.facets, function(val, key) { 103 if (val && 0 < val.length) { 104 $('.facetwp-facet-' + key).addClass('is-active').removeClass('not-active'); 105 } 106 else { 107 $('.facetwp-facet-' + key).addClass('not-active').removeClass('is-active'); 108 } 109 }); 110 } 111 112 var doAction = function(action, is_valid) { 113 var item; 114 var is_custom = false; 115 var animation = ".addClass('is-hidden')"; // hide 116 117 if ('template' == action.object) { 118 item = '.facetwp-template'; 119 } 120 else if ('facets' == action.object) { 121 item = '.facetwp-facet'; 122 } 123 else if ('facet-' == action.object.substr(0, 6)) { 124 item = '.facetwp-facet-' + action.object.substr(6); 125 } 126 else if ('custom' == action.object) { 127 is_custom = true; 128 var lines = action.selector.split("\n"); 129 var selectors = []; 130 for (var i = 0; i < lines.length; i++){ 131 var selector = lines[i].replace(/^\s+|\s+$/gm, ''); 132 if (selector.length) { 133 selectors.push(selector); 134 } 135 } 136 item = selectors; 137 } 138 139 if (item.length < 1) { 140 return; 141 } 142 143 if (('show' == action.toggle && is_valid) || ('hide' == action.toggle && ! is_valid)) { 144 animation = ".removeClass('is-hidden')"; // show 145 } 146 147 // toggle 148 if (is_custom) { 149 $.each(item, function(selector) { 150 var first_part = selector.split('.')[0]; 151 152 if (['$EMPTY', '$NONEMPTY', '$ACTIVE', '$INACTIVE'].includes(first_part)) { 153 154 if (!is_valid) { 155 if ('$EMPTY' == first_part) { 156 selector = selector.replace('$EMPTY', '$NONEMPTY'); 157 } 158 else if ('$NONEMPTY' == first_part) { 159 selector = selector.replace('$NONEMPTY', '$EMPTY'); 160 } 161 else if ('$ACTIVE' == first_part) { 162 selector = selector.replace('$ACTIVE', '$INACTIVE'); 163 } 164 else if ('$INACTIVE' == first_part) { 165 selector = selector.replace('$INACTIVE', '$ACTIVE'); 166 } 167 } 168 169 selector = selector.replace('$EMPTY', "$('.facetwp-facet.is-empty')"); 170 selector = selector.replace('$NONEMPTY', "$('.facetwp-facet.not-empty')"); 171 selector = selector.replace('$ACTIVE', "$('.facetwp-facet.is-active')"); 172 selector = selector.replace('$INACTIVE', "$('.facetwp-facet.not-active')"); 173 174 FWPCL.actions.push(selector + animation); 175 } 176 else { 177 FWPCL.actions.push(selector + animation); 178 } 179 }); 180 } 181 else { 182 FWPCL.actions.push("$('" + item + "')" + animation); 183 } 184 } 185 186 window.FWPCL = {}; 187 188 FWPCL.run = function() { 189 FWPCL.actions = []; 190 191 buildAliases(); 192 193 // each ruleset 194 $.each(FWP_JSON.rulesets, function(ruleset) { 195 196 // skip inactive rulesets 197 if ( 'undefined' !== typeof ruleset.active && false === ruleset.active) { 198 return; 199 } 200 201 // if no conditions, set to TRUE 202 var this_result = (ruleset.conditions.length < 1); 203 var result = []; 204 205 // foreach condition group 206 $.each(ruleset.conditions, function(cond_group) { 207 this_result = false;
208 209 // foreach "OR" condition 210 $.each(cond_group, function(cond_or) { 211 if (evaluateCondition(cond_or)) { 212 this_result = true; 213 return false; // exit loop 214 } 215 }); 216 217 result.push(this_result); 218 }); 219 220 // make sure no conditions are false 221 var is_valid = (result.indexOf(false) < 0); 222 var action_else = ('undefined' !== typeof ruleset.else) ? ruleset.else : 'flip'; 223 224 // apply actions 225 $.each(ruleset.actions, function(action) { 226 if (is_valid || 'flip' === action_else) { 227 doAction(action, is_valid); 228 } 229 }); 230 231 $.each(FWPCL.actions, function(action) { 232 eval(action); 233 }); 234 235 // do custom actions after each ruleset is applied 236 FWP.hooks.doAction('facetwp/ruleset/apply', { 237 ruleset: ruleset, 238 is_valid: is_valid, 239 action_else: action_else 240 }); 241 242 }); 243 244 // do custom actions after all rulesets are applied 245 FWP.hooks.doAction('facetwp/rulesets/apply'); 246 } 247 248 $().on('facetwp-loaded', function() { 249 FWPCL.run(); 250 }); 251})(fUtil);
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.