Submitter | Alexander Plavin |
---|---|
Date | June 29, 2013, 2:06 p.m. |
Message ID | <cc47e0b1bf3ecf020a1f.1372514816@debian-alexander.dolgopa> |
Download | mbox | patch |
Permalink | /patch/1764/ |
State | Superseded, archived |
Headers | show |
Comments
Op 29-6-2013 16:06, Alexander Plavin schreef: > # HG changeset patch > # User Alexander Plavin <me@aplavin.ru> > # Date 1372180347 -14400 > # Tue Jun 25 21:12:27 2013 +0400 > # Node ID cc47e0b1bf3ecf020a1f84753694502ef4b9b603 > # Parent 397045d4f1bed3b95c4c42d410edd762d20abd3f > hgweb: click on line number in file source view gives link to it > > As the source lines are shown as HTML list, a bit of JavaScript code > is required to process clicks on the numbers. > > diff -r 397045d4f1be -r cc47e0b1bf3e mercurial/templates/paper/footer.tmpl > --- a/mercurial/templates/paper/footer.tmpl Tue Jun 25 21:10:21 2013 +0400 > +++ b/mercurial/templates/paper/footer.tmpl Tue Jun 25 21:12:27 2013 +0400 > @@ -1,4 +1,7 @@ > -<script type="text/javascript">process_dates()</script> > +<script type="text/javascript"> > +process_dates(); > +addOnclickSource(); > +</script> > {motd} > > </body> > diff -r 397045d4f1be -r cc47e0b1bf3e mercurial/templates/static/mercurial.js > --- a/mercurial/templates/static/mercurial.js Tue Jun 25 21:10:21 2013 +0400 > +++ b/mercurial/templates/static/mercurial.js Tue Jun 25 21:12:27 2013 +0400 > @@ -3,6 +3,7 @@ > // Rendering of branch DAGs on the client side > // Display of elapsed time > // Show or hide diffstat > +// Link to a line when clicking on it > // > // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl> > // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de> > @@ -274,3 +275,28 @@ > document.getElementById('diffstatdetails').style.display = 'none'; > document.getElementById('diffstatexpand').style.display = 'inline'; > } > + > + > +function addOnclickSource() { > + var nodes = document.querySelectorAll('ol.sourcelines'); > + > + clickHandler = function (event) { Missing a ‘var’ here, without it will be global. Personally I think it looks nicer to write: function clickHandler() {} (It will be locally scoped still.) > + var id; > + if (event.offsetX < 0) { > + // WebKit, Presto > + id = event.target.parentNode.id; > + } > + if (event.target.tagName == 'LI') { > + // Gecko, Presto > + id = event.target.id; > + } > + > + if (id) { > + window.location.hash = '#' + id; > + } > + }; > + > + for (i = 0; i < nodes.length; i++) { > + nodes[i].onclick = clickHandler; > + } > +} > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@selenic.com > http://selenic.com/mailman/listinfo/mercurial-devel >
I fully agree with you here, will change this way. 2013/6/29 Laurens Holst <laurens.nospam@grauw.nl>: > Op 29-6-2013 16:06, Alexander Plavin schreef: > >> # HG changeset patch >> # User Alexander Plavin <me@aplavin.ru> >> # Date 1372180347 -14400 >> # Tue Jun 25 21:12:27 2013 +0400 >> # Node ID cc47e0b1bf3ecf020a1f84753694502ef4b9b603 >> # Parent 397045d4f1bed3b95c4c42d410edd762d20abd3f >> hgweb: click on line number in file source view gives link to it >> >> As the source lines are shown as HTML list, a bit of JavaScript code >> is required to process clicks on the numbers. >> >> diff -r 397045d4f1be -r cc47e0b1bf3e mercurial/templates/paper/footer.tmpl >> --- a/mercurial/templates/paper/footer.tmpl Tue Jun 25 21:10:21 2013 >> +0400 >> +++ b/mercurial/templates/paper/footer.tmpl Tue Jun 25 21:12:27 2013 >> +0400 >> @@ -1,4 +1,7 @@ >> -<script type="text/javascript">process_dates()</script> >> +<script type="text/javascript"> >> +process_dates(); >> +addOnclickSource(); >> +</script> >> {motd} >> </body> >> diff -r 397045d4f1be -r cc47e0b1bf3e >> mercurial/templates/static/mercurial.js >> --- a/mercurial/templates/static/mercurial.js Tue Jun 25 21:10:21 2013 >> +0400 >> +++ b/mercurial/templates/static/mercurial.js Tue Jun 25 21:12:27 2013 >> +0400 >> @@ -3,6 +3,7 @@ >> // Rendering of branch DAGs on the client side >> // Display of elapsed time >> // Show or hide diffstat >> +// Link to a line when clicking on it >> // >> // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl> >> // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de> >> @@ -274,3 +275,28 @@ >> document.getElementById('diffstatdetails').style.display = 'none'; >> document.getElementById('diffstatexpand').style.display = >> 'inline'; >> } >> + >> + >> +function addOnclickSource() { >> + var nodes = document.querySelectorAll('ol.sourcelines'); >> + >> + clickHandler = function (event) { > > > Missing a ‘var’ here, without it will be global. > > Personally I think it looks nicer to write: > > function clickHandler() {} > > (It will be locally scoped still.) > >> + var id; >> + if (event.offsetX < 0) { >> + // WebKit, Presto >> + id = event.target.parentNode.id; >> + } >> + if (event.target.tagName == 'LI') { >> + // Gecko, Presto >> + id = event.target.id; >> + } >> + >> + if (id) { >> + window.location.hash = '#' + id; >> + } >> + }; >> + >> + for (i = 0; i < nodes.length; i++) { >> + nodes[i].onclick = clickHandler; >> + } >> +} >> _______________________________________________ >> Mercurial-devel mailing list >> Mercurial-devel@selenic.com >> http://selenic.com/mailman/listinfo/mercurial-devel >> >
Patch
diff -r 397045d4f1be -r cc47e0b1bf3e mercurial/templates/paper/footer.tmpl --- a/mercurial/templates/paper/footer.tmpl Tue Jun 25 21:10:21 2013 +0400 +++ b/mercurial/templates/paper/footer.tmpl Tue Jun 25 21:12:27 2013 +0400 @@ -1,4 +1,7 @@ -<script type="text/javascript">process_dates()</script> +<script type="text/javascript"> +process_dates(); +addOnclickSource(); +</script> {motd} </body> diff -r 397045d4f1be -r cc47e0b1bf3e mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js Tue Jun 25 21:10:21 2013 +0400 +++ b/mercurial/templates/static/mercurial.js Tue Jun 25 21:12:27 2013 +0400 @@ -3,6 +3,7 @@ // Rendering of branch DAGs on the client side // Display of elapsed time // Show or hide diffstat +// Link to a line when clicking on it // // Copyright 2008 Dirkjan Ochtman <dirkjan AT ochtman DOT nl> // Copyright 2006 Alexander Schremmer <alex AT alexanderweb DOT de> @@ -274,3 +275,28 @@ document.getElementById('diffstatdetails').style.display = 'none'; document.getElementById('diffstatexpand').style.display = 'inline'; } + + +function addOnclickSource() { + var nodes = document.querySelectorAll('ol.sourcelines'); + + clickHandler = function (event) { + var id; + if (event.offsetX < 0) { + // WebKit, Presto + id = event.target.parentNode.id; + } + if (event.target.tagName == 'LI') { + // Gecko, Presto + id = event.target.id; + } + + if (id) { + window.location.hash = '#' + id; + } + }; + + for (i = 0; i < nodes.length; i++) { + nodes[i].onclick = clickHandler; + } +}