aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Resources/static/themes/baggy/js/saveLink.js
blob: 91cc2c3fab58d2909eef681ea08099e8eca6faab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
$.fn.ready(function() {

  var $bagit = $('#bagit'),
      $bagitForm = $('#bagit-form'),
      $bagitFormForm = $('#bagit-form-form');

  /* ==========================================================================
   bag it link and close button
   ========================================================================== */

  function toggleSaveLinkForm(url, event) {
    $("#add-link-result").empty();

    $bagit.toggleClass("active-current");

    //only if bag-it link is not presented on page
    if ( $bagit.length === 0 ) {
      if ( event !== 'undefined' && event ) {
        $bagitForm.css( {position:"absolute", top:event.pageY, left:event.pageX-200});
      }
      else {
        $bagitForm.css( {position:"relative", top:"auto", left:"auto"});
      }
    }

    if ($("#search-form").length != 0) {
    	$("#search").removeClass("current");
    	$("#search-arrow").removeClass("arrow-down");
    	$("#search-form").hide();
    }
    $bagitForm.toggle();
    $('#content').toggleClass("opacity03");
    if (url !== 'undefined' && url) {
      $('#plainurl').val(url);
    }
    $('#plainurl').focus();
  }

  //send "bag it link" form request via ajax
  $bagitFormForm.submit( function(event) {
    $("body").css("cursor", "wait");
    $("#add-link-result").empty();

    $.ajax({
      type: $bagitFormForm.attr('method'),
      url: $bagitFormForm.attr('action'),
      data: $bagitFormForm.serialize(),
      success: function(data) {
        $('#add-link-result').html("Done!");
        $('#plainurl').val('');
        $('#plainurl').blur('');
        $("body").css("cursor", "auto");
      },
      error: function(data) {
        $('#add-link-result').html("Failed!");
        $("body").css("cursor", "auto");
      }
    });

    event.preventDefault();
  });

  /* ==========================================================================
   Process all links inside an article
   ========================================================================== */

  $("article a[href^='http']").after(function() {
    return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\"></a> ";
  });

  $(".add-to-wallabag-link-after").click(function(event){
    toggleSaveLinkForm($(this).attr('href'), event);
    event.preventDefault();
  });

});