Skip to content
This repository has been archived by the owner on Jun 24, 2019. It is now read-only.

Commit

Permalink
feat: now the autocomplete box is usable with tab key
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kruse committed Jul 22, 2015
1 parent 813003e commit 03968e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 27 additions & 4 deletions app/assets/javascripts/mentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,45 @@

$("body").append(elem);

var hideElem = function() {
area.removeAttr('tabindex');
elem.fadeOut('fast', function() { elem.html(''); });
};

elem.on('keydown', function(ev) {
/* we completely ignore the tabkey */
if(ev.keyCode == 9) {
return;
}

ev.preventDefault();

if(ev.keyCode == 32 || ev.keyCode == 13) {
chooseName(ev);
}

hideElem();
area.focus();
});

var showAutocomplete = function(nick) {
$.get(cforum.baseUrl + 'users.json?nick=' + encodeURIComponent(nick)).
done(function(data) {
if(data.length === 0 || (data.length == 1 && data[0].username == nick)) {
elem.fadeOut('fast');
hideElem();
return;
}

var pos = area.offset();
var sel = area.getSelection();

area.attr('tabindex', 1);

var caretPos = window.getCaretCoordinates(area.get(0), sel.end);

var html = "";
for(var i = 0; i < data.length && i < 20; ++i) {
html += "<li>" + data[i].username + "</li>";
html += "<li tabindex=\"" + (i + 2) + "\">" + data[i].username + "</li>";
}

elem.html(html);
Expand Down Expand Up @@ -76,7 +99,7 @@

completed[start] = name;

elem.fadeOut('fast');
hideElem();
});
};

Expand All @@ -100,7 +123,7 @@
tm = null;
}

elem.fadeOut('fast');
hideElem();
});
});
};
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/mentions.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
cursor:pointer;
}

li:hover {
li:hover, li:focus {
background-color:#ccc;
}
}
Expand Down

0 comments on commit 03968e4

Please sign in to comment.