nurl/public/javascripts/shorten.js
Martin Donnelly 868b705b72 gulp stuff
2017-08-05 23:43:02 +01:00

40 lines
986 B
JavaScript

$('#btn-shorten').on('click', function(){
$.ajax({
url: '/api/v1/shorten',
type: 'POST',
dataType: 'JSON',
data: {url: $('#url-field').val()},
success: function(data){
const $link = $('#link');
const resultHTML = `<a class="result" href="${data.shortUrl}">${data.shortUrl}</a>`;
$link.html(resultHTML);
// $link.hide().fadeIn('slow');
$link.hide().show();
}
});
});
(function($) {
$.extend($.fn, {
fadeIn: function(ms) {
if(typeof(ms) === 'undefined') ms = 500;
$(this).css({ display: 'block', opacity: 0 }).animate({ opacity: 1 }, ms);
return this;
},
fadeOut: function(ms)
{
if(typeof(ms) === 'undefined') ms = 500;
$(this).css({ opacity: 1 }).animate({ opacity: 0 }, ms, 'linear', function() {
$(this).css('display', 'none');
});
return this;
}
});
})(Zepto);