Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Modified events to properly reflect the actual event, Added extra events. #63

Closed
wants to merge 2 commits into from

2 participants

@chemass

OnAdding: replaces OnAdded - fires before tag is added
OnAdded: fires after tag has been added
OnRemoving: replaces OnRemoved - fires before tag is removed
OnRemoved: fires after tag has been removed
OnBlur: fires on input field blur event

@chemass chemass Added/Modified events:
OnAdding: replaces OnAdded - fires before tag is added
OnAdded: fires after tag has been added
OnRemoving: replaces OnRemoved - fires before tag is removed
OnRemoved: fires after tag has been removed
OnBlur: fires on input field blur event
0d86b5f
@aehlke
Owner
@chemass chemass Changed callback names.
onTagAdding > beforeAdding
onTagAdded > afterAdding
onTagRemoving > beforeRemoving
onTagRemoved > afterRemoving
92535ac
@aehlke
Owner

Thanks but I've tackled this a bit differently with 28e6161 - I've also exposed the tag input publicly for allowing you to bind to its events.

@aehlke aehlke closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 13, 2012
  1. @chemass

    Added/Modified events:

    chemass authored
    OnAdding: replaces OnAdded - fires before tag is added
    OnAdded: fires after tag has been added
    OnRemoving: replaces OnRemoved - fires before tag is removed
    OnRemoved: fires after tag has been removed
    OnBlur: fires on input field blur event
Commits on Feb 14, 2012
  1. @chemass

    Changed callback names.

    chemass authored
    onTagAdding > beforeAdding
    onTagAdded > afterAdding
    onTagRemoving > beforeRemoving
    onTagRemoved > afterRemoving
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 10 deletions.
  1. +13 −4 examples.html
  2. +13 −6 js/tag-it.js
View
17 examples.html
@@ -69,18 +69,27 @@
var eventTags = $('#eventTags');
eventTags.tagit({
availableTags: sampleTags,
- onTagRemoved: function(evt, tag) {
+ beforeRemoving: function(evt, tag) {
console.log(evt);
alert('This tag is being removed: ' + eventTags.tagit('tagLabel', tag));
},
+ afterRemoving: function(evt, tag) {
+ console.log(evt);
+ alert('This tag has been removed: ' + eventTags.tagit('tagLabel', tag));
+ },
onTagClicked: function(evt, tag) {
console.log(tag);
alert('This tag was clicked: ' + eventTags.tagit('tagLabel', tag));
- }
- }).tagit('option', 'onTagAdded', function(evt, tag) {
+ },
+ onBlur: function(){ alert('Blur event'); }
+ }).tagit('option', 'beforeAdding', function(evt, tag) {
// Add this callbackafter we initialize the widget,
- // so that onTagAdded doesn't get called on page load.
+ // so that beforeAdding doesn't get called on page load.
alert('This tag is being added: ' + eventTags.tagit('tagLabel', tag));
+ }).tagit('option', 'afterAdding', function(evt, tag) {
+ // Add this callbackafter we initialize the widget,
+ // so that afterAdding doesn't get called on page load.
+ alert('This tag has been added: ' + eventTags.tagit('tagLabel', tag));
});
//-------------------------------
View
19 js/tag-it.js
@@ -74,9 +74,12 @@
// Event callbacks.
- onTagAdded : null,
- onTagRemoved: null,
- onTagClicked: null
+ beforeAdding: null,
+ afterAdding: null,
+ beforeRemoving: null,
+ afterRemoving: null,
+ onTagClicked: null,
+ onBlur: null
},
@@ -97,7 +100,7 @@
this.tagList = this.element.find('ul, ol').andSelf().last();
}
- this._tagInput = $('<input type="text" />').addClass('ui-widget-content');
+ this._tagInput = $('<input type="text" />').addClass('ui-widget-content').blur(function () { that._trigger('onBlur', null) });
if (this.options.tabIndex) {
this._tagInput.attr('tabindex', this.options.tabIndex);
}
@@ -343,13 +346,15 @@
tag.append('<input type="hidden" style="display:none;" value="' + escapedValue + '" name="' + this.options.itemName + '[' + this.options.fieldName + '][]" />');
}
- this._trigger('onTagAdded', null, tag);
+ this._trigger('beforeAdding', null, tag);
// Cleaning the input.
this._tagInput.val('');
// insert tag
this._tagInput.parent().before(tag);
+
+ this._trigger('afterAdding', null, tag);
},
removeTag: function(tag, animate) {
@@ -357,7 +362,7 @@
tag = $(tag);
- this._trigger('onTagRemoved', null, tag);
+ this._trigger('beforeRemoving', null, tag);
if (this.options.singleField) {
var tags = this.assignedTags();
@@ -375,6 +380,8 @@
} else {
tag.remove();
}
+
+ this._trigger('afterRemoving', null, tag);
},
removeAll: function() {
Something went wrong with that request. Please try again.