diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index 1e7095a5..62bb2507 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -193,6 +193,25 @@ function extractLast(term) return split(term).pop(); } +function retrieveTags(searchTerm, cb) +{ + var options = { filter: searchTerm + ' order:popularity,desc' }; + $.getJSON('/tags?json', options, function(data) + { + var tags = $.map(data.tags.slice(0, 15), function(tag) + { + var ret = + { + label: tag.name + ' (' + tag.count + ')', + value: tag.name, + }; + return ret; + }); + + cb(tags); + }); +} + $(function() { $('.autocomplete').each(function() @@ -204,10 +223,7 @@ $(function() { var term = extractLast(request.term); if (term != '') - $.get(searchInput.attr('data-autocomplete-url') + '?json', {filter: term + ' order:popularity,desc'}, function(data) - { - response($.map(data.tags, function(tag) { return { label: tag.name + ' (' + tag.count + ')', value: tag.name }; })); - }); + retrieveTags(term, response); }, focus: function(e) { @@ -245,34 +261,34 @@ $(function() }); }); -function getTagItOptions() +function attachTagIt(element) { - return { + var tagItOptions = + { caseSensitive: false, autocomplete: { source: function(request, response) { - var term = request.term.toLowerCase(); - var tags = $.map(this.options.availableTags, function(a) + var tagit = this; + retrieveTags(request.term.toLowerCase(), function(tags) { - return a.name; + if (!tagit.options.allowDuplicates) + { + tags = $.grep(tags, function(tag) + { + return tagit.assignedTags().indexOf(tag.value) == -1; + }); + } + response(tags); }); - var results = $.grep(tags, function(a) - { - if (term.length < 3) - return a.toLowerCase().indexOf(term) == 0; - else - return a.toLowerCase().indexOf(term) != -1; - }); - results = results.slice(0, 15); - if (!this.options.allowDuplicates) - results = this._subtractArray(results, this.assignedTags()); - response(results); }, } }; + + tagItOptions.placeholderText = element.attr('placeholder'); + element.tagit(tagItOptions); } diff --git a/public_html/media/js/post-upload.js b/public_html/media/js/post-upload.js index 7924dd4d..76422245 100644 --- a/public_html/media/js/post-upload.js +++ b/public_html/media/js/post-upload.js @@ -10,12 +10,6 @@ $(function() $('.tab-content.' + className).show(); }); - var tags = []; - $.getJSON('/tags?json', {filter: 'order:popularity,desc'}, function(data) - { - tags = data['tags']; - }); - $('#file-handler').on('dragenter', function(e) { $(this).addClass('active'); @@ -237,10 +231,7 @@ $(function() $('.posts').append(postDom); postDom.show(); - var tagItOptions = getTagItOptions(); - tagItOptions.availableTags = tags; - tagItOptions.placeholderText = $('.tags input').attr('placeholder'); - $('.tags input', postDom).tagit(tagItOptions); + attachTagIt($('.tags input', postDom)); callback(postDom, input); } diff --git a/public_html/media/js/post-view.js b/public_html/media/js/post-view.js index 4ce03465..32a1df78 100644 --- a/public_html/media/js/post-view.js +++ b/public_html/media/js/post-view.js @@ -14,22 +14,14 @@ $(function() var formDom = $('form.edit-post'); if (formDom.find('.tagit').length == 0) { - $.getJSON('/tags?json', {filter: 'order:popularity,desc'}, function(data) + attachTagIt($('.tags input')); + aDom.removeClass('inactive'); + + formDom.find('input[type=text]:visible:eq(0)').focus(); + formDom.find('textarea, input').bind('change keyup', function() { - aDom.removeClass('inactive'); - var tags = data['tags']; - - var tagItOptions = getTagItOptions(); - tagItOptions.availableTags = tags; - tagItOptions.placeholderText = $('.tags input').attr('placeholder'); - $('.tags input').tagit(tagItOptions); - - formDom.find('input[type=text]:visible:eq(0)').focus(); - formDom.find('textarea, input').bind('change keyup', function() - { - if (formDom.serialize() != formDom.data('original-data')) - enableExitConfirmation(); - }); + if (formDom.serialize() != formDom.data('original-data')) + enableExitConfirmation(); }); } else diff --git a/src/Models/SearchServices/TagSearchService.php b/src/Models/SearchServices/TagSearchService.php index 0c26b3f4..09520df6 100644 --- a/src/Models/SearchServices/TagSearchService.php +++ b/src/Models/SearchServices/TagSearchService.php @@ -4,7 +4,6 @@ class TagSearchService extends AbstractSearchService public static function decorate(SqlQuery $sqlQuery, $searchQuery) { $allowedSafety = PrivilegesHelper::getAllowedSafety(); - $limitQuery = false; $sqlQuery ->raw(', COUNT(post_tag.post_id)') ->as('post_count') @@ -38,7 +37,6 @@ class TagSearchService extends AbstractSearchService } else { - $limitQuery = true; if (strlen($token) >= 3) $token = '%' . $token; $token .= '%'; @@ -53,10 +51,6 @@ class TagSearchService extends AbstractSearchService $sqlQuery->groupBy('tag.id'); if ($orderToken) self::order($sqlQuery,$orderToken); - - - if ($limitQuery) - $sqlQuery->limit(15); } private static function order(SqlQuery $sqlQuery, $value) diff --git a/src/Views/tag-mass-tag.phtml b/src/Views/tag-mass-tag.phtml index fdeccbe3..621525cd 100644 --- a/src/Views/tag-mass-tag.phtml +++ b/src/Views/tag-mass-tag.phtml @@ -4,12 +4,12 @@