[PATCH 1 of 3] hgweb: use a function expression for the install listener of followlines UI

Gregory Szorc gregory.szorc at gmail.com
Mon Apr 3 11:50:29 EDT 2017


On Mon, Apr 3, 2017 at 1:33 AM, Denis Laxalde <denis at laxalde.org> wrote:

> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1491205225 -7200
> #      Mon Apr 03 09:40:25 2017 +0200
> # Node ID 0ac235a0ef4f08d227d96de458a91cbaff46dc92
> # Parent  04ec317b81280c189fcea33a05c8cbbac3c186b1
> # Available At http://hg.logilab.org/users/dlaxalde/hg
> #              hg pull http://hg.logilab.org/users/dlaxalde/hg -r
> 0ac235a0ef4f
> hgweb: use a function expression for the install listener of followlines UI
>

This series LGTM. It could potentially be folded into the changeset that
introduced all this code (if it hasn't been published yet). That would save
us from the extra linerangelog.js in published history.


>
> We define the listener of document's "DOMContentLoaded" inline in
> registration
> and use a function expression (anonymous) with everything inside. This
> makes
> it clearer that this file is not a library of JavaScript functions but
> rather
> an executable script.
>
> (Most of changes consists of reindenting the "followlinesBox" function, so
> mostly white space changes.)
>
> diff --git a/mercurial/templates/static/linerangelog.js
> b/mercurial/templates/static/linerangelog.js
> --- a/mercurial/templates/static/linerangelog.js
> +++ b/mercurial/templates/static/linerangelog.js
> @@ -6,7 +6,7 @@
>  // GNU General Public License version 2 or any later version.
>
>  //** Install event listeners for line block selection and followlines
> action */
> -function installLineSelect() {
> +document.addEventListener('DOMContentLoaded', function() {
>      var sourcelines = document.getElementsByClassName('sourcelines')[0];
>      if (typeof sourcelines === 'undefined') {
>          return;
> @@ -127,37 +127,35 @@ function installLineSelect() {
>
>      sourcelines.addEventListener('click', lineSelectStart);
>
> -}
> +    //** return a <div id="followlines"> and inner cancel <button>
> elements */
> +    function followlinesBox(targetUri, fromline, toline) {
> +        // <div id="followlines">
> +        var div = document.createElement('div');
> +        div.id = 'followlines';
>
> -//** return a <div id="followlines"> and inner cancel <button> elements */
> -function followlinesBox(targetUri, fromline, toline) {
> -    // <div id="followlines">
> -    var div = document.createElement('div');
> -    div.id = 'followlines';
> +        //   <div class="followlines-cancel">
> +        var buttonDiv = document.createElement('div');
> +        buttonDiv.classList.add('followlines-cancel');
>
> -    //   <div class="followlines-cancel">
> -    var buttonDiv = document.createElement('div');
> -    buttonDiv.classList.add('followlines-cancel');
> +        //     <button>x</button>
> +        var button = document.createElement('button');
> +        button.textContent = 'x';
> +        buttonDiv.appendChild(button);
> +        div.appendChild(buttonDiv);
>
> -    //     <button>x</button>
> -    var button = document.createElement('button');
> -    button.textContent = 'x';
> -    buttonDiv.appendChild(button);
> -    div.appendChild(buttonDiv);
> -
> -    //   <div class="followlines-link">
> -    var aDiv = document.createElement('div');
> -    aDiv.classList.add('followlines-link');
> +        //   <div class="followlines-link">
> +        var aDiv = document.createElement('div');
> +        aDiv.classList.add('followlines-link');
>
> -    //     <a href="/log/<rev>/<file>?patch=&linerange=...">
> -    var a = document.createElement('a');
> -    var url = targetUri + '?patch=&linerange=' + fromline + ':' + toline;
> -    a.setAttribute('href', url);
> -    a.textContent = 'follow lines ' + fromline + ':' + toline;
> -    aDiv.appendChild(a);
> -    div.appendChild(aDiv);
> +        //     <a href="/log/<rev>/<file>?patch=&linerange=...">
> +        var a = document.createElement('a');
> +        var url = targetUri + '?patch=&linerange=' + fromline + ':' +
> toline;
> +        a.setAttribute('href', url);
> +        a.textContent = 'follow lines ' + fromline + ':' + toline;
> +        aDiv.appendChild(a);
> +        div.appendChild(aDiv);
>
> -    return [div, button];
> -}
> +        return [div, button];
> +    }
>
> -document.addEventListener('DOMContentLoaded', installLineSelect, false);
> +}, false);
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170403/07eca6fe/attachment.html>


More information about the Mercurial-devel mailing list