agarzola / jQueryAutocompletePlugin

Jörn Zaefferer’s (now deprecated) jQuery plugin, with tweaks.
282 stars 151 forks source link

Prevent jumping to first item when clicking keydown on last item #9

Closed borkor closed 13 years ago

borkor commented 13 years ago

Maybe there is a an option to prevent this anoying behaviour, but I just cant find it.

agarzola commented 13 years ago

Hi, borkor. I’m labeling this as a feature request. It shouldn’t be too difficult to implement, but I don’t have a whole lot of time this week. Perhaps in the coming weeks. In the meantime, if you do come up with a solution, please don’t hesitate to share it here (either post the change here or fork, change and send a pull request when you’re done).

Thank you for the suggestion!

borkor commented 13 years ago

Here is it:

function movePosition(step) {
if (options.scrollJumpPosition || 
          (!options.scrollJumpPosition && !((step < 0 && active == 0) || 
             (step > 0 && active == listItems.size() - 1)) ))   {
        active += step;
        if (active < 0) {
            active = listItems.size() - 1;
        } else if (active >= listItems.size()) {
            active = 0;
        }
    } 
}

I've also added the new option scrollJumpPosition, default is true.

agarzola commented 13 years ago

Thank you for your contribution, borkor!

I’ll implement this in the next version.

agarzola commented 13 years ago

I finally got around to merging your branch, borkor. Thanks again!