]>
Commit | Line | Data |
---|---|---|
1 | var $ = global.jquery = require('jquery'); | |
2 | ||
3 | $.fn.ready(function () { | |
4 | var $bagit = $('#bagit'); | |
5 | var $bagitForm = $('#bagit-form'); | |
6 | var $bagitFormForm = $('#bagit-form-form'); | |
7 | ||
8 | /* ========================================================================== | |
9 | bag it link and close button | |
10 | ========================================================================== */ | |
11 | ||
12 | function toggleSaveLinkForm(url, event) { | |
13 | $('#add-link-result').empty(); | |
14 | ||
15 | $bagit.toggleClass('active-current'); | |
16 | ||
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' }); | |
23 | } | |
24 | } | |
25 | ||
26 | if ($('#search-form').length !== 0) { | |
27 | $('#search').removeClass('current'); | |
28 | $('#search-arrow').removeClass('arrow-down'); | |
29 | $('#search-form').hide(); | |
30 | } | |
31 | $bagitForm.toggle(); | |
32 | $('#content').toggleClass('opacity03'); | |
33 | if (url !== 'undefined' && url) { | |
34 | $('#plainurl').val(url); | |
35 | } | |
36 | $('#plainurl').focus(); | |
37 | } | |
38 | ||
39 | // send 'bag it link' form request via ajax | |
40 | $bagitFormForm.submit(function (event) { | |
41 | $('body').css('cursor', 'wait'); | |
42 | $('#add-link-result').empty(); | |
43 | ||
44 | $.ajax({ | |
45 | type: $bagitFormForm.attr('method'), | |
46 | url: $bagitFormForm.attr('action'), | |
47 | data: $bagitFormForm.serialize(), | |
48 | success: function (data) { | |
49 | $('#add-link-result').html('Done!'); | |
50 | $('#plainurl').val(''); | |
51 | $('#plainurl').blur(''); | |
52 | $('body').css('cursor', 'auto'); | |
53 | }, | |
54 | error: function (data) { | |
55 | $('#add-link-result').html('Failed!'); | |
56 | $('body').css('cursor', 'auto'); | |
57 | }, | |
58 | }); | |
59 | ||
60 | event.preventDefault(); | |
61 | }); | |
62 | ||
63 | /* ========================================================================== | |
64 | Process all links inside an article | |
65 | ========================================================================== */ | |
66 | ||
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> '; | |
69 | }); | |
70 | ||
71 | $('.add-to-wallabag-link-after').click(function (event) { | |
72 | toggleSaveLinkForm($(this).attr('href'), event); | |
73 | event.preventDefault(); | |
74 | }); | |
75 | }); |