nurl/public/javascripts/shorten.js

39 lines
954 B
JavaScript
Raw Normal View History

2017-08-05 20:14:17 +00:00
$('#btn-shorten').on('click', function(){
2016-02-07 21:16:07 +00:00
$.ajax({
2017-08-05 20:14:17 +00:00
url: '/api/v1/shorten',
2016-02-07 21:16:07 +00:00
type: 'POST',
dataType: 'JSON',
data: {url: $('#url-field').val()},
success: function(data){
2017-08-05 22:28:59 +00:00
const $link = $('#link');
const resultHTML = `<a class="result" href="${data.shortUrl}">${data.shortUrl}</a>`;
$link.html(resultHTML);
$link.hide().fadeIn('slow');
2016-02-07 21:16:07 +00:00
}
});
});
2017-08-05 22:41:26 +00:00
(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);