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

Sensitive doesn't work #45

Open
AntoineTurmel opened this issue Feb 10, 2016 · 2 comments
Open

Sensitive doesn't work #45

AntoineTurmel opened this issue Feb 10, 2016 · 2 comments

Comments

@AntoineTurmel
Copy link

Typing first two letters "mu", the first result is "HackMurphy" instead of "mutmaurice"...

$("#full").mention({
sensitive:true,
users:
 [{
                    name: 'Lindsay Made',
                    username: 'LindsayM',
                    image: 'http://placekitten.com/25/25'
                }, {
                    name: 'Rob Dyrdek',
                    username: 'robdyrdek',
                    image: 'http://placekitten.com/25/24'
                }, {
                    name: 'Rick Bahner',
                    username: 'RickyBahner',
                    image: 'http://placekitten.com/25/23'
                }, {
                    name: 'Jacob Kelley',
                    username: 'jakiestfu',
                    image: 'http://placekitten.com/25/22'
                },{
                    name: 'John Doe',
                    username: 'HackMurphy',
                    image: 'http://placekitten.com/25/21'
                }, {
                    name: 'Maurice',
                    username: 'mutmaurice',
                    image: 'http://placekitten.com/25/21'
                }, {
                    name: 'Charlie Edmiston',
                    username: 'charlie',
                    image: 'http://placekitten.com/25/20'
                }, {
                    name: 'Andrea Montoya',
                    username: 'andream',
                    image: 'http://placekitten.com/24/20'
                }, {
                    name: 'Jenna Talbert',
                    username: 'calisunshine',
                    image: 'http://placekitten.com/23/20'
                }, {
                    name: 'Street League',
                    username: 'streetleague',
                    image: 'http://placekitten.com/22/20'
                }, {
                    name: 'Loud Mouth Burrito',
                    username: 'Loudmouthfoods',
                    image: 'http://placekitten.com/21/20'
                }]
            });
@Xawier
Copy link

Xawier commented May 5, 2016

+1

It's work only with one, 1st letter... :(

@Xawier
Copy link

Xawier commented May 5, 2016

Ok, i repair this. Now work with every letter. Here you have _sorter function:

_sorter = function(items) {
                    if (items.length && settings.sensitive) {
                        var currentUser = _extractCurrentQuery(this.query, this.$element[0].selectionStart).substring(1),
                            i, len = items.length,
                            priorities = {
                                highest: [],
                                high: [],
                                med: [],
                                low: []
                            }, finals = [];
                        if (currentUser.length) {
                            for (i = 0; i < len; i++) {
                                var currentRes = items[i];
                                if ((currentRes.USERNAME.substr(0, currentUser.length) == currentUser || currentRes.NAME_SURNAME.substr(0, currentUser.length) == currentUser)) {
                                    priorities.highest.push(currentRes);
                                }
                                else if ((currentRes.USERNAME.toLowerCase().substr(0, currentUser.length) == currentUser.toLowerCase() || currentRes.NAME_SURNAME.toLowerCase().substr(0, currentUser.length) == currentUser.toLowerCase())) {
                                    priorities.high.push(currentRes);
                                }
                                else if (currentRes.USERNAME.indexOf(currentUser) != -1 || currentRes.NAME_SURNAME.indexOf(currentUser) != -1) {
                                    priorities.med.push(currentRes);
                                }
                                else {
                                    priorities.low.push(currentRes);
                                }
                            }
                            for (i in priorities) {
                                var j;
                                for (j in priorities[i]) {
                                    finals.push(priorities[i][j]);
                                }
                            }
                            return finals;
                        }
                    }
                    return items;
                }

Buy you must change "USERNAME" to your "username" and NAME_SURNAME to "name" in your case. You can also delete one of if condition's to sort only by name or only by surname.

If i find time i will improve that with "queryBy" in settings and commit to repo.

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

No branches or pull requests

2 participants