Remove AJAX requests when adding a movie
I do not like how it is currently implemented and it is not necessary.master
parent
50694cc25a
commit
f803a6adfb
|
@ -8,8 +8,8 @@ function request(method, url, data, loadevent) {
|
|||
req.send(data)
|
||||
}
|
||||
|
||||
function initButtons() {
|
||||
var buttons = document.querySelectorAll('button[data-action=remove-movie]');
|
||||
function initButtons(element) {
|
||||
var buttons = element.querySelectorAll('button[data-action=remove-movie]');
|
||||
for (var i = 0; i < buttons.length; i++) {
|
||||
buttons[i].addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
|
@ -17,7 +17,7 @@ function initButtons() {
|
|||
});
|
||||
}
|
||||
|
||||
var view_buttons = document.querySelectorAll('button[data-action=view-movie]');
|
||||
var view_buttons = element.querySelectorAll('button[data-action=view-movie]');
|
||||
for (var i = 0; i < view_buttons.length; i++) {
|
||||
view_buttons[i].addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
|
@ -26,33 +26,6 @@ function initButtons() {
|
|||
}
|
||||
}
|
||||
|
||||
function initSearch() {
|
||||
var typing_timer;
|
||||
var typing_interval = 300;
|
||||
|
||||
document.querySelector('#search > input[type="text"]').addEventListener('input', function(event) {
|
||||
var value = this.value;
|
||||
|
||||
clearTimeout(typing_timer);
|
||||
typing_timer = setTimeout(function() { search(value); }, typing_interval);
|
||||
});
|
||||
document.querySelector('#search > input[type="submit"]').style.display = 'none';
|
||||
|
||||
window.addEventListener('popstate', function(event) {
|
||||
document.querySelector('#search > input[type="text"]').value = event.state.value;
|
||||
search(event.state.value);
|
||||
});
|
||||
}
|
||||
|
||||
function search(value) {
|
||||
var url = '/search?search=' + encodeURIComponent(value)
|
||||
window.history.pushState({value: value}, "", url);
|
||||
|
||||
request('GET', url, null, function(e) {
|
||||
document.getElementById('movies').parentNode.innerHTML = this.responseText;
|
||||
});
|
||||
}
|
||||
|
||||
function removeMovie(id) {
|
||||
var data = new FormData();
|
||||
data.append('id', id);
|
||||
|
@ -72,9 +45,5 @@ function viewMovie(id) {
|
|||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function(event) {
|
||||
initButtons();
|
||||
|
||||
if(document.querySelector('#search') != null) {
|
||||
initSearch();
|
||||
}
|
||||
initButtons(document);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue