[PATCH 3 of 5 V2] hgweb: highlight the line which is linked at

Laurens Holst laurens.nospam at grauw.nl
Sat Jun 1 07:04:29 CDT 2013


Op 5/31/13 12:51 PM, Alexander Plavin schreef:
> +function addOnclickSource() {
> +    nodes = document.querySelectorAll('li.source');
> +    for (i = 0; i < nodes.length; i++) {
> +        nodes[i].onclick = function (event) {
> +            if (event.offsetX < 0 || event.target.tagName == 'LI') {
> +                window.location.hash = '#' + this.id;
> +            }
> +        };
> +    }
> +}

It would be faster to just add the listener on the <ul> element, and use 
event.target.id instead of this.id.

You should avoid iterating over all source line, this could cause 
noticeable problems (unresponsive browser) for long source files. I 
think there was a similar issue in the past with process_dates().

~Laurens


More information about the Mercurial-devel mailing list