mirror of
https://github.com/moebooru/moebooru
synced 2025-08-22 01:47:48 +00:00
Javascript Autocomplete (cleanup)
This commit is contained in:
parent
6dfa49262a
commit
55fc74a0fa
@ -1,77 +1,58 @@
|
||||
var $, Autocomplete, autocompleterMap;
|
||||
|
||||
import autocompleter from 'autocompleter';
|
||||
|
||||
import TagCompletion from './tag_completion';
|
||||
|
||||
import TagCompletionBox from './tag_completion_box';
|
||||
|
||||
$ = jQuery;
|
||||
const $ = window.jQuery;
|
||||
|
||||
autocompleterMap = (match) => {
|
||||
function autocompleterMap (match) {
|
||||
return {
|
||||
label: match,
|
||||
value: match
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default Autocomplete = class Autocomplete {
|
||||
export default class Autocomplete {
|
||||
constructor (tagCompletionInstance) {
|
||||
this._genericCompletion = this._genericCompletion.bind(this);
|
||||
this._genericCompletionAll = this._genericCompletionAll.bind(this);
|
||||
this._tagCompletion = this._tagCompletion.bind(this);
|
||||
this.tagCompletionInstance = tagCompletionInstance;
|
||||
$(() => {
|
||||
this._genericCompletionAll();
|
||||
return this._tagCompletion();
|
||||
this.genericCompletionAll();
|
||||
this.tagCompletion();
|
||||
});
|
||||
}
|
||||
|
||||
_genericCompletion(input) {
|
||||
var url;
|
||||
url = input.dataset.autocomplete;
|
||||
return autocompleter({
|
||||
input: input,
|
||||
genericCompletion (input) {
|
||||
const url = input.dataset.autocomplete;
|
||||
|
||||
autocompleter({
|
||||
input,
|
||||
fetch: (text, update) => {
|
||||
return $.ajax(url, {
|
||||
data: {
|
||||
term: text
|
||||
},
|
||||
$.ajax(url, {
|
||||
data: { term: text },
|
||||
dataType: 'json'
|
||||
}).done((matches) => {
|
||||
return update(matches.map(autocompleterMap));
|
||||
update(matches.map(autocompleterMap));
|
||||
});
|
||||
},
|
||||
onSelect: (match) => {
|
||||
return input.value = match.value;
|
||||
input.value = match.value;
|
||||
},
|
||||
preventSubmit: 2 // OnSelect
|
||||
});
|
||||
}
|
||||
|
||||
_genericCompletionAll() {
|
||||
var i, input, len, ref, results;
|
||||
ref = document.querySelectorAll('[data-autocomplete]');
|
||||
results = [];
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
input = ref[i];
|
||||
results.push(this._genericCompletion(input));
|
||||
genericCompletionAll () {
|
||||
for (const input of document.querySelectorAll('[data-autocomplete]')) {
|
||||
this.genericCompletion(input);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
_tagCompletion() {
|
||||
var editForm, tags;
|
||||
editForm = document.querySelector('#edit-form');
|
||||
if (editForm == null) {
|
||||
return;
|
||||
}
|
||||
tags = document.querySelector('.ac-tags');
|
||||
if (tags == null) {
|
||||
return;
|
||||
}
|
||||
new TagCompletionBox(tags);
|
||||
return this.tagCompletionInstance.observe_tag_changes_on_submit(editForm, tags);
|
||||
}
|
||||
tagCompletion () {
|
||||
const editForm = document.querySelector('#edit-form');
|
||||
if (editForm == null) return;
|
||||
|
||||
};
|
||||
const tags = document.querySelector('.ac-tags');
|
||||
if (tags == null) return;
|
||||
|
||||
new TagCompletionBox(tags); // eslint-disable-line no-new
|
||||
this.tagCompletionInstance.observe_tag_changes_on_submit(editForm, tags);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user