* [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links
@ 2013-04-08 20:09 Jürgen Kreileder
2013-04-09 15:16 ` Jakub Narębski
0 siblings, 1 reply; 4+ messages in thread
From: Jürgen Kreileder @ 2013-04-08 20:09 UTC (permalink / raw)
To: git
Don't add js parameters to links outside of gitweb itself.
Signed-off-by: Jürgen Kreileder <jk@blackdown.de>
---
gitweb/gitweb.perl | 2 +-
gitweb/static/js/javascript-detection.js | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1309196..f0912d7 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -4165,7 +4165,7 @@ sub git_footer_html {
print qq!<script type="text/javascript">\n!.
qq!window.onload = function () {\n!;
if (gitweb_check_feature('javascript-actions')) {
- print qq! fixLinks();\n!;
+ print qq! fixLinks('$my_url');\n!;
}
if ($jstimezone && $tz_cookie && $datetime_class) {
print qq! var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
diff --git a/gitweb/static/js/javascript-detection.js b/gitweb/static/js/javascript-detection.js
index fa2596f..36964ad 100644
--- a/gitweb/static/js/javascript-detection.js
+++ b/gitweb/static/js/javascript-detection.js
@@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
*
* @globals jsExceptionsRe
*/
-function fixLinks() {
+function fixLinks(baseurl) {
var allLinks = document.getElementsByTagName("a") || document.links;
for (var i = 0, len = allLinks.length; i < len; i++) {
var link = allLinks[i];
- if (!jsExceptionsRe.test(link)) {
+ if (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {
link.href = link.href.replace(/(#|$)/,
(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links
2013-04-08 20:09 [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links Jürgen Kreileder
@ 2013-04-09 15:16 ` Jakub Narębski
2013-04-09 17:54 ` Jürgen Kreileder
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Narębski @ 2013-04-09 15:16 UTC (permalink / raw)
To: Jürgen Kreileder; +Cc: git
Jürgen Kreileder wrote:
> Don't add js parameters to links outside of gitweb itself.
Hmmm... this limits adding ';js=(0|1)' to only links which begin with
$my_url, i.e. absolute links beginning with gitweb's base URL.
Wouldn't that mean that most internal gitweb-generated links wouldn't
get ';js=(0|1)'? href(..., -full => 1) is not the default...
> Signed-off-by: Jürgen Kreileder <jk@blackdown.de>
> ---
> gitweb/gitweb.perl | 2 +-
> gitweb/static/js/javascript-detection.js | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 1309196..f0912d7 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -4165,7 +4165,7 @@ sub git_footer_html {
> print qq!<script type="text/javascript">\n!.
> qq!window.onload = function () {\n!;
> if (gitweb_check_feature('javascript-actions')) {
> - print qq! fixLinks();\n!;
> + print qq! fixLinks('$my_url');\n!;
> }
> if ($jstimezone && $tz_cookie && $datetime_class) {
> print qq! var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
> diff --git a/gitweb/static/js/javascript-detection.js b/gitweb/static/js/javascript-detection.js
> index fa2596f..36964ad 100644
> --- a/gitweb/static/js/javascript-detection.js
> +++ b/gitweb/static/js/javascript-detection.js
> @@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
> *
> * @globals jsExceptionsRe
> */
> -function fixLinks() {
> +function fixLinks(baseurl) {
> var allLinks = document.getElementsByTagName("a") || document.links;
> for (var i = 0, len = allLinks.length; i < len; i++) {
> var link = allLinks[i];
> - if (!jsExceptionsRe.test(link)) {
> + if (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {
> link.href = link.href.replace(/(#|$)/,
> (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
> }
>
--
Jakub Narębski
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links
2013-04-09 15:16 ` Jakub Narębski
@ 2013-04-09 17:54 ` Jürgen Kreileder
2013-04-09 17:59 ` Jakub Narębski
0 siblings, 1 reply; 4+ messages in thread
From: Jürgen Kreileder @ 2013-04-09 17:54 UTC (permalink / raw)
To: Jakub Narębski; +Cc: git
Jakub Narębski <jnareb@gmail.com> writes:
> Jürgen Kreileder wrote:
>
>> Don't add js parameters to links outside of gitweb itself.
>
> Hmmm... this limits adding ';js=(0|1)' to only links which begin with
> $my_url, i.e. absolute links beginning with gitweb's base URL.
>
> Wouldn't that mean that most internal gitweb-generated links wouldn't
> get ';js=(0|1)'? href(..., -full => 1) is not the default...
No, link.href is always absolute in JavaScript - even if the emitted URL
was relative.
Old: https://git.blackdown.de/old.cgi?p=contactalbum.git;a=summary;js=1
New: https://git.blackdown.de/?p=contactalbum.git;a=summary;js=1
With the old version the external links in the description got ';js=1'
appended. With the new version, ';js=1' isn't on those links.
Other links are the same in both versions.
>> Signed-off-by: Jürgen Kreileder <jk@blackdown.de>
>> ---
>> gitweb/gitweb.perl | 2 +-
>> gitweb/static/js/javascript-detection.js | 4 ++--
>> 2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
>> index 1309196..f0912d7 100755
>> --- a/gitweb/gitweb.perl
>> +++ b/gitweb/gitweb.perl
>> @@ -4165,7 +4165,7 @@ sub git_footer_html {
>> print qq!<script type="text/javascript">\n!.
>> qq!window.onload = function () {\n!;
>> if (gitweb_check_feature('javascript-actions')) {
>> - print qq! fixLinks();\n!;
>> + print qq! fixLinks('$my_url');\n!;
>> }
>> if ($jstimezone && $tz_cookie && $datetime_class) {
>> print qq! var tz_cookie = { name: '$tz_cookie', expires: 14, path: '/' };\n!. # in days
>> diff --git a/gitweb/static/js/javascript-detection.js b/gitweb/static/js/javascript-detection.js
>> index fa2596f..36964ad 100644
>> --- a/gitweb/static/js/javascript-detection.js
>> +++ b/gitweb/static/js/javascript-detection.js
>> @@ -29,11 +29,11 @@ var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
>> *
>> * @globals jsExceptionsRe
>> */
>> -function fixLinks() {
>> +function fixLinks(baseurl) {
>> var allLinks = document.getElementsByTagName("a") || document.links;
>> for (var i = 0, len = allLinks.length; i < len; i++) {
>> var link = allLinks[i];
>> - if (!jsExceptionsRe.test(link)) {
>> + if (!jsExceptionsRe.test(link) && !link.href.indexOf(baseurl)) {
>> link.href = link.href.replace(/(#|$)/,
>> (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
>> }
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links
2013-04-09 17:54 ` Jürgen Kreileder
@ 2013-04-09 17:59 ` Jakub Narębski
0 siblings, 0 replies; 4+ messages in thread
From: Jakub Narębski @ 2013-04-09 17:59 UTC (permalink / raw)
To: Jürgen Kreileder; +Cc: git
W dniu 09.04.2013 19:54, Jürgen Kreileder napisał:
> Jakub Narębski <jnareb@gmail.com> writes:
>
>> Jürgen Kreileder wrote:
>>
>>> Don't add js parameters to links outside of gitweb itself.
>>
>> Hmmm... this limits adding ';js=(0|1)' to only links which begin with
>> $my_url, i.e. absolute links beginning with gitweb's base URL.
>>
>> Wouldn't that mean that most internal gitweb-generated links wouldn't
>> get ';js=(0|1)'? href(..., -full => 1) is not the default...
>
> No, link.href is always absolute in JavaScript - even if the emitted URL
> was relative.
Thanks, I didn't know that.
So, with that explanation:
Acked-by: Jakub Narebski <jnareb@gmail.com>
> Old: https://git.blackdown.de/old.cgi?p=contactalbum.git;a=summary;js=1
> New: https://git.blackdown.de/?p=contactalbum.git;a=summary;js=1
>
> With the old version the external links in the description got ';js=1'
> appended. With the new version, ';js=1' isn't on those links.
> Other links are the same in both versions.
Thanks. This is a nice solution for a problem which I didn't know
how to solve (I was thinking about using <a class="internal" ...>,
but your solution is better).
--
Jakub Narębski
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-04-09 17:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-08 20:09 [PATCH 3/4] gitweb: Don't append ';js=(0|1)' to external links Jürgen Kreileder
2013-04-09 15:16 ` Jakub Narębski
2013-04-09 17:54 ` Jürgen Kreileder
2013-04-09 17:59 ` Jakub Narębski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).