Skip to content

Instantly share code, notes, and snippets.

@antecedent
Created December 14, 2017 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antecedent/fbd9ab441a91ba83f589872dce0ed534 to your computer and use it in GitHub Desktop.
Save antecedent/fbd9ab441a91ba83f589872dce0ed534 to your computer and use it in GitHub Desktop.
Mini užduotis
<!DOCTYPE html>
<html lang="lt">
<head>
<meta charset="utf-8">
<title>Pašto indeksai</title>
<script
src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>
<style type="text/css">
table {
border-collapse: collapse;
}
td {
padding: 10px;
border-bottom: 1px solid gray;
}
</style>
</head>
<body>
<table>
<tr>
<td>Saltoniškių g. 12</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Didlaukio g. 47</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Kalvarijų g. 98</td>
<td>&nbsp;</td>
</tr>
</table>
<script src="adresai.js"></script>
</body>
</html>
$(function() {
var sort = function() {
var result = $('tr').toArray().sort(function(a, b) {
a = $(a).find('td:last-child').text();
b = $(b).find('td:last-child').text();
if (a == b) {
return 0;
}
return a < b ? -1 : 1;
});
$('table').empty().append($(result));
};
var makeHandler = function(cell) {
return function(data) {
cell.text(data.data[0].post_code);
sort();
};
};
$('td:first-child').each(function() {
$.get({
url: 'https://postit.lt/data/',
dataType: 'json',
data: {
address: $(this).text() + ', Vilnius'
}
})
.done(makeHandler($(this).closest('tr').find('td:last-child')))
.fail(function() {
window.alert('Negautas tinkamas atsakymas iš serviso.');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment