1
0
Fork 0
mirror of https://github.com/Findus23/acronomy.git synced 2024-09-19 15:33:45 +02:00
acronomy/static/app.js

75 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-06-01 11:03:21 +02:00
$(function () {
$('[data-toggle="tooltip"]').tooltip()
2020-06-15 19:40:55 +02:00
new Autocomplete('#autocomplete', {
2020-06-13 21:18:58 +02:00
2020-06-15 19:40:55 +02:00
search: input => {
2020-06-01 11:03:21 +02:00
2020-06-15 19:40:55 +02:00
const acroSearch = input.split(':')[0];
const url = "/api/acronym/?search=" + acroSearch
2020-06-01 11:03:21 +02:00
2020-06-15 19:40:55 +02:00
return new Promise(resolve => {
if (acroSearch.length < 1) {
return resolve([])
}
2020-06-01 11:03:21 +02:00
2020-06-15 19:40:55 +02:00
fetch(url)
.then(response => response.json())
.then(data => {
resolve(data)
})
})
},
2020-06-01 11:03:21 +02:00
2020-06-15 19:40:55 +02:00
getResultValue: result => (result.name + ": " + result.full_name),
2020-06-01 11:03:21 +02:00
2020-06-15 19:40:55 +02:00
// Open the selected article in
// a new window
onSubmit: result => {
console.log(result)
window.location = "/acronym/" + result.slug
},
autoSelect: true,
2020-06-01 11:03:21 +02:00
})
2020-06-15 19:40:55 +02:00
const input = document.querySelector('input[name="tags"]')
input.classList.remove("form-control")
document.querySelector("form").addEventListener("submit", function () {
const list = JSON.parse(input.value).map(function (item) {
return item['value'];
2020-06-01 11:03:21 +02:00
})
2020-06-15 19:40:55 +02:00
input.value = list.join(",")
console.log(input.value)
return false;
})
const tagify = new Tagify(input, {
whitelist: [],
maxTags: 10,
dropdown: {
maxItems: 20,
enabled: 0
}
})
fetch("/api/tag/")
.then(response => response.json())
.then(data =>
data.map(function (item) {
return item['name'];
})
)
.then(data => {
2020-06-01 11:03:21 +02:00
2020-06-15 19:40:55 +02:00
tagify.settings.whitelist = data
2020-06-01 11:03:21 +02:00
2020-06-15 19:40:55 +02:00
})
2020-06-01 11:03:21 +02:00
2020-06-15 19:40:55 +02:00
const myCodeMirror = CodeMirror.fromTextArea(
document.getElementById("id_description_md"),
{
lineWrapping: true,
lineNumbers: true,
}
);
})