Skip to content

Commit

Permalink
port onAdd callback to function similarily to onDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Phillips committed Mar 4, 2012
1 parent c448d8c commit 756c14a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions js/jquery.taghandler.js
Expand Up @@ -332,7 +332,7 @@
// delegates a click event function to all future <li> elements with
// the tagItem class that will remove the tag upon click
tagContainerObject.delegate("li.tagItem", "click", function() {
var rc;
var rc = 1;

if ( typeof(opts.onDelete) == "function" ) {
rc = opts.onDelete.call(this, $.trim($(this).text()));
Expand Down Expand Up @@ -367,15 +367,22 @@
alert('Maximum tags allowed: ' + opts.maxTags);
} else {
var newTag = $.trim($(this).val());
tags = addTag(this, newTag, tags, opts.sortTags);
if (opts.updateURL !=='' && opts.autoUpdate) {
saveTags(tags, opts, tagContainer.id);
}
if (opts.autocomplete && typeof($.fn.autocomplete) == 'function' && opts.initLoad) {
$(inputField).autocomplete("option", "source", tags.availableTags);
}

// allow addition onAdd return code to control whether addition
// is allowed to go through.
var rc = 1;
if ( typeof(opts.onAdd) == "function" ) {
opts.onAdd.call(this, newTag);
rc = opts.onAdd.call(this, newTag);
}

if (rc) {
tags = addtag(this, newtag, tags, opts.sorttags);
if (opts.updateurl !=='' && opts.autoupdate) {
savetags(tags, opts, tagcontainer.id);
}
if (opts.autocomplete && typeof($.fn.autocomplete) == 'function' && opts.initload) {
$(inputField).autocomplete("option", "source", tags.availableTags);
}
}
}
$(this).val("");
Expand Down

0 comments on commit 756c14a

Please sign in to comment.