12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- function split_query(query) {
- query = query.split(' ');
- query = query.map(function (tag) {
- return tag.trim();
- });
- query = query.filter(Boolean);
-
- return query;
- }
- function complete(field, suggestions, tag) {
- var query = $(field).val();
- query = split_query(query);
- if (query.length == 0)
- return;
- query[query.length - 1] = tag + ' ';
- $(field).val(query.join(' '));
- $(suggestions).hide();
- }
- function suggest(suggestions, suggestion_content, field, query) {
- query = split_query(query);
- if (query.length == 0)
- return;
- query = query[query.length - 1];
- if (query.length < 2)
- return;
- if (query[query.length - 1] == ' ' || query[query.length - 1] == '-') {
- $(suggestions).hide();
- return;
- }
-
- api_unchecked('suggest', {tag: query}, function (data) {
- if (data.error !== undefined) {
- popup('danger', data.error);
- $(suggestions).hide();
- return;
- }
- $(suggestion_content).html('');
- for (var i = 0; i < data.tags_list.length; i++) {
- var html = '';
- html += '<a class="dropdown-item" onclick="complete(\'' + field + '\', \'' + suggestions + '\', \'' + data.tags_list[i] + '\');">';
- html += data.tags_list[i];
- html += '</a>';
- $(suggestion_content).append(html);
- }
- if (data.tags_list.length)
- $(suggestions).show();
- });
- }
|