diff --git a/build/ng-tags-input.js b/build/ng-tags-input.js index 9b50aa65..6f03589d 100644 --- a/build/ng-tags-input.js +++ b/build/ng-tags-input.js @@ -52,7 +52,7 @@ angular.module('tags-input').directive('tagsInput', ["configuration", function(c }, trigger: function(name, args) { angular.forEach(events[name], function(handler) { - handler(args); + handler.call(null, args); }); } }; @@ -126,6 +126,7 @@ angular.module('tags-input').directive('tagsInput', ["configuration", function(c } $scope.newTag = ''; + events.trigger('input-changed', ''); changed = true; } return changed; @@ -168,23 +169,27 @@ angular.module('tags-input').directive('tagsInput', ["configuration", function(c shouldRemoveLastTag = false; }); - $scope.newTagChange = angular.noop; - this.registerAutocomplete = function() { var input = $element.find('input'); - input.changeValue = function(value) { - $scope.newTag = value; - }; + input.on('keydown', function(e) { + events.trigger('input-keydown', e); + }); - input.change = function(handler) { - $scope.newTagChange = function() { - handler($scope.newTag); - }; + $scope.newTagChange = function() { + events.trigger('input-changed', $scope.newTag); }; return { - input: input, - events: events + changeInputValue: function(value) { + $scope.newTag = value; + }, + focusInput: function() { + input[0].focus(); + }, + on: function(name, handler) { + events.on(name, handler); + return this; + } }; }; }], @@ -324,7 +329,7 @@ angular.module('tags-input').directive('autoComplete', ["$document","$timeout"," '', link: function(scope, element, attrs, tagsInputCtrl) { var hotkeys = [KEYS.enter, KEYS.tab, KEYS.escape, KEYS.up, KEYS.down], - suggestionList, tagsInput, input, highlight; + suggestionList, tagsInput, highlight; configuration.load(scope, attrs, { debounceDelay: { type: Number, defaultValue: 100 }, @@ -335,7 +340,6 @@ angular.module('tags-input').directive('autoComplete', ["$document","$timeout"," suggestionList = new SuggestionList(scope.source, scope.options); tagsInput = tagsInputCtrl.registerAutocomplete(); - input = tagsInput.input; if (scope.options.highlightMatchedText) { highlight = function(item, text) { @@ -355,9 +359,9 @@ angular.module('tags-input').directive('autoComplete', ["$document","$timeout"," var added = false; if (suggestionList.selected) { - input.changeValue(suggestionList.selected); + tagsInput.changeInputValue(suggestionList.selected); suggestionList.reset(); - input[0].focus(); + tagsInput.focusInput(); added = true; } @@ -368,60 +372,60 @@ angular.module('tags-input').directive('autoComplete', ["$document","$timeout"," return $sce.trustAsHtml(highlight(item, suggestionList.query)); }; - input.change(function(value) { - if (value) { - suggestionList.load(value); - } else { - suggestionList.reset(); - } - }); - - input.on('keydown', function(e) { - var key, handled; + tagsInput + .on('input-changed', function(value) { + if (value) { + suggestionList.load(value); + } else { + suggestionList.reset(); + } + }) + .on('input-keydown', function(e) { + var key, handled; - if (hotkeys.indexOf(e.keyCode) === -1) { - return; - } + if (hotkeys.indexOf(e.keyCode) === -1) { + return; + } - // This hack is needed because jqLite doesn't implement stopImmediatePropagation properly. - // I've sent a PR to Angular addressing this issue and hopefully it'll be fixed soon. - // https://github.com/angular/angular.js/pull/4833 - var immediatePropagationStopped = false; - e.stopImmediatePropagation = function() { - immediatePropagationStopped = true; - e.stopPropagation(); - }; - e.isImmediatePropagationStopped = function() { - return immediatePropagationStopped; - }; + // This hack is needed because jqLite doesn't implement stopImmediatePropagation properly. + // I've sent a PR to Angular addressing this issue and hopefully it'll be fixed soon. + // https://github.com/angular/angular.js/pull/4833 + var immediatePropagationStopped = false; + e.stopImmediatePropagation = function() { + immediatePropagationStopped = true; + e.stopPropagation(); + }; + e.isImmediatePropagationStopped = function() { + return immediatePropagationStopped; + }; - if (suggestionList.visible) { - key = e.keyCode; - handled = false; + if (suggestionList.visible) { + key = e.keyCode; + handled = false; - if (key === KEYS.down) { - suggestionList.selectNext(); - handled = true; - } - else if (key === KEYS.up) { - suggestionList.selectPrior(); - handled = true; - } - else if (key === KEYS.escape) { - suggestionList.reset(); - handled = true; - } - else if (key === KEYS.enter || key === KEYS.tab) { - handled = scope.addSuggestion(); - } + if (key === KEYS.down) { + suggestionList.selectNext(); + handled = true; + } + else if (key === KEYS.up) { + suggestionList.selectPrior(); + handled = true; + } + else if (key === KEYS.escape) { + suggestionList.reset(); + handled = true; + } + else if (key === KEYS.enter || key === KEYS.tab) { + handled = scope.addSuggestion(); + } - if (handled) { - e.preventDefault(); - e.stopImmediatePropagation(); - scope.$apply(); + if (handled) { + e.preventDefault(); + e.stopImmediatePropagation(); + scope.$apply(); + } } - } - }); + }); $document.on('click', function() { if (suggestionList.visible) { @@ -429,10 +433,6 @@ angular.module('tags-input').directive('autoComplete', ["$document","$timeout"," scope.$apply(); } }); - - tagsInput.events.on('tag-added', function() { - suggestionList.reset(); - }); } }; }]); diff --git a/build/ng-tags-input.min.zip b/build/ng-tags-input.min.zip index 6ebc1915..dca7c259 100644 Binary files a/build/ng-tags-input.min.zip and b/build/ng-tags-input.min.zip differ diff --git a/build/ng-tags-input.zip b/build/ng-tags-input.zip index e61c12e2..0443a98b 100644 Binary files a/build/ng-tags-input.zip and b/build/ng-tags-input.zip differ