Minor changes
This commit is contained in:
46
scripts/posts.ts
Normal file
46
scripts/posts.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import * as $ from './aqua'
|
||||
|
||||
function like(type, id) {
|
||||
$.post(`/api/${type}/like/` + id)
|
||||
$.find('like-' + id).style.display = 'none'
|
||||
$.find('unlike-' + id).style.display = 'inline-block'
|
||||
|
||||
let likes = $.find('likes-' + id)
|
||||
likes.innerHTML = (parseInt(likes.textContent) + 1).toString()
|
||||
}
|
||||
|
||||
function unlike(type, id) {
|
||||
$.post(`/api/${type}/unlike/` + id)
|
||||
$.find('like-' + id).style.display = 'inline-block'
|
||||
$.find('unlike-' + id).style.display = 'none'
|
||||
|
||||
let likes = $.find('likes-' + id)
|
||||
likes.innerHTML = (parseInt(likes.textContent) - 1).toString()
|
||||
}
|
||||
|
||||
function edit(id) {
|
||||
$.find('source-' + id).style.display = 'block'
|
||||
$.find('save-' + id).style.display = 'block'
|
||||
$.find('render-' + id).style.display = 'none'
|
||||
$.find('toolbar-' + id).style.display = 'none'
|
||||
}
|
||||
|
||||
function cancelEdit(id) {
|
||||
$.find('source-' + id).style.display = 'none'
|
||||
$.find('save-' + id).style.display = 'none'
|
||||
$.find('render-' + id).style.display = ''
|
||||
$.find('toolbar-' + id).style.display = ''
|
||||
}
|
||||
|
||||
function saveEdit(type, id) {
|
||||
let source = <HTMLInputElement> $.find('source-' + id)
|
||||
let text = source.value
|
||||
|
||||
$.post(`/api/${type}/edit/` + id, {
|
||||
id,
|
||||
text
|
||||
}).then(response => {
|
||||
$.find('render-' + id).innerHTML = response
|
||||
cancelEdit(id)
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user