]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - app/Resources/static/themes/baggy/js/saveLink.js
manage assets through npm
[github/wallabag/wallabag.git] / app / Resources / static / themes / baggy / js / saveLink.js
diff --git a/app/Resources/static/themes/baggy/js/saveLink.js b/app/Resources/static/themes/baggy/js/saveLink.js
new file mode 100755 (executable)
index 0000000..91cc2c3
--- /dev/null
@@ -0,0 +1,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();
+  });
+
+});
+
+