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.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/themes/_global/js/saveLink.js b/themes/_global/js/saveLink.js
new file mode 100755
index 00000000..b7dd7a34
--- /dev/null
+++ b/themes/_global/js/saveLink.js
@@ -0,0 +1,119 @@
1$.fn.ready(function() {
2
3 var $bagit = $('#bagit'),
4 $bagitForm = $('#bagit-form'),
5 $bagitFormForm = $('#bagit-form-form');
6
7$("#tags2add").hide();
8
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
18 //only if bag-it link is not presented on page
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
28 if ($("#search-form").length != 0) {
29 $("#search").removeClass("current");
30 $("#search-arrow").removeClass("arrow-down");
31 $("#search-form").hide();
32 }
33 $bagitForm.toggle();
34 $('#content').toggleClass("opacity03");
35 if (url !== 'undefined' && url) {
36 $('#plainurl').val(url);
37 }
38 $('#plainurl').focus();
39 }
40
41 //---------------------------------------------------------------------------
42 // These two functions are now taken care of in popupForm.js
43 //---------------------------------------------------------------------------
44
45 // $bagit.click(function(){
46 // $bagit.toggleClass("current");
47 // $("#bagit-arrow").toggleClass("arrow-down");
48 // toggleSaveLinkForm();
49 // });
50
51 // $("#bagit-form-close").click(function(){
52 // $bagit.removeClass("current");
53 // $("#bagit-arrow").removeClass("arrow-down");
54 // toggleSaveLinkForm();
55 // });
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
83$('#showtaginput').click(function(){
84 $('#tags2add').toggle();
85 $('#plainurl').toggle();
86 $('#showtaginput').toggleClass('icon-tags');
87 $('#showtaginput').toggleClass('icon-check');
88});
89
90
91 /* ==========================================================================
92 Keyboard gestion
93 ========================================================================== */
94
95 $(window).keydown(function(e){
96 if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || (e.keyCode == 27 && $bagitForm.is(':visible') ) ) {
97 $bagit.removeClass("current");
98 $("#bagit-arrow").removeClass("arrow-down");
99 toggleSaveLinkForm();
100 return false;
101 }
102 });
103
104 /* ==========================================================================
105 Process all links inside an article
106 ========================================================================== */
107
108 $("article a[href^='http']").after(function() {
109 return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\"></a> ";
110 });
111
112 $(".add-to-wallabag-link-after").click(function(event){
113 toggleSaveLinkForm($(this).attr('href'), event);
114 event.preventDefault();
115 });
116
117});
118
119