]>
Commit | Line | Data |
---|---|---|
19f2f11e NL |
1 | $.fn.ready(function() { |
2 | ||
3 | var $bagit = $('#bagit'), | |
4 | $bagitForm = $('#bagit-form'), | |
5 | $bagitFormForm = $('#bagit-form-form'); | |
6 | ||
7 | /* ========================================================================== | |
8 | bag it link and close button | |
9 | ========================================================================== */ | |
10 | ||
11 | function toggleSaveLinkForm(url, event) { | |
12 | $("#add-link-result").empty(); | |
13 | ||
14 | $bagit.toggleClass("active-current"); | |
15 | ||
16 | //only if bag-it link is not presented on page | |
17 | if ( $bagit.length === 0 ) { | |
18 | if ( event !== 'undefined' && event ) { | |
19 | $bagitForm.css( {position:"absolute", top:event.pageY, left:event.pageX-200}); | |
20 | } | |
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 | ||
19f2f11e NL |
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"); | |
19f2f11e NL |
53 | }, |
54 | error: function(data) { | |
55 | $('#add-link-result').html("Failed!"); | |
56 | $("body").css("cursor", "auto"); | |
57 | } | |
58 | }); | |
59 | ||
60 | event.preventDefault(); | |
61 | }); | |
62 | ||
19f2f11e NL |
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 | ||
76 | }); | |
77 | ||
78 |