Created
May 10, 2012 15:25
-
-
Save Irio/2653897 to your computer and use it in GitHub Desktop.
tag-it.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Comma/Space/Enter are all valid delimiters for new tags, | |
// except when there is an open quote or if setting allowSpaces = true. | |
// Tab will also create a tag, unless the tag input is empty, in which case it isn't caught. | |
if ( | |
event.which == $.ui.keyCode.COMMA || | |
event.which == $.ui.keyCode.ENTER || | |
( | |
event.which == $.ui.keyCode.TAB && | |
that._tagInput.val() !== '' | |
) || | |
( | |
event.which == $.ui.keyCode.SPACE && | |
that.options.allowSpaces !== true && | |
( | |
$.trim(that._tagInput.val()).replace( /^s*/, '' ).charAt(0) != '"' || | |
( | |
$.trim(that._tagInput.val()).charAt(0) == '"' && | |
$.trim(that._tagInput.val()).charAt($.trim(that._tagInput.val()).length - 1) == '"' && | |
$.trim(that._tagInput.val()).length - 1 !== 0 | |
) | |
) | |
) | |
) { | |
event.preventDefault(); | |
that.createTag(that._cleanedInput()); | |
// The autocomplete doesn't close automatically when TAB is pressed. | |
// So let's ensure that it closes. | |
that._tagInput.autocomplete('close'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment