X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=index.js;h=d3326803fedcbd42455f5cebdc2654caf3197a16;hb=d3e33e708a783c634a3f8f5db634a7f03f8520f4;hp=6334108c3888036c669315abd09891b4f0fb512c;hpb=277cfe1f0e09b05e6615ce87603672e0f305520a;p=mdref%2Fmdref diff --git a/index.js b/index.js index 6334108..d332680 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,16 @@ +function is_constant(s) { + return s.length > 1 && s.toUpperCase(s) === s; +} + +function is_variable(s) { + return s.substring(0,1) === "$"; +} + +var is_in_string = false; + function type(s) { - + var i, j, t; + console.log("type", s); // nothing if (!s.match(/[a-zA-Z]/)) { return; @@ -15,6 +26,7 @@ function type(s) { case "array": case "object": case "callable": + case "mixed": return ""; // keywords @@ -29,22 +41,30 @@ function type(s) { case "static": case "final": case "abstract": + case "self": + case "parent": // phrases case "Optional": case "optional": return ""; } - var is_namespace, is_method; - - if ((is_method = (s.indexOf("::") !== -1)) || (is_namespace = (s.indexOf("\\") !== -1))) { - return ""; + // class members + if (-1 !== (i = s.indexOf("::"))) { + t = s.substring(i+2); + if (!is_constant(t) && !is_variable(t)) { + // methods + return ""; + } + } + if (-1 !== (j = s.indexOf("\\"))) { + return ""; } switch (s.toLowerCase()) { // variables default: - if (s.substring(0,1) !== "$") { + if (!is_variable(s)) { break; } // special constants @@ -55,10 +75,11 @@ function type(s) { } // constants - if (s.toUpperCase() === s) { - return ""; + if (is_constant(s)) { + return ""; } } + function node(s) { //console.log("node", s); @@ -73,29 +94,68 @@ function wrap(n) { var $n = $(n) var a = []; - $n.text().split(/([^a-zA-Z_\\\$:]+)/).forEach(function(v) { + $n.text().split(/([^a-zA-Z0-9_\\\$:]+)/).forEach(function(v) { a.push(node(v)); }); $n.replaceWith(a); } function walk(i, e) { - //console.log("walk", i, e); + console.log("walk", i, e); - e && $.each(e.childNodes, function(i, n) { - //console.log(n.nodeName); + $.each($.makeArray(e.childNodes), function(i, n) { switch (n.nodeName) { case "A": + case "BR": + case "HR": break; case "#text": wrap(n); break; default: - walk(n); + walk(-1, n); + break; } }); } -$(document).ready(function() { - //console.log("ready"); +function blink(c) { + var $c = $(c); + + $c.fadeOut("slow").queue(function(next) { + this.style.color = "red"; + next(); + }).fadeIn("fast").fadeOut("fast").queue(function(next) { + this.style.color = ""; + next(); + }).fadeIn("slow"); +} + +function hashchange() { + if (location.hash.length > 1) { + var hash = location.hash.substring(1); + var name = 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) { + $(window).scrollTop($(c).offset().top - 100); + scrolled = true; + } + blink(c); + } + } : function(i, c) { + if (c.textContent === hash) { + $(window).scrollTop($(c).offset().top - 100); + blink(c); + return false; + } + }); + } +} + +$(function() { $("h1,h2,h3,h4,h5,h6,p,li,code").each(walk); + $(window).on("hashchange", hashchange); + hashchange(); });