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