[PATCH 1 of 3] hgweb: use a function expression for the install listener of followlines UI
Denis Laxalde
denis at laxalde.org
Mon Apr 3 08:33:51 UTC 2017
# 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
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);
More information about the Mercurial-devel
mailing list