From b693a5f4b31ffe3a3009ad43d4e9d4628f02d5f0 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 30 Nov 2014 11:54:38 +0100 Subject: [PATCH] Added tag siblings suggestion synchronization --- public_html/js/Controls/TagInput.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/public_html/js/Controls/TagInput.js b/public_html/js/Controls/TagInput.js index 1e23568f..57aec200 100644 --- a/public_html/js/Controls/TagInput.js +++ b/public_html/js/Controls/TagInput.js @@ -174,6 +174,16 @@ App.Controls.TagInput = function($underlyingInput) { $tagList.append($elem); } + function beforeTagRemoved(tagName) { + if (typeof(options.beforeTagRemoved) === 'function') { + options.beforeTagRemoved(tagName); + } + } + + function afterTagRemoved(tagName) { + refreshShownSiblings(); + } + function beforeTagAdded(tagName) { if (typeof(options.beforeTagAdded) === 'function') { options.beforeTagAdded(tagName); @@ -188,6 +198,7 @@ App.Controls.TagInput = function($underlyingInput) { flashTagYellow(impliedTagName); }); showOrHideSuggestions(tagName); + refreshShownSiblings(); } else { flashTagGreen(tagName); } @@ -205,10 +216,9 @@ App.Controls.TagInput = function($underlyingInput) { var oldTagNames = getTags(); var newTagNames = _.without(oldTagNames, tagName); if (newTagNames.length !== oldTagNames.length) { - if (typeof(options.beforeTagRemoved) === 'function') { - options.beforeTagRemoved(tagName); - } + beforeTagRemoved(tagName); setTags(newTagNames); + afterTagRemoved(tagName); } } @@ -295,11 +305,16 @@ App.Controls.TagInput = function($underlyingInput) { })).then(function(siblings) { siblings = _.pluck(siblings, 'name'); $siblings.data('lastTag', tagName); + $siblings.data('siblings', siblings); updateSuggestions($siblings, siblings); }).fail(function() { }); } + function refreshShownSiblings() { + updateSuggestions($siblings, $siblings.data('siblings')); + } + function updateSuggestions($target, siblings) { function filterSuggestions(sourceTagNames) { if (!sourceTagNames) {