aboutsummaryrefslogtreecommitdiffhomepage
path: root/themes/default/js/saveLink.js
diff options
context:
space:
mode:
authorMaryana Rozhankivska <mariroz@mr.lviv.ua>2014-03-27 18:21:30 +0200
committerMaryana Rozhankivska <mariroz@mr.lviv.ua>2014-03-27 18:21:30 +0200
commite68348f6271fab591960902feebe167d01e15468 (patch)
tree32c4d866fe41f7f7ff13c100bad67e94b6d76f9b /themes/default/js/saveLink.js
parentd60733055714bbe43b9f7d4f4ade8576f1042bb1 (diff)
downloadwallabag-e68348f6271fab591960902feebe167d01e15468.tar.gz
wallabag-e68348f6271fab591960902feebe167d01e15468.tar.zst
wallabag-e68348f6271fab591960902feebe167d01e15468.zip
wallabag a link in wallabag now in default theme, issue #505
Diffstat (limited to 'themes/default/js/saveLink.js')
-rwxr-xr-xthemes/default/js/saveLink.js101
1 files changed, 101 insertions, 0 deletions
diff --git a/themes/default/js/saveLink.js b/themes/default/js/saveLink.js
new file mode 100755
index 00000000..ccc00d1e
--- /dev/null
+++ b/themes/default/js/saveLink.js
@@ -0,0 +1,101 @@
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){
78 if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || e.keyCode == 27 ) {
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() {
91 return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\">w</a> ";
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