Skip to content

Commit

Permalink
Merge pull request #23 from MSommer/master
Browse files Browse the repository at this point in the history
Fix #22
  • Loading branch information
sniperwolf committed Oct 24, 2014
2 parents 5452775 + f1c25a0 commit 38d87e9
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions tagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
this.elem = elem; // The tag box
this.$elem = $( elem ); // jQuerify tag box
this.options = options; // JS custom options
this.tags = []; // The tags
// this.$type_zone = void 0; // The tag box's input zone
};

Expand All @@ -40,9 +41,7 @@
*/
Tagging.prototype = {

// We store here all tags
tags: [],


// All special Keys
keys: {
// Special keys to add a tag
Expand Down Expand Up @@ -84,6 +83,7 @@
"tag-char": "#", // Single Tag char
"tag-class": "tag", // Single Tag class
"tags-input-name": "tag", // Name to use as name="" in single tags (by default tag[])
"tag-on-blur": true, // Add the current tag if user clicks away from type-zone
"type-zone-class": "type-zone", // Class of the type-zone
},

Expand Down Expand Up @@ -178,7 +178,7 @@
// Creating a new div for the new tag
$tag = $( document.createElement( "div" ) )
.addClass( self.config[ "tag-class" ] )
.html( "<span>" + self.config[ "tag-char" ] + "</span> " + text );
.html( text );

// Creating and Appending hidden input
$( document.createElement( "input" ) )
Expand Down Expand Up @@ -209,9 +209,10 @@
self.tags.push( $tag );

// Adding tag in the type zone
self.$type_zone.before( $tag );

return true;

self.$type_zone.before( $tag );

return true;
},

/**
Expand Down Expand Up @@ -516,7 +517,21 @@
// Exit with success
return true;
});


// Add tag on a click away from the type_zone
if ( self.config[ "tag-on-blur" ] ) {
self.$type_zone.focusout(function(e) {
// Get text from current input box
text = self.valInput();
// If text is empty, then continue focusout
if ( ! text || ! text.length ) {
return false;
}
// Otherwise add the tag first
return self.add();
});
}

// On click, we focus the type_zone
self.$elem.on( "click", function() {
self.focusInput();
Expand Down Expand Up @@ -785,3 +800,4 @@
// // console.log( t[0] );
// });
// })( window.jQuery, window, document );

0 comments on commit 38d87e9

Please sign in to comment.