From b5d6e4837d95bb9e7d44ab20f58eeafa99bfd7b8 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 24 Jun 2015 23:51:11 +0200 Subject: [PATCH] Removed a way to repeat a tag in uploaded post --- .../js/Presenters/PostUploadPresenter.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/public_html/js/Presenters/PostUploadPresenter.js b/public_html/js/Presenters/PostUploadPresenter.js index dff8ee17..580fa870 100644 --- a/public_html/js/Presenters/PostUploadPresenter.js +++ b/public_html/js/Presenters/PostUploadPresenter.js @@ -440,6 +440,15 @@ App.Presenters.PostUploadPresenter = function( }; } + function getTagIndex(post, tag) { + var tags = jQuery.map(post.tags, String.toLowerCase); + return tags.indexOf(tag.toLowerCase()); + } + + function hasTag(post, tag) { + return getTagIndex(post, tag) !== -1; + } + function getCombinedPost(posts) { var combinedPost = _.extend({}, getDefaultPost()); if (posts.length === 0) { @@ -449,7 +458,7 @@ App.Presenters.PostUploadPresenter = function( var tagFilter = function(post) { return function(tag) { - return post.tags.indexOf(tag) !== -1; + return hasTag(post, tag); }; }; @@ -496,8 +505,7 @@ App.Presenters.PostUploadPresenter = function( function addTagToPosts(posts, tag) { jQuery.each(posts, function(i, post) { - var index = post.tags.indexOf(tag); - if (index === -1) { + if (!hasTag(post, tag)) { post.tags.push(tag); } postChanged(post); @@ -506,9 +514,8 @@ App.Presenters.PostUploadPresenter = function( function removeTagFromPosts(posts, tag) { jQuery.each(posts, function(i, post) { - var index = post.tags.indexOf(tag); - if (index !== -1) { - post.tags.splice(index, 1); + if (hasTag(post, tag)) { + post.tags.splice(getTagIndex(post, tag), 1); } postChanged(post); });