summaryrefslogtreecommitdiff
path: root/assets/js/checkLinks.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js/checkLinks.js')
-rw-r--r--assets/js/checkLinks.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/assets/js/checkLinks.js b/assets/js/checkLinks.js
new file mode 100644
index 0000000..bd41fb6
--- /dev/null
+++ b/assets/js/checkLinks.js
@@ -0,0 +1,53 @@
+(function ($) {
+ //
+ // RED LINK FEATURE (Hacky)
+ $.fn.checkLinks = function (staticPages) {
+ setTimeout(
+ function () {
+ $('a').each(function () {
+ // avoid red link for external urls
+ if (this.hostname != window.location.hostname) {
+ if ($(this).parents('#git-wiki-content').length > 0)
+ $(this).addClass("external-link");
+ return;
+ }
+
+ for (var k in staticPages) {
+ var page = staticPages[k];
+ var link = document.createElement("a");
+ link.href = page;
+
+ if (this.href === link.href) {
+ return;
+ }
+ }
+
+ var ext = this.pathname.split('.').pop().split(/\#|\?/)[0];
+
+ // pessimistic condition based on the fact that
+ // markdown files are automatically converted in html
+ // if they are part of the wiki (the real check is right below)
+ var lExt = ext && ext.toLowerCase();
+ var isRed = lExt == "md" || lExt == "markdown";
+
+ if (isRed)
+ $(this).css('color', 'red');
+
+ var that = this;
+ $.ajax({
+ type: 'HEAD',
+ url: this.href,
+ success: function () {
+ $(that).css('color', '');
+ },
+ error: function (xhr, ajaxOptions, thrownError) {
+ if (xhr.status == 404) {
+ $(that).css('color', 'red');
+ }
+ }
+ });
+ });
+ }, 0);
+ };
+
+})(jQuery); \ No newline at end of file