Git Product home page Git Product logo

Comments (16)

jharding avatar jharding commented on June 15, 2024

No reason why we have a hard dependency on jQuery right now other than that's what we use. If we can verify typeahead.js works as expected with Zepto, I'd be ok with loosening up the hard dependency on jQuery to a dependency on jQuery or Zepto.

from typeahead.js.

dsimmons avatar dsimmons commented on June 15, 2024

Good to hear! 👍

I tried using typeahead.js + Zepto a few days ago to no avail unfortunately (obviously resolving the jQuery dependency manually for the time being). I started debugging the stack trace but didn't get far into looking into it.

If I have some free time over the next few weeks, I'll try to come up with a fix and submit a PR (if someone doesn't beat me to it first).

from typeahead.js.

jharding avatar jharding commented on June 15, 2024

FWIW, I tried to run the test suite using Zepto in place of jQuery, but the library we use for mocking out ajax requests, doesn't support Zepto. So if we were to support Zepto, we would first need to patch jasmine-ajax first. This isn't a big deal, just something to be aware of.

from typeahead.js.

dsimmons avatar dsimmons commented on June 15, 2024

Hmm, interesting... I haven't tried this out specifically yet. In looking through the commit logs, it looks like it was supported at one point? Now it says Supports both Prototype.js and jQuery. 😦

What I don't know is if that means that it doesn't explicitly support Zepto, or if the two are incompatible altogether. I suppose I'll have to investigate further on that front.

from typeahead.js.

dotnetchris avatar dotnetchris commented on June 15, 2024

Seeing this closed, does this mean it was abandoned?

from typeahead.js.

jharding avatar jharding commented on June 15, 2024

It's something I have no interest in working on myself, but if someone submits a compelling pull request, I'd have no problem accepting it.

from typeahead.js.

dsimmons avatar dsimmons commented on June 15, 2024

Due to time constraints, we ended up not using typeahead.js for the project I was working on -- I'm also running low on extracurricular time to take on this task, so although I would love to see this happen, I more than likely won't be submitting a PR anytime soon.

from typeahead.js.

dotnetchris avatar dotnetchris commented on June 15, 2024

We analyzed this at my work to see how significant of an effort this would be to allow zepto to work instead of jquery, and it does seem rather significant. Many of the jquery dependencies exist in zepto however the substantial usage of deferred seems to be the most significant piece that does not exist in zepto. I can see why this was passed over.

from typeahead.js.

dsimmons avatar dsimmons commented on June 15, 2024

Yep, that's about the same conclusion that we arrived at. I would love to try to resolve the dependencies and make the library choice a non-issue, but as you mentioned, it's no trivial task (unfortunately).

from typeahead.js.

tassilogroeper avatar tassilogroeper commented on June 15, 2024

Hi,
@dotnetchris and @dsimmons have you seen this one: https://github.com/sudhirj/simply-deferred ?
I was trying to use typeahead with zepto, too. Would love to combine both.

Any chance you could post your work done so far?

from typeahead.js.

dsimmons avatar dsimmons commented on June 15, 2024

I didn't get very far before quickly realizing that it wouldn't be as easy as I thought it would, so I unfortunately discarded my work and moved on with a different approach. 😦 Sorry!

edit: @pheadeaux, I haven't checked that project out. Most of my non-jQuery deferred experience has been with q.

from typeahead.js.

jasonsperske avatar jasonsperske commented on June 15, 2024

I have started working on a project using the Zurb Foundation 4 framework and have managed to get typeahead.js working with Zepto (and jQuery) with remote and local data sources. Here is what I changed I haven't tried to pass all of the tests in typeahead.js yet but if this helps anyone with more free time I thought it would at least be worth sharing. First, Zepto.js by default doesn't have deferred support, so in addition to replacing jQuery with Zepto, I also included the excellent library simply-deferred. I also initialized it to make Zepto behave more closely to jQuery with this one line:

Deferred.installInto(Zepto);

Then I made the following changes to typeahead.js. At line 328 there is a block of code that is responsible for executing the $.ajax() request (without this change any attempt to resolve the remote resource will only result in a request to the same page that the typeahead input is located (the effect being an ajax request with no URL)):

_sendRequest: function(url) {
  var that = this, jqXhr = pendingRequests[url];
  if (!jqXhr) {
    incrementPendingRequests();
    jqXhr = pendingRequests[url] = $.ajax(url, this.ajaxSettings).always(always);
  }

This uses a jQuery shortcut of providing the URL as the first argument and the ajaxSettings object as the second argument. In Zepto $.ajax() only takes one argument (a pattern that jQuery actually natively supports as well, the URL then object method is compensated for by type checking the first and second arguments), so I changed it to this block that work in both frameworks:

_sendRequest: function(url) {
  var that = this, jqXhr = pendingRequests[url], ajaxOptions = {'url': url};
  if (!jqXhr) {
    incrementPendingRequests();
    $.extend(ajaxOptions, this.ajaxSettings);
    jqXhr = pendingRequests[url] = $.ajax(ajaxOptions).always(always);
  }

Then at the end of typeahead.js there are two references to jQuery directly:

      jQuery.fn.typeahead = function(method) {
        if (methods[method]) {
            return methods[method].apply(this, [].slice.call(arguments, 1));
        } else {
            return methods.initialize.apply(this, arguments);
        }
    };
  })();
})(window.jQuery); 

I changed that code to this:

      $.extend($.fn, {
        typeahead: function(method) {
            if (methods[method]) {
                return methods[method].apply(this, [].slice.call(arguments, 1));
            } else {
                return methods.initialize.apply(this, arguments);
            }
        }
    });
  })();
})(window.$);

And with that the code is now working (at least for my needs). I did have to add a bunch of CSS to compensate with the effects of the dynamically added HTML, but that is Foundation 4 Specific and I figured anyone who was working on just Zepto and typeahead would be interested in this.

from typeahead.js.

jasonsperske avatar jasonsperske commented on June 15, 2024

I've started working on a proper patch that adds in zepto.js support so far I have the changes I outlined in my previous comment and I've refactored the Jasmin tests so you can see that jQuery support is completely intact. the playground-zepto.html works but the automated tests are much more rigorous, because of the failed Jasmin tests with Zepto I don't think this is ready for a full on push, however if it helps anyone else here is my branch:

https://github.com/jasonsperske/typeahead.js/tree/zepto-support

from typeahead.js.

andy-polhill avatar andy-polhill commented on June 15, 2024

Once all of the relevant shims are in place, typeahead seems to work with zepto.js with the exception of this one selector..

            .find(".tt-suggestions > .tt-suggestion");

As far as I can tell the immediate child selector isn't supported by zepto.

from typeahead.js.

dsimmons avatar dsimmons commented on June 15, 2024

Actually, now that you mention it, I think that might have been the realization that I'd had after shimming it myself locally before deciding to go ahead and switch gears because it was proving to be too much of a time sink.

from typeahead.js.

yugaljindle avatar yugaljindle commented on June 15, 2024

Tried my best to work with zepto. Finally ended up creating my own autocomplete/typeahead which works with zepto. zepto-autocomplete, finally we have an autocomplete plugin native to zepto.

https://github.com/yugal/zepto-autocomplete

Worked well for me in production :)

from typeahead.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.