podio / jquery-mentions-input

MIT License
985 stars 333 forks source link

How to disable elastic? #185

Closed ghost closed 5 years ago

ghost commented 5 years ago

From the examples:

$('textarea.mention').mentionsInput({
    onDataRequest:function (mode, query, callback) {
        var data = [
            { id:1, name:'Kenneth Auchenberg', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
            { id:2, name:'Jon Froda', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
            { id:3, name:'Anders Pollas', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
            { id:4, name:'Kasper Hulthin', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
            { id:5, name:'Andreas Haugstrup', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
            { id:6, name:'Pete Lacey', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
            { id:7, name:'kenneth@auchenberg.dk', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
            { id:8, name:'Pete Awesome Lacey', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
            { id:9, name:'Kenneth Hulthin', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' }
        ];

        data = _.filter(data, function(item) { return item.name.toLowerCase().indexOf(query.toLowerCase()) > -1 });
        callback.call(this, data);
    }
});

However, the problem seems that passing settings like {elastic: false} get overwritten a few lines later. Since method is not a method here, settings will be pointing to method:

jquery-mentionsInput.js:

$.fn.mentionsInput = function (method, settings) {

    var outerArguments = arguments; //Gets the arguments
    //If method is not a function
    if (typeof method === 'object' || !method) {
        settings = method;
    }
    // ..
}

So, is this a bug or am I using it wrong?

ghost commented 5 years ago

Okay, a second later I figured ...

$('textarea.my-mentions').mentionsInput({
    onDataRequest:function (mode, query, callback) {
       // ..
    },
    elastic: false
});