src/Filterizr.js
/**
   * Performs multifiltering with AND/OR logic.
   * @param {String} toggledFilter the filter to toggle
   */
Performs multifiltering with AND/OR logic.
@param {String} toggledFilter the filter to toggle
Performs multifiltering with AND / OR logic . @param { String } toggledFilter the filter to toggle
toggleFilter(toggledFilter) {
    let activeFilters = this.options.filter;
    if (activeFilters === 'all') {
      activeFilters = toggledFilter;
    } else {
      if (Array.isArray(activeFilters)) {
        if (activeFilters.includes(toggledFilter)) {
          activeFilters = activeFilters.filter(f => f !== toggledFilter);
          if (activeFilters.length === 1) activeFilters = activeFilters[0];
        } else {
          if(toggledFilter) {
            activeFilters.push(toggledFilter);
          }
        }
      } else {
        activeFilters = activeFilters === toggledFilter
          ? 'all' 
          : [activeFilters, toggledFilter]; 
      }
    }
    if(Array.isArray(activeFilters)) {
      activeFilters = activeFilters.filter(filter => {
        return !!filter;
      });
    }
    this.options.filter = activeFilters;
    this.filter(this.options.filter);
  }
toggleFilter ( toggledFilter ) { let activeFilters = this . options . filter ; if ( activeFilters === 'all' ) { activeFilters = toggledFilter ; } else { if ( Array . isArray ( activeFilters ) ) { if ( activeFilters . includes ( toggledFilter ) ) { activeFilters = activeFilters . filter ( f => f !== toggledFilter ) ; if ( activeFilters . length === 1 ) activeFilters = activeFilters [ 0 ] ; } else { if ( toggledFilter ) { activeFilters . push ( toggledFilter ) ; } } } else { activeFilters = activeFilters === toggledFilter ? 'all' : [ activeFilters , toggledFilter ] ; } } if ( Array . isArray ( activeFilters ) ) { activeFilters = activeFilters . filter ( filter => { return ! ! filter ; } ) ; } this . options . filter = activeFilters ; this . filter ( this . options . filter ) ; }
Performs multifiltering with AND/OR logic.
Performs multifiltering with AND / OR logic .
// If set to all then just set to new category // If the activeFilters are an array // Check if the toggledFilter is in the array and remove it // In case there is only 1 item now left in the array, flatten it // If the item is not in the array then simply push it // If the activeFilters === toggledFilter revert to 'all' // Otherwise start array // control undefined in array // Update active filter in Filterizr's options // Trigger a refilter