Giter VIP home page Giter VIP logo

Comments (13)

mrsweaters avatar mrsweaters commented on June 6, 2024

This seems reasonable to me. Currently I'm hiding the menu when there is nothing found in the collection. Will this conflict with your goal?
https://github.com/zurb/tribute/blob/master/js/tribute.js#L197

from tribute.

mattschwarz avatar mattschwarz commented on June 6, 2024

Good question, it would be nice to be able to keep the menu available even when there is no result to give the event enough time to load another collection. Perhaps a loading state is in order?

from tribute.

mattschwarz avatar mattschwarz commented on June 6, 2024

To expand on that last thought: my project has a custom loading .gif and it would be great to display that in the menu as a dummy list item while the other collection loads. You could possibly also have a config option to keep the list hidden for those who don't care about a loading state like me :)

from tribute.

mrsweaters avatar mrsweaters commented on June 6, 2024

This makes sense, so maybe if you define an noMatchTemplate function we then load that instead of hiding the list?

from tribute.

mattschwarz avatar mattschwarz commented on June 6, 2024

That would be great!

from tribute.

mrsweaters avatar mrsweaters commented on June 6, 2024

Please test this pull request: #17

from tribute.

mattschwarz avatar mattschwarz commented on June 6, 2024

Looking good so far, just a couple things I've noticed based on how I think it should work:

  • After the collection is updated inside the tribute-no-match event, the list continues to render the noMatchTemplate instead of updating to show new results.
  • When you backspace to start filtering again (because the list doesn't update on its own), two lists begin to render, one behind the other.
  • The enter key no longer inserts the mention, instead a mouse click is required.
  • It seems the event fires at least twice when there is no match, but that could be a symptom of my code. In my experience it fires even when the list has been updated and there is in-fact a match. Below is some pseudo code that mimics what I'm doing.
var t = new Tribute({
            values: window.mentions,
            menuItemTemplate: function (item) {
                return '<li>' + item + '</li>';
            },
            noMatchTemplate: function (tribute) {
                return '<li>Finding more...</li>';
            },
            selectClass: 'selected',
        });

        // bind to element
        t.attach(element);

        // if no match is found, request another page and update list
        element.addEventListener('tribute-no-match', function(e) {
            var xhr = new XMLHttpRequest();

            // abort multiple requests
            try {
                xhr.abort();
            }
            catch(e) {}

            xhr.open('GET', '/following?action=get_following_for_mentions&get_remainder=true');
            xhr.send();

            xhr.addEventListener('load', function() {
                if (xhr.status === 200) {
                    var response = JSON.parse(xhr.response);

                    t.collection[0].values.push(response);
                }
            });
        });

from tribute.

mrsweaters avatar mrsweaters commented on June 6, 2024

@mattschwarz Thank you for testing it out! I'll take a look at this today.

from tribute.

mrsweaters avatar mrsweaters commented on June 6, 2024

@mattschwarz I have pushed up a bunch of fixes to that pull request. Along with the fixes in #18, there may be enough here for a major release. As far as the multiple calls to no-match, this happens because a lookup is fired on each keyup event. If collection values are being manipulated, you will have to be sure that duplicates are not inserted.

I have added the appendCurrent(values) and append(index, values) helper methods to make updating the current and arbitrary collections much easier.

from tribute.

mrsweaters avatar mrsweaters commented on June 6, 2024

I've merged into master, seems to be working pretty well.

from tribute.

mattschwarz avatar mattschwarz commented on June 6, 2024

Great, will test!

from tribute.

anubrij avatar anubrij commented on June 6, 2024

Hi, is there any way to add the no match text in current collection or select it
I mean suppose I write #thisIsHash and that is not in the value list , still want to have possibility to select this

from tribute.

nilesh-spotdraft avatar nilesh-spotdraft commented on June 6, 2024

How can we add click event on image in noMatchTemplate function template in angular?
noMatchTemplate: function(item) { return '

  • Invite info
  • `}

    from tribute.

    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.