]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Resources/public/themes/baggy/js/saveLink.js
Merge pull request #2097 from bmillemathias/issue_2045
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Resources / public / themes / baggy / js / saveLink.js
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
39 //---------------------------------------------------------------------------
40 // These two functions are now taken care of in popupForm.js
41 //---------------------------------------------------------------------------
42
43 // $bagit.click(function(){
44 // $bagit.toggleClass("current");
45 // $("#bagit-arrow").toggleClass("arrow-down");
46 // toggleSaveLinkForm();
47 // });
48
49 // $("#bagit-form-close").click(function(){
50 // $bagit.removeClass("current");
51 // $("#bagit-arrow").removeClass("arrow-down");
52 // toggleSaveLinkForm();
53 // });
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 Process all links inside an article
83 ========================================================================== */
84
85 $("article a[href^='http']").after(function() {
86 return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\"></a> ";
87 });
88
89 $(".add-to-wallabag-link-after").click(function(event){
90 toggleSaveLinkForm($(this).attr('href'), event);
91 event.preventDefault();
92 });
93
94 });
95
96