-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
55 lines (47 loc) · 1.4 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
( function ( $ ) {
$( '#search-movie' ).keyup( function () {
var query = $( this ).val();
if ( query.length > 2 ) {
$.ajax( {
method: 'post',
url: movies.adminAjax,
data: {
action: 'findMovie',
query: query
},
beforeSend: function () {
if ( $( '#movie-finder .search-results' ).length ) {
$( '#movie-finder .search-results' ).html( '<p>Buscando Películas</p>' );
}
else {
$( '#movie-finder' ).append( '<div class="search-results"><p>Buscando Películas</p></div>' );
}
},
success: function ( movies ) {
var $wrapper = $( '#movie-finder .search-results' );
if ( movies.length ) {
var moviesMArkup = searchResultsMarkup( movies );
$wrapper.html( moviesMArkup );
}
else {
$wrapper.html( '<p>No se encontraron películas</p>' );
}
}
} );
}
} );
function searchResultsMarkup( movies ) {
var markup = '';
movies.forEach( function ( movie ) {
markup += '<div class="movie-wrapper">';
markup += ' <div class="image">';
markup += ' <a href="' + movie.link + '"><img src="' + movie.image + '"></a>';
markup += ' </div>';
markup += ' <div class="content">';
markup += ' <h4><a href="' + movie.link + '">' + movie.title + '</a></h4>';
markup += ' </div>';
markup += '</div>';
} );
return markup;
}
} )( jQuery );