Fixed and simplified tag autocompletion
This commit is contained in:
parent
4469767d8f
commit
b86aaf90a3
8 changed files with 50 additions and 57 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
<div class="form-row">
|
||||
<label for="mass-tag-query">Search query:</label>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="query" id="mass-tag-query" value="<?php echo isset($this->context->massTagQuery) ? $this->context->massTagQuery : '' ?>" data-autocomplete-url="<?php echo \Chibi\UrlHelper::route('tag', 'list') ?>"/></div>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="query" id="mass-tag-query" value="<?php echo isset($this->context->massTagQuery) ? $this->context->massTagQuery : '' ?>"/></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="mass-tag-tag">Tag:</label>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="tag" id="mass-tag-tag" value="<?php echo isset($this->context->massTagTag) ? $this->context->massTagTag : '' ?>" data-autocomplete-url="<?php echo \Chibi\UrlHelper::route('tag', 'list') ?>"/></div>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="tag" id="mass-tag-tag" value="<?php echo isset($this->context->massTagTag) ? $this->context->massTagTag : '' ?>"/></div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="submit" value="1"/>
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
<div class="form-row">
|
||||
<label for="merge-source-tag">Source tag:</label>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="source-tag" id="merge-source-tag" data-autocomplete-url="<?php echo \Chibi\UrlHelper::route('tag', 'list') ?>"/></div>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="source-tag" id="merge-source-tag"/></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="merge-target-tag">Target tag:</label>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="target-tag" id="merge-target-tag" data-autocomplete-url="<?php echo \Chibi\UrlHelper::route('tag', 'list') ?>"/></div>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="target-tag" id="merge-target-tag"/></div>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="submit" value="1"/>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<div class="form-row">
|
||||
<label for="rename-source-tag">Source tag:</label>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="source-tag" id="rename-source-tag" data-autocomplete-url="<?php echo \Chibi\UrlHelper::route('tag', 'list') ?>"/></div>
|
||||
<div class="input-wrapper"><input class="autocomplete" type="text" name="source-tag" id="rename-source-tag"/></div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
|
|
|
@ -127,7 +127,7 @@
|
|||
|
||||
<li class="search">
|
||||
<form name="search" action="<?php echo \Chibi\UrlHelper::route('post', 'list') ?>" method="get">
|
||||
<input class="autocomplete" type="search" name="query" placeholder="Search…" value="<?php echo isset($this->context->transport->searchQuery) ? htmlspecialchars($this->context->transport->searchQuery) : '' ?>" data-autocomplete-url="<?php echo \Chibi\UrlHelper::route('tag', 'list') ?>"/>
|
||||
<input class="autocomplete" type="search" name="query" placeholder="Search…" value="<?php echo isset($this->context->transport->searchQuery) ? htmlspecialchars($this->context->transport->searchQuery) : '' ?>"/>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue