]> git.immae.eu Git - github/wallabag/wallabag.git/blame - app/Resources/static/themes/baggy/js/saveLink.js
Merge pull request #2309 from mruminski/2.1
[github/wallabag/wallabag.git] / app / Resources / static / themes / baggy / js / saveLink.js
CommitLineData
0743287f 1var $ = global.jquery = require('jquery');
19f2f11e 2
0743287f
TC
3$.fn.ready(function () {
4 var $bagit = $('#bagit');
5 var $bagitForm = $('#bagit-form');
6 var $bagitFormForm = $('#bagit-form-form');
19f2f11e
NL
7
8 /* ==========================================================================
9 bag it link and close button
10 ========================================================================== */
11
12 function toggleSaveLinkForm(url, event) {
0743287f 13 $('#add-link-result').empty();
19f2f11e 14
0743287f 15 $bagit.toggleClass('active-current');
19f2f11e 16
0743287f
TC
17 // only if bag-it link is not presented on page
18 if ($bagit.length === 0) {
19 if (event !== 'undefined' && event) {
20 $bagitForm.css({ position: 'absolute', top: event.pageY, left: event.pageX - 200 });
21 } else {
22 $bagitForm.css({ position: 'relative', top: 'auto', left: 'auto' });
19f2f11e
NL
23 }
24 }
25
0743287f
TC
26 if ($('#search-form').length !== 0) {
27 $('#search').removeClass('current');
28 $('#search-arrow').removeClass('arrow-down');
29 $('#search-form').hide();
19f2f11e
NL
30 }
31 $bagitForm.toggle();
0743287f 32 $('#content').toggleClass('opacity03');
19f2f11e
NL
33 if (url !== 'undefined' && url) {
34 $('#plainurl').val(url);
35 }
36 $('#plainurl').focus();
37 }
38
0743287f
TC
39 // send 'bag it link' form request via ajax
40 $bagitFormForm.submit(function (event) {
41 $('body').css('cursor', 'wait');
42 $('#add-link-result').empty();
19f2f11e
NL
43
44 $.ajax({
45 type: $bagitFormForm.attr('method'),
46 url: $bagitFormForm.attr('action'),
47 data: $bagitFormForm.serialize(),
0743287f
TC
48 success: function (data) {
49 $('#add-link-result').html('Done!');
19f2f11e
NL
50 $('#plainurl').val('');
51 $('#plainurl').blur('');
0743287f
TC
52 $('body').css('cursor', 'auto');
53 },
54 error: function (data) {
55 $('#add-link-result').html('Failed!');
56 $('body').css('cursor', 'auto');
19f2f11e 57 },
19f2f11e
NL
58 });
59
60 event.preventDefault();
61 });
62
19f2f11e
NL
63 /* ==========================================================================
64 Process all links inside an article
65 ========================================================================== */
66
0743287f
TC
67 $('article a[href^="http"]').after(function () {
68 return ' <a href="' + $(this).attr('href') + '" class="add-to-wallabag-link-after" alt="add to wallabag" title="add to wallabag"></a> ';
19f2f11e
NL
69 });
70
0743287f 71 $('.add-to-wallabag-link-after').click(function (event) {
19f2f11e
NL
72 toggleSaveLinkForm($(this).attr('href'), event);
73 event.preventDefault();
74 });
19f2f11e 75});