Sha256: 720279b92c3012203fc2f4414ffae25ac65e841da7ed86c64c5b098ef1581082

Contents?: true

Size: 1.4 KB

Versions: 11

Compression:

Stored size: 1.4 KB

Contents

var RomoWordBoundaryFilter = function(filterString, setElems, getElemTextContentCallback) {
  this.boundaryCharsRegex = /[\s-_]+/;
  this.matchingElems      = [];
  this.notMatchingElems   = [];
  this.filters            = filterString
                              .trim()
                              .toLowerCase()
                              .split(this.boundaryCharsRegex);

  Romo.array(setElems).forEach(Romo.proxy(function(elem) {
    var contentStack = getElemTextContentCallback(elem)
                         .trim()
                         .toLowerCase()
                         .split(this.boundaryCharsRegex).reverse();

    var match = this.filters.reduce(Romo.proxy(function(filterMatch, filter) {
      if (filterMatch === false) {
        // short-circuit the reduce
        return false;
      } else {
        var contentMatch = false;
        do {
          var content = contentStack.pop();
          if (content !== undefined && content.indexOf(filter) === 0) {
            contentMatch = true;
            // we found a match for this filter so we need to
            // break out of this do...while and go to next filter
            content = undefined;
          }
        } while(content !== undefined);
        return contentMatch;
      }
    }, this), true);

    if (match === true) {
      this.matchingElems.push(elem);
    } else {
      this.notMatchingElems.push(elem);
    }
  }, this));
}

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
romo-0.20.10 assets/js/romo/word_boundary_filter.js
romo-0.20.9 assets/js/romo/word_boundary_filter.js
romo-0.20.8 assets/js/romo/word_boundary_filter.js
romo-0.20.7 assets/js/romo/word_boundary_filter.js
romo-0.20.6 assets/js/romo/word_boundary_filter.js
romo-0.20.5 assets/js/romo/word_boundary_filter.js
romo-0.20.4 assets/js/romo/word_boundary_filter.js
romo-0.20.3 assets/js/romo/word_boundary_filter.js
romo-0.20.2 assets/js/romo/word_boundary_filter.js
romo-0.20.1 assets/js/romo/word_boundary_filter.js
romo-0.20.0 assets/js/romo/word_boundary_filter.js