+ }
+
+ //---------------------------------------------------------------------------
+ // Close all #links popups in the sidebar
+ //---------------------------------------------------------------------------
+ function closePopups() {
+ $('#links .messages').hide();
+ $('#links > li > a').removeClass('active-current');
+ $('#links > li > a').removeClass('current');
+ $('[id$=-arrow]').removeClass('arrow-down');
+ $('#content').removeClass('opacity03');
+ }
+
+ $('#search').click(() => {
+ closePopups();
+ toggleSearch();
+ $('#searchfield').focus();
+ });
+
+ $('.filter-btn').click(() => {
+ closePopups();
+ toggleFilter();
+ });
+
+ $('.download-btn').click(() => {
+ closePopups();
+ toggleDownload();
+ });
+
+ $('#bagit').click(() => {
+ closePopups();
+ toggleBagit();
+ $('#plainurl').focus();
+ });
+
+ $('#search-form-close').click(() => {
+ toggleSearch();
+ });
+
+ $('#filter-form-close').click(() => {
+ toggleFilter();
+ });
+
+ $('#download-form-close').click(() => {
+ toggleDownload();
+ });
+
+ $('#bagit-form-close').click(() => {
+ toggleBagit();
+ });
+
+ const $bagitFormForm = $('#bagit-form-form');
+
+ /* ==========================================================================
+ bag it link and close button
+ ========================================================================== */
+
+ // send 'bag it link' form request via ajax
+ $bagitFormForm.submit((event) => {
+ $('body').css('cursor', 'wait');
+ $('#add-link-result').empty();
+
+ $.ajax({
+ type: $bagitFormForm.attr('method'),
+ url: $bagitFormForm.attr('action'),
+ data: $bagitFormForm.serialize(),
+ success: function success() {
+ $('#add-link-result').html('Done!');
+ $('#plainurl').val('');
+ $('#plainurl').blur('');
+ $('body').css('cursor', 'auto');
+ },
+ error: function error() {
+ $('#add-link-result').html('Failed!');
+ $('body').css('cursor', 'auto');
+ },
+ });
+
+ event.preventDefault();
+ });
+
+ /* ==========================================================================
+ Process all links inside an article
+ ========================================================================== */
+
+ $('article a[href^="http"]').after(
+ () => `<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((event) => {
+ toggleSaveLinkForm($(this).attr('href'), event);
+ event.preventDefault();
+ });