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)
|
req.send(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
function initButtons() {
|
function initButtons(element) {
|
||||||
var buttons = document.querySelectorAll('button[data-action=remove-movie]');
|
var buttons = element.querySelectorAll('button[data-action=remove-movie]');
|
||||||
for (var i = 0; i < buttons.length; i++) {
|
for (var i = 0; i < buttons.length; i++) {
|
||||||
buttons[i].addEventListener('click', function(event) {
|
buttons[i].addEventListener('click', function(event) {
|
||||||
event.preventDefault();
|
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++) {
|
for (var i = 0; i < view_buttons.length; i++) {
|
||||||
view_buttons[i].addEventListener('click', function(event) {
|
view_buttons[i].addEventListener('click', function(event) {
|
||||||
event.preventDefault();
|
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) {
|
function removeMovie(id) {
|
||||||
var data = new FormData();
|
var data = new FormData();
|
||||||
data.append('id', id);
|
data.append('id', id);
|
||||||
|
@ -72,9 +45,5 @@ function viewMovie(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function(event) {
|
document.addEventListener('DOMContentLoaded', function(event) {
|
||||||
initButtons();
|
initButtons(document);
|
||||||
|
|
||||||
if(document.querySelector('#search') != null) {
|
|
||||||
initSearch();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue