aboutsummaryrefslogtreecommitdiffhomepage
path: root/themes/_global/js/saveLink.js
diff options
context:
space:
mode:
Diffstat (limited to 'themes/_global/js/saveLink.js')
-rwxr-xr-xthemes/_global/js/saveLink.js109
1 files changed, 109 insertions, 0 deletions
diff --git a/themes/_global/js/saveLink.js b/themes/_global/js/saveLink.js
new file mode 100755
index 00000000..a7acd84c
--- /dev/null
+++ b/themes/_global/js/saveLink.js
@@ -0,0 +1,109 @@
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 Keyboard gestion
83 ========================================================================== */
84
85 $(window).keydown(function(e){
86 if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || (e.keyCode == 27 && $bagitForm.is(':visible') ) ) {
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() {
99 return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\"></a> ";
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