Browse Source

Add an example JS file that gets webmentions

Chimo 3 years ago
parent
commit
13908de0ce
1 changed files with 38 additions and 0 deletions
  1. 38
    0
      webmentions.js

+ 38
- 0
webmentions.js View File

@@ -0,0 +1,38 @@
1
+( function( ) {
2
+    "use strict";
3
+
4
+    var url = document.location.href;
5
+
6
+    $.ajax(
7
+        "http://chromic.org/php/webmention/get.php",
8
+        {
9
+            type: "POST",
10
+            data: {
11
+                target: url
12
+            },
13
+            success: function( data ) {
14
+                var i,
15
+                    len = data.length,
16
+                    /* $container = $( "#webmentions" ), */
17
+                    $container = $( "body" ),
18
+                    html = "<ul>";
19
+
20
+                if ( len === 0 ) {
21
+                    return;
22
+                }
23
+
24
+                for ( i = 0; i < len; i += 1 ) {
25
+                    html += "<li>" + data[ i ] + "</li>";
26
+                }
27
+
28
+                $container
29
+                    .append( html + "</ul>" )
30
+                    .show();
31
+            },
32
+            error: function( xhr, status ) {
33
+                window.console.log( "Error fetching webentions: " + status );
34
+            }
35
+        }
36
+    );
37
+
38
+}() );

Loading…
Cancel
Save