X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=public%2Findex.js;h=8d6c506bd533a71ff70ed92b0e33f0c32f07b2bc;hb=ba46a6cdffd56d99c191b8fa9a510cf7c6af45bd;hp=4878936a383649981948a0b3645b81534c10b3f3;hpb=4887931d502e44a0fe0d3fcc77f1efe72ca3dd79;p=mdref%2Fmdref diff --git a/public/index.js b/public/index.js index 4878936..8d6c506 100644 --- a/public/index.js +++ b/public/index.js @@ -129,7 +129,7 @@ $(function() { $n.text().split(/([^a-zA-Z0-9_\\\$:]+)/).forEach(function(v) { var t; - + if ((t = mdref.type(v.replace(/:$/, ""), nn))) { a.push($(t).text(v)); } else if (a.length && a[a.length-1].nodeName === "#text") { @@ -147,6 +147,28 @@ $(function() { walk: function walk(i, e) { // mdref.log("walk", i, e); + switch (e.nodeName) { + case "H1": + case "H2": + case "H3": + case "H4": + case "H5": + case "H6": + if (e.id.length) { + var href = document.location.pathname; + var perm = $("#"); + if (e.nodeName === "H1") { + perm.prependTo(e); + } else { + perm.attr("href", function(i, href) { + return href + e.id; + }); + perm.appendTo(e); + } + } + break; + } + $.each($.makeArray(e.childNodes), function(i, n) { switch (n.nodeName) { case "A": @@ -178,29 +200,34 @@ $(function() { }, hashchange: function hashchange() { if (location.hash.length > 1) { - var hash = location.hash.substring(1); - var name = mdref.is_variable(hash) ? ".var" : ".constant"; - var scrolled = false; + var e; + if ((e = document.getElementById(location.hash.substring(1)))) { + mdref.blink(e); + } else { + var hash = location.hash.substring(1); + var name = mdref.is_variable(hash) ? ".var" : ".constant"; + var scrolled = false; - $(name).each(hash.substring(hash.length-1) === "_" ? function(i, c) { - if (c.textContent.substring(0, hash.length) === hash) { - if (!scrolled) { + $(name).each(hash.substring(hash.length-1) === "_" ? function(i, c) { + if (c.textContent.substring(0, hash.length) === hash) { + if (!scrolled) { + $(window).scrollTop($(c).offset().top - 100); + scrolled = true; + } + mdref.blink(c); + } + } : function(i, c) { + if (c.textContent === hash) { $(window).scrollTop($(c).offset().top - 100); - scrolled = true; + mdref.blink(c); + return false; } - mdref.blink(c); - } - } : function(i, c) { - if (c.textContent === hash) { - $(window).scrollTop($(c).offset().top - 100); - mdref.blink(c); - return false; - } - }); + }); + } } } }; - + $("h1,h2,h3,h4,h5,h6,p,li,code,td").each(mdref.walk); $(window).on("hashchange", mdref.hashchange); mdref.hashchange();