Skip to content

Commit

Permalink
Merge pull request #6 from michael87/master
Browse files Browse the repository at this point in the history
Added blur support
  • Loading branch information
alicial committed Mar 11, 2012
2 parents 6c133ca + 09936e0 commit 551448f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.markdown
Expand Up @@ -11,6 +11,7 @@ Demo
Features
--------
* _New!_ Supports full integration with jQuery UI Autocomplete plug-in. Try typing some programming languages into the demo.
* _New!_ Supports blur action. After blur create a tag
* Configurable keys to create a tag
* Backspace on empty field deletes last tag
* Public methods to add and remove tags programatically
Expand Down Expand Up @@ -75,4 +76,8 @@ Available options and their defaults are:

* Placeholder text

$('textarea').( {addTagPrompt: 'add tags'} );
$('textarea').( {addTagPrompt: 'add tags'} );
* Blur action for creating tags

$('textarea').( {addTagOnBlur: true} );
20 changes: 18 additions & 2 deletions demo/jquery.tagify.js
Expand Up @@ -4,10 +4,11 @@

$.widget("ui.tagify", {
options: {
delimiters: [13, 188], // what user can type to complete a tag in char codes: [enter], [comma]
delimiters: [13, 188, 44], // what user can type to complete a tag in char codes: [enter], [comma]
outputDelimiter: ',', // delimiter for tags in original input field
cssClass: 'tagify-container', // CSS class to style the tagify div and tags, see stylesheet
addTagPrompt: 'add tags' // placeholder text
addTagPrompt: 'add tags', // placeholder text
addTagOnBlur: false // Add a tag on blur when not empty
},

_create: function() {
Expand Down Expand Up @@ -52,6 +53,21 @@
return;
}
});

// Add tags blur event when required
if (opts.addTagOnBlur) {
// When needed, add tags on blur
this.tagInput.blur( function(e) {
var $this = $(this);

// if lose focus on input field, check if length is empty
if ('' !== $this.val()) {
self.add( $this.val() );
e.preventDefault();
return false;
}
});
}

this.tagDiv = $("<div></div>")
.addClass( opts.cssClass )
Expand Down
20 changes: 18 additions & 2 deletions jquery.tagify.js
Expand Up @@ -4,10 +4,11 @@

$.widget("ui.tagify", {
options: {
delimiters: [13, 188], // what user can type to complete a tag in char codes: [enter], [comma]
delimiters: [13, 188, 44], // what user can type to complete a tag in char codes: [enter], [comma]
outputDelimiter: ',', // delimiter for tags in original input field
cssClass: 'tagify-container', // CSS class to style the tagify div and tags, see stylesheet
addTagPrompt: 'add tags' // placeholder text
addTagPrompt: 'add tags', // placeholder text
addTagOnBlur: false // Add a tag on blur when not empty
},

_create: function() {
Expand Down Expand Up @@ -52,6 +53,21 @@
return;
}
});

// Add tags blur event when required
if (opts.addTagOnBlur) {
// When needed, add tags on blur
this.tagInput.blur( function(e) {
var $this = $(this);

// if lose focus on input field, check if length is empty
if ('' !== $this.val()) {
self.add( $this.val() );
e.preventDefault();
return false;
}
})
}

this.tagDiv = $("<div></div>")
.addClass( opts.cssClass )
Expand Down

0 comments on commit 551448f

Please sign in to comment.