-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
99 lines (87 loc) · 4.03 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var mus = "";
var can = "";
function pegarInformacoes() {
mus = document.getElementById('musica').value
document.getElementById('music').innerHTML = mus
can = document.getElementById('cantor').value
document.getElementById('artista').innerHTML = can
function showLetra (data,art,mus,arrayid) {
if (! arrayid) arrayid = 0;
if (data.type == 'exact' || data.type == 'aprox') {
// Print lyrics text
$('#letra .text').text(data.mus[arrayid].text);
// Show buttons to open original and portuguese translation
if (data.mus[arrayid].translate) {
$('#letra .text').prepend('<input type=button value="Portuguese »" onClick="$(document).trigger(\'translate\')"><br/>');
$(document).one('translate',function() {
$('#letra .text').text(data.mus[arrayid].translate[0].text);
$('#letra .text').prepend('<input type=button value="« Original" onClick="$(document).trigger(\'original\')"><br/>');
$(document).one('original',function() {
showLetra(data,art,mus,arrayid);
});
});
}
// If not exact match (ex: U2 / Beautiful)
if (data.type == 'aprox' && !$('#aprox').is('div')) {
$('#letra').prepend('<div id=aprox>We found something similar<br/><span class=songname>"' + data.mus[arrayid].name + '"</span></div>');
// If Vagalume found more than one possible matches
if (data.mus.length > 0) {
var html = '<select class=songselect>';
for (var i = 0; i < data.mus.length; i++) {
html += '<option value="'+i+'"'+(i==arrayid?' selected':'')+'>'+data.mus[i].name+'</option>';
}
html += '</select>';
$('#aprox span.songname').html(html);
$('#aprox select.songselect').change(function() {
var aID = $('option:selected',this).val();
showLetra (data,art,mus,aID);
});
}
}
} else if (data.type == 'song_notfound') {
// Song not found, but artist was found
// You can list all songs from Vagalume here
$('#letra .text').html(
'Song "'+mus+'" from "'+art+'" was not found.<br/>'
+'<a target=_blank href="http://www.vagalume.com.br/add/lyrics.php">'
+'Add this song to Vagalume »</a>'
);
} else {
// Artist not found
$('#letra .text').html(
'Song "'+mus+'" from "'+art+'" was not found<br/>'
+'(artist not found)<br/>'
+'<a target=_blank href="http://www.vagalume.com.br/add/lyrics.php">'
+'Add this song to Vagalume »</a>'
);
}
}
function fetchLetra (art,mus) {
var data = jQuery.data(document,art + mus); // cache read
if (data) {
showLetra(data, art, mus);
return true;
}
var url = "http://api.vagalume.com.br/search.php"
+"?art="+encodeURIComponent(art)
+"&mus="+encodeURIComponent(mus);
// Check if browser supports CORS - http://www.w3.org/TR/cors/
if (!jQuery.support.cors) {
url += "&callback=?";
}
jQuery.getJSON(url,function(data) {
// What we do with the data
jQuery.data(document,art + mus,data); // cache write
showLetra(data, art, mus);
});
}
// Just an example of how you can call this using elements on the page
fetchLetra($("#artista").text(),$("#music").text());
}
function mostra() {
document.getElementById('vag').style.display = "block"
}
document.getElementById('botao').onclick = function() {
pegarInformacoes();
mostra();
}