Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing of data attributes with tags #75

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions js/tag-it.js
Expand Up @@ -52,7 +52,7 @@
//
// The easiest way to use singleField is to just instantiate tag-it
// on an INPUT element, in which case singleField is automatically
// set to true, and singleFieldNode is set to that element. This
// set to true, and singleFieldNode is set to that element. This
// way, you don't need to fiddle with these options.
singleField: false,

Expand All @@ -64,7 +64,7 @@
// delimited by singleFieldDelimiter.
//
// If this is not set, we create an input node for it,
// with the name given in settings.fieldName,
// with the name given in settings.fieldName,
// ignoring settings.itemName.
singleFieldNode: null,

Expand Down Expand Up @@ -140,7 +140,7 @@
// Add existing tags from the list, if any.
this.tagList.children('li').each(function() {
if (!$(this).hasClass('tagit-new')) {
that.createTag($(this).html(), $(this).attr('class'));
that.createTag($(this).html(), $(this).attr('class'), $(this).data());
$(this).remove();
}
});
Expand Down Expand Up @@ -211,7 +211,7 @@
// Create a tag when the element loses focus (unless it's empty).
that.createTag(that._cleanedInput());
});


// Autocomplete.
if (this.options.availableTags || this.options.tagSource) {
Expand All @@ -227,7 +227,7 @@
if (that._tagInput.val() === '') {
that.removeTag(that._lastTag(), false);
}
that.createTag(ui.item.value);
that.createTag(ui.item.value, null, ui.item);
// Preventing the tag input to be updated with the chosen value.
return false;
}
Expand Down Expand Up @@ -304,7 +304,7 @@
return $.trim(str.toLowerCase());
},

createTag: function(value, additionalClass) {
createTag: function(value, additionalClass, data) {
var that = this;
// Automatically trims the value of leading and trailing whitespace.
value = $.trim(value);
Expand All @@ -321,6 +321,10 @@
.addClass(additionalClass)
.append(label);

if (data) {
tag.data("tagit", data)
}

// Button for removing the tag.
var removeTagIcon = $('<span></span>')
.addClass('ui-icon ui-icon-close');
Expand Down Expand Up @@ -351,7 +355,7 @@
// insert tag
this._tagInput.parent().before(tag);
},

removeTag: function(tag, animate) {
animate = animate || this.options.animate;

Expand Down