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