Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJAX data sources and multiple tokens #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

andrewsnowden
Copy link

I've added some functionality that I needed, not sure if you'd like to pull these upstream.

You can fetch data remotely using an onFilterChanged callback and a setValues call. You can also specify a list of tokens to match (e.g. ["@", "#"]). I've added a demo for both of these functions in the demo.html

Added an onFilterChanged callback which is called whenever the filter
expression changes.
This can fetch data remotely and use the setValues to populate the
newly updated set of values.
An example of using this to show Github repositories is included in the
demo page.
Tokens can be passed in as an array.
The token that was matched is passed into the elementFactory as well as
the onFilterChanged callback
@chrisgraham
Copy link

Thanks for that, you saved me.

Note that this code is not compatible with IE8, without changes. The forEach needs changing to a regular for loop, and you need some polyfills..

if (!Array.prototype.filter) {
  Array.prototype.filter = function(
     a, // a function to test each value of the array against. Truthy values will be put into the new array and falsy values will be excluded from the new array
    b, // placeholder
    c, // placeholder 
    d, // placeholder
    e  // placeholder
  ) {
      c = this; // cache the array
      d = []; // array to hold the new values which match the expression
      for (e in c) // for each value in the array, 
        ~~e + '' == e && e >= 0 && // coerce the array position and if valid,
        a.call(b, c[e], +e, c) && // pass the current value into the expression and if truthy,
        d.push(c[e]); // add it to the new array

      return d // give back the new array
  };
}

if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function (searchElement , fromIndex) {
    var i,
        pivot = (fromIndex) ? fromIndex : 0,
        length;

    if (!this) {
      throw new TypeError();
    }

    length = this.length;

    if (length === 0 || pivot >= length) {
      return -1;
    }

    if (pivot < 0) {
      pivot = length - Math.abs(pivot);
    }

    for (i = pivot; i < length; i++) {
      if (this[i] === searchElement) {
        return i;
      }
    }
    return -1;
  };
}

Also note the code is not compatible with jfelsinger's second token delimiter regexp workaround in #6. That's fine though, that was kind of a hack. The first token delimiter workaround (removing \b) still works.

@andrewsnowden
Copy link
Author

Thanks, will try dig out a copy of IE8 and patch and test on that as soon as I get a chance

@chrisgraham
Copy link

Oh, actually I assumed that this was a problem in your code, and I just realised it wasn't - it's an original 'bug' (incompatibility, really) in sew. Sorry for pinning it on you ;).

@smilesrg
Copy link

Why don't you accept this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants