]>
Commit | Line | Data |
---|---|---|
e68348f6 MR |
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 | ||
48fb171d | 16 | //only if bag-it link is not presented on page |
e68348f6 MR |
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 | ||
48fb171d | 26 | if ($("#search-form").length != 0) { |
27 | $("#search").removeClass("current"); | |
28 | $("#search-arrow").removeClass("arrow-down"); | |
29 | $("#search-form").hide(); | |
30 | } | |
e68348f6 MR |
31 | $bagitForm.toggle(); |
32 | $('#content').toggleClass("opacity03"); | |
33 | if (url !== 'undefined' && url) { | |
34 | $('#plainurl').val(url); | |
35 | } | |
36 | $('#plainurl').focus(); | |
37 | } | |
38 | ||
ff02fd8a JS |
39 | //--------------------------------------------------------------------------- |
40 | // These two functions are now taken care of in popupForm.js | |
41 | //--------------------------------------------------------------------------- | |
e68348f6 | 42 | |
ff02fd8a JS |
43 | // $bagit.click(function(){ |
44 | // $bagit.toggleClass("current"); | |
45 | // $("#bagit-arrow").toggleClass("arrow-down"); | |
46 | // toggleSaveLinkForm(); | |
47 | // }); | |
e68348f6 | 48 | |
ff02fd8a JS |
49 | // $("#bagit-form-close").click(function(){ |
50 | // $bagit.removeClass("current"); | |
51 | // $("#bagit-arrow").removeClass("arrow-down"); | |
52 | // toggleSaveLinkForm(); | |
53 | // }); | |
e68348f6 MR |
54 | |
55 | ||
56 | //send "bag it link" form request via ajax | |
57 | $bagitFormForm.submit( function(event) { | |
58 | $("body").css("cursor", "wait"); | |
59 | $("#add-link-result").empty(); | |
60 | ||
61 | $.ajax({ | |
62 | type: $bagitFormForm.attr('method'), | |
63 | url: $bagitFormForm.attr('action'), | |
64 | data: $bagitFormForm.serialize(), | |
65 | success: function(data) { | |
66 | $('#add-link-result').html("Done!"); | |
67 | $('#plainurl').val(''); | |
68 | $('#plainurl').blur(''); | |
69 | $("body").css("cursor", "auto"); | |
70 | //setTimeout( function() { toggleSaveLinkForm(); }, 1000); //close form after 1000 delay | |
71 | }, | |
72 | error: function(data) { | |
73 | $('#add-link-result').html("Failed!"); | |
74 | $("body").css("cursor", "auto"); | |
75 | } | |
76 | }); | |
77 | ||
78 | event.preventDefault(); | |
79 | }); | |
80 | ||
81 | /* ========================================================================== | |
82 | Keyboard gestion | |
83 | ========================================================================== */ | |
84 | ||
85 | $(window).keydown(function(e){ | |
f8e9d8bd | 86 | if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || (e.keyCode == 27 && $bagitForm.is(':visible') ) ) { |
e68348f6 MR |
87 | $bagit.removeClass("current"); |
88 | $("#bagit-arrow").removeClass("arrow-down"); | |
89 | toggleSaveLinkForm(); | |
90 | return false; | |
91 | } | |
92 | }); | |
93 | ||
94 | /* ========================================================================== | |
95 | Process all links inside an article | |
96 | ========================================================================== */ | |
97 | ||
98 | $("article a[href^='http']").after(function() { | |
74e09e56 | 99 | return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\"></a> "; |
e68348f6 MR |
100 | }); |
101 | ||
102 | $(".add-to-wallabag-link-after").click(function(event){ | |
103 | toggleSaveLinkForm($(this).attr('href'), event); | |
104 | event.preventDefault(); | |
105 | }); | |
106 | ||
107 | }); | |
108 | ||
109 |