]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - themes/default/js/saveLink.js
b52b8a2c2bb0c35156cd66efe2c004f66417ff1e
1 $.fn
.ready(function() {
3 var $bagit
= $('#bagit'),
4 $bagitForm
= $('#bagit-form'),
5 $bagitFormForm
= $('#bagit-form-form');
7 /* ==========================================================================
8 bag it link and close button
9 ========================================================================== */
11 function toggleSaveLinkForm(url
, event
) {
12 $("#add-link-result").empty();
14 $bagit
.toggleClass("active-current");
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});
22 $bagitForm
.css( {position:"relative", top:"auto", left:"auto"});
26 if ($("#search-form").length
!= 0) {
27 $("#search").removeClass("current");
28 $("#search-arrow").removeClass("arrow-down");
29 $("#search-form").hide();
32 $('#content').toggleClass("opacity03");
33 if (url
!== 'undefined' && url
) {
34 $('#plainurl').val(url
);
36 $('#plainurl').focus();
40 $bagit
.click(function(){
41 $bagit
.toggleClass("current");
42 $("#bagit-arrow").toggleClass("arrow-down");
46 $("#bagit-form-close").click(function(){
47 $bagit
.removeClass("current");
48 $("#bagit-arrow").removeClass("arrow-down");
53 //send "bag it link" form request via ajax
54 $bagitFormForm
.submit( function(event
) {
55 $("body").css("cursor", "wait");
56 $("#add-link-result").empty();
59 type: $bagitFormForm
.attr('method'),
60 url: $bagitFormForm
.attr('action'),
61 data: $bagitFormForm
.serialize(),
62 success: function(data
) {
63 $('#add-link-result').html("Done!");
64 $('#plainurl').val('');
65 $('#plainurl').blur('');
66 $("body").css("cursor", "auto");
67 //setTimeout( function() { toggleSaveLinkForm(); }, 1000); //close form after 1000 delay
69 error: function(data
) {
70 $('#add-link-result').html("Failed!");
71 $("body").css("cursor", "auto");
75 event
.preventDefault();
78 /* ==========================================================================
80 ========================================================================== */
82 $(window
).keydown(function(e
){
83 if ( ( e
.target
.tagName
.toLowerCase() !== 'input' && e
.keyCode
== 83 ) || (e
.keyCode
== 27 && $bagitForm
.is(':visible') ) ) {
84 $bagit
.removeClass("current");
85 $("#bagit-arrow").removeClass("arrow-down");
91 /* ==========================================================================
92 Process all links inside an article
93 ========================================================================== */
95 $("article a[href^='http']").after(function() {
96 return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\"></a> ";
99 $(".add-to-wallabag-link-after").click(function(event
){
100 toggleSaveLinkForm($(this).attr('href'), event
);
101 event
.preventDefault();