mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-20 08:01:05 +00:00
75 lines
2.3 KiB
JavaScript
Executable file
75 lines
2.3 KiB
JavaScript
Executable file
var $ = global.jquery = require('jquery');
|
|
|
|
$.fn.ready(function () {
|
|
var $bagit = $('#bagit');
|
|
var $bagitForm = $('#bagit-form');
|
|
var $bagitFormForm = $('#bagit-form-form');
|
|
|
|
/* ==========================================================================
|
|
bag it link and close button
|
|
========================================================================== */
|
|
|
|
function toggleSaveLinkForm(url, event) {
|
|
$('#add-link-result').empty();
|
|
|
|
$bagit.toggleClass('active-current');
|
|
|
|
// 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' });
|
|
}
|
|
}
|
|
|
|
if ($('#search-form').length !== 0) {
|
|
$('#search').removeClass('current');
|
|
$('#search-arrow').removeClass('arrow-down');
|
|
$('#search-form').hide();
|
|
}
|
|
$bagitForm.toggle();
|
|
$('#content').toggleClass('opacity03');
|
|
if (url !== 'undefined' && url) {
|
|
$('#plainurl').val(url);
|
|
}
|
|
$('#plainurl').focus();
|
|
}
|
|
|
|
// send 'bag it link' form request via ajax
|
|
$bagitFormForm.submit(function (event) {
|
|
$('body').css('cursor', 'wait');
|
|
$('#add-link-result').empty();
|
|
|
|
$.ajax({
|
|
type: $bagitFormForm.attr('method'),
|
|
url: $bagitFormForm.attr('action'),
|
|
data: $bagitFormForm.serialize(),
|
|
success: function (data) {
|
|
$('#add-link-result').html('Done!');
|
|
$('#plainurl').val('');
|
|
$('#plainurl').blur('');
|
|
$('body').css('cursor', 'auto');
|
|
},
|
|
error: function (data) {
|
|
$('#add-link-result').html('Failed!');
|
|
$('body').css('cursor', 'auto');
|
|
},
|
|
});
|
|
|
|
event.preventDefault();
|
|
});
|
|
|
|
/* ==========================================================================
|
|
Process all links inside an article
|
|
========================================================================== */
|
|
|
|
$('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> ';
|
|
});
|
|
|
|
$('.add-to-wallabag-link-after').click(function (event) {
|
|
toggleSaveLinkForm($(this).attr('href'), event);
|
|
event.preventDefault();
|
|
});
|
|
});
|