Permalink
Browse files

Hide floater on blur. Focus on select tag after selected.

  • Loading branch information...
1 parent 748fd94 commit 575f88fe03e5163af1ec516c32e083ea5e070ae3 @ordinaryzelig committed Apr 11, 2012
Showing with 19 additions and 4 deletions.
  1. +2 −0 CHANGELOG.md
  2. +8 −1 src/jquery-selectTagAutocompleteFloater.coffee
  3. +9 −3 src/jquery-selectTagAutocompleteFloater.js
View
@@ -5,6 +5,8 @@
### Minor features
* Prevent form submission when 'enter' key pressed in text field.
+* Hide floater on blur.
+* Focus on select tag after selection made.
## v0.1.0 2012-04-10
@@ -36,10 +36,15 @@ autocompleteFloaterFunctions = {
createAutocompleteTextField: (selectTag) ->
textField = $('<input type="text" placeholder="Search" />')
+ # Ignore return key presses to prevent form submission.
textField.keydown (event) ->
returnKeyCode = 13
if event.keyCode == returnKeyCode
event.preventDefault()
+ # Hide floater on blur.
+ textField.blur ->
+ floater = $(@).parents('.autocompleteFloater:first')
+ floater.hide()
# Create a link that toggles the floater.
# When floater visible, focus on text field.
@@ -54,7 +59,7 @@ autocompleteFloaterFunctions = {
link.click (event) ->
event.preventDefault()
floater = $(@).nextAll('.autocompleteFloater:first')
- floater.toggle()
+ floater.show()
if floater.is(':visible')
textField = floater.children('input:text')
textField.val('')
@@ -87,5 +92,7 @@ autocompleteFloaterFunctions = {
return false
# Hide the floater.
floater.hide()
+ # Focus on select tag.
+ selectTag.focus()
}
@@ -35,11 +35,16 @@
createAutocompleteTextField: function(selectTag) {
var textField;
textField = $('<input type="text" placeholder="Search" />');
- return textField.keydown(function(event) {
+ textField.keydown(function(event) {
var returnKeyCode;
returnKeyCode = 13;
if (event.keyCode === returnKeyCode) return event.preventDefault();
});
+ return textField.blur(function() {
+ var floater;
+ floater = $(this).parents('.autocompleteFloater:first');
+ return floater.hide();
+ });
},
createLinktoShowFloater: function() {
var link, linkContent;
@@ -49,7 +54,7 @@
var floater, textField;
event.preventDefault();
floater = $(this).nextAll('.autocompleteFloater:first');
- floater.toggle();
+ floater.show();
if (floater.is(':visible')) {
textField = floater.children('input:text');
textField.val('');
@@ -79,7 +84,8 @@
return false;
}
});
- return floater.hide();
+ floater.hide();
+ return selectTag.focus();
}
});
}

0 comments on commit 575f88f

Please sign in to comment.