Files
wallabag/app/Resources/static/themes/baggy/js/saveLink.js

76 lines
2.3 KiB
JavaScript
Raw Normal View History

2016-06-09 19:02:38 +02:00
var $ = global.jquery = require('jquery');
2015-01-28 13:58:12 +01:00
2016-06-09 19:02:38 +02:00
$.fn.ready(function () {
var $bagit = $('#bagit');
var $bagitForm = $('#bagit-form');
var $bagitFormForm = $('#bagit-form-form');
2015-01-28 13:58:12 +01:00
/* ==========================================================================
bag it link and close button
========================================================================== */
function toggleSaveLinkForm(url, event) {
2016-06-09 19:02:38 +02:00
$('#add-link-result').empty();
2015-01-28 13:58:12 +01:00
2016-06-09 19:02:38 +02:00
$bagit.toggleClass('active-current');
2015-01-28 13:58:12 +01:00
2016-06-09 19:02:38 +02:00
// only if bag-it link is not presented on page
if ($bagit.length === 0) {
if (event !== 'undefined' && event) {
$bagitForm.css({ position: 'absolute', top: event.pageY, left: event.pageX - 200 });
} else {
$bagitForm.css({ position: 'relative', top: 'auto', left: 'auto' });
2015-01-28 13:58:12 +01:00
}
}
2016-06-09 19:02:38 +02:00
if ($('#search-form').length !== 0) {
$('#search').removeClass('current');
$('#search-arrow').removeClass('arrow-down');
$('#search-form').hide();
2015-01-28 13:58:12 +01:00
}
$bagitForm.toggle();
2016-06-09 19:02:38 +02:00
$('#content').toggleClass('opacity03');
2015-01-28 13:58:12 +01:00
if (url !== 'undefined' && url) {
$('#plainurl').val(url);
}
$('#plainurl').focus();
}
2016-06-09 19:02:38 +02:00
// send 'bag it link' form request via ajax
$bagitFormForm.submit(function (event) {
$('body').css('cursor', 'wait');
$('#add-link-result').empty();
2015-01-28 13:58:12 +01:00
$.ajax({
type: $bagitFormForm.attr('method'),
url: $bagitFormForm.attr('action'),
data: $bagitFormForm.serialize(),
2016-06-09 19:02:38 +02:00
success: function (data) {
$('#add-link-result').html('Done!');
2015-01-28 13:58:12 +01:00
$('#plainurl').val('');
$('#plainurl').blur('');
2016-06-09 19:02:38 +02:00
$('body').css('cursor', 'auto');
},
error: function (data) {
$('#add-link-result').html('Failed!');
$('body').css('cursor', 'auto');
2015-01-28 13:58:12 +01:00
},
});
event.preventDefault();
});
/* ==========================================================================
Process all links inside an article
========================================================================== */
2016-06-09 19:02:38 +02:00
$('article a[href^="http"]').after(function () {
return ' <a href="' + $(this).attr('href') + '" class="add-to-wallabag-link-after" alt="add to wallabag" title="add to wallabag"></a> ';
2015-01-28 13:58:12 +01:00
});
2016-06-09 19:02:38 +02:00
$('.add-to-wallabag-link-after').click(function (event) {
2015-01-28 13:58:12 +01:00
toggleSaveLinkForm($(this).attr('href'), event);
event.preventDefault();
});
});