markup-validator commit: Add onclick handler to badge sample code to avoid uri=referer redirects.

changeset:   3235:dfa0fd19825f
tag:         tip
user:        Ville Skyttä <ville.skytta@iki.fi>
date:        Sat May 21 11:52:05 2011 +0300
files:       htdocs/config/types.conf htdocs/dev/tests/html40-strict.html httpd/cgi-bin/check share/templates/en_US/ucn_output.tmpl share/templates/en_US/valid.tmpl
description:
Add onclick handler to badge sample code to avoid uri=referer redirects.

In addition to avoiding the redirect, this removes the need for
presence of the Referer header in JavaScript enabled browsers thus
making things work in setups that don't send the referer at all, and
when the badge is in https docs and the validator isn't.


diff -r 754ab36d4cf6 -r dfa0fd19825f htdocs/config/types.conf
--- a/htdocs/config/types.conf	Sat May 21 11:05:49 2011 +0300
+++ b/htdocs/config/types.conf	Sat May 21 11:52:05 2011 +0300
@@ -152,6 +152,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid HTML 4.0 Strict
+    OnClick   = onclick
   </Badge>
 </HTML_4_0_Strict>
 
@@ -174,6 +175,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid HTML 4.0 Transitional
+    OnClick   = onclick
   </Badge>
 </HTML_4_0_Transitional>
 
@@ -196,6 +198,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid HTML 4.0 Frameset
+    OnClick   = onclick
   </Badge>
 </HTML_4_0_Frameset>
 
@@ -218,6 +221,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid HTML 4.01 Strict
+    OnClick   = onclick
   </Badge>
 </HTML_4_01_Strict>
 
@@ -240,6 +244,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid HTML 4.01 Transitional
+    OnClick   = onclick
   </Badge>
 </HTML_4_01_Transitional>
 
@@ -262,6 +267,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid HTML 4.01 Frameset
+    OnClick   = onclick
   </Badge>
 </HTML_4_01_Frameset>
 
@@ -284,6 +290,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid HTML 4.01 + RDFa 1.1
+    OnClick   = onclick
   </Badge>
 </HTML_4_01_RDFa_1_1>
 
@@ -322,6 +329,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid XHTML 1.0 Strict
+    OnClick   = onclick
   </Badge>
 </XHTML_1_0_Strict>
 
@@ -347,6 +355,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid XHTML 1.0 Transitional
+    OnClick   = onclick
   </Badge>
 </XHTML_1_0_Transitional>
 
@@ -372,6 +381,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid XHTML 1.0 Frameset
+    OnClick   = onclick
   </Badge>
 </XHTML_1_0_Frameset>
 
@@ -515,6 +525,7 @@
     Height    = 31
     Width     = 88
     Alt       = Valid XHTML 1.1
+    OnClick   = onclick
   </Badge>
 </XHTML_1_1>
 
@@ -663,6 +674,7 @@
     Width     = 88
     Alt       = Valid XHTML + RDFa
     RDFa      = http://www.w3.org/TR/rdfa-syntax
+    OnClick   = onclick
   </Badge>
 </XHTML_RDFa>
 
diff -r 754ab36d4cf6 -r dfa0fd19825f htdocs/dev/tests/html40-strict.html
--- a/htdocs/dev/tests/html40-strict.html	Sat May 21 11:05:49 2011 +0300
+++ b/htdocs/dev/tests/html40-strict.html	Sat May 21 11:52:05 2011 +0300
@@ -19,7 +19,7 @@
 <hr>
 
 <address>
-  <a href="http://validator.w3.org/check?uri=referer">valid HTML</a><br>
+  <a href="http://validator.w3.org/check?uri=referer" onclick="this.href=this.href.replace(/referer$/,encodeURIComponent(document.URL))">valid HTML</a><br>
   <a href="../../feedback.html">Gerald Oskoboiny</A>
 </address>
 
diff -r 754ab36d4cf6 -r dfa0fd19825f httpd/cgi-bin/check
--- a/httpd/cgi-bin/check	Sat May 21 11:05:49 2011 +0300
+++ b/httpd/cgi-bin/check	Sat May 21 11:52:05 2011 +0300
@@ -1695,6 +1695,7 @@
             $T->param(badge_rdfa          => $cfg->{Badge}->{RDFa});
             $T->param(badge_h             => $cfg->{Badge}->{Height});
             $T->param(badge_w             => $cfg->{Badge}->{Width});
+            $T->param(badge_onclick       => $cfg->{Badge}->{OnClick});
             $T->param(badge_tagc => $cfg->{'Parse Mode'} eq 'XML' ? ' /' : '');
         }
     }
diff -r 754ab36d4cf6 -r dfa0fd19825f share/templates/en_US/ucn_output.tmpl
--- a/share/templates/en_US/ucn_output.tmpl	Sat May 21 11:05:49 2011 +0300
+++ b/share/templates/en_US/ucn_output.tmpl	Sat May 21 11:52:05 2011 +0300
@@ -64,10 +64,9 @@
 <pre><code>&lt;p<TMPL_IF NAME="badge_rdfa"> about="" 
 	resource="<TMPL_VAR NAME="badge_rdfa">" 
 	rel="dc:conformsTo" xmlns:dc="http://purl.org/dc/terms/"</TMPL_IF>&gt;
-	&lt;a href="<TMPL_VAR NAME="env_home_page" ESCAPE="HTML">check?uri=referer"&gt;
-		&lt;img src="<TMPL_VAR NAME="badge_uri" ESCAPE="HTML">"
-			<TMPL_IF NAME="badge_alt">alt="<TMPL_VAR NAME="badge_alt" ESCAPE="HTML">"</TMPL_IF>
-			style="<TMPL_IF NAME="badge_h">height: <TMPL_VAR NAME="badge_h">px;</TMPL_IF> <TMPL_IF NAME="badge_w">width: <TMPL_VAR NAME="badge_w">px;</TMPL_IF> border:0"<TMPL_VAR NAME="badge_tagc">&gt;
+	&lt;a href="<TMPL_VAR NAME="env_home_page" ESCAPE="HTML">check?uri=referer"<TMPL_IF NAME="badge_onclick">
+		<TMPL_VAR NAME="badge_onclick">="this.href=this.href.replace(/referer$/,encodeURIComponent(document.URL))"</TMPL_IF>&gt;&lt;img
+		src="<TMPL_VAR NAME="badge_uri" ESCAPE="HTML">"<TMPL_IF NAME="badge_alt"> alt="<TMPL_VAR NAME="badge_alt" ESCAPE="HTML">"</TMPL_IF> style="border: 0<TMPL_IF NAME="badge_h">; height: <TMPL_VAR NAME="badge_h">px</TMPL_IF><TMPL_IF NAME="badge_w">; width: <TMPL_VAR NAME="badge_w">px</TMPL_IF>"<TMPL_VAR NAME="badge_tagc">&gt;
 	&lt;/a&gt;
 &lt;/p&gt;</code></pre>
 
@@ -80,10 +79,9 @@
 <pre><code>&lt;p<TMPL_IF NAME="badge_rdfa"> about="" 
 	resource="<TMPL_VAR NAME="badge_rdfa">" 
 	rel="dc:conformsTo" xmlns:dc="http://purl.org/dc/terms/"</TMPL_IF>&gt;
-	&lt;a href="<TMPL_VAR NAME="env_home_page" ESCAPE="HTML">check?uri=referer"&gt;
-		&lt;img src="<TMPL_VAR NAME="badge_alt_uri" ESCAPE="HTML">"
-			<TMPL_IF NAME="badge_alt">alt="<TMPL_VAR NAME="badge_alt" ESCAPE="HTML">"</TMPL_IF>
-			style="<TMPL_IF NAME="badge_h">height: <TMPL_VAR NAME="badge_h">px;</TMPL_IF> <TMPL_IF NAME="badge_w">width: <TMPL_VAR NAME="badge_w">px;</TMPL_IF> border:0"<TMPL_VAR NAME="badge_tagc">&gt;
+	&lt;a href="<TMPL_VAR NAME="env_home_page" ESCAPE="HTML">check?uri=referer"<TMPL_IF NAME="badge_onclick">
+		<TMPL_VAR NAME="badge_onclick">="this.href=this.href.replace(/referer$/,encodeURIComponent(document.URL))"</TMPL_IF>&gt;&lt;img
+		src="<TMPL_VAR NAME="badge_alt_uri" ESCAPE="HTML">"<TMPL_IF NAME="badge_alt"> alt="<TMPL_VAR NAME="badge_alt" ESCAPE="HTML">"</TMPL_IF> style="border: 0<TMPL_IF NAME="badge_h">; height: <TMPL_VAR NAME="badge_h">px</TMPL_IF><TMPL_IF NAME="badge_w">; width: <TMPL_VAR NAME="badge_w">px</TMPL_IF>"<TMPL_VAR NAME="badge_tagc">&gt;
 	&lt;/a&gt;
 &lt;/p&gt;</code></pre>
 
diff -r 754ab36d4cf6 -r dfa0fd19825f share/templates/en_US/valid.tmpl
--- a/share/templates/en_US/valid.tmpl	Sat May 21 11:05:49 2011 +0300
+++ b/share/templates/en_US/valid.tmpl	Sat May 21 11:52:05 2011 +0300
@@ -74,9 +74,9 @@
   &lt;p<TMPL_IF NAME="badge_rdfa"> about=""
      resource="<TMPL_VAR NAME="badge_rdfa">"
      rel="dc:conformsTo" xmlns:dc="http://purl.org/dc/terms/"</TMPL_IF>&gt;
-    &lt;a href="<TMPL_VAR NAME="env_home_page" ESCAPE="HTML">check?uri=referer"&gt;&lt;img
-        src="<TMPL_VAR NAME="badge_uri" ESCAPE="HTML">"
-        <TMPL_IF NAME="badge_alt">alt="<TMPL_VAR NAME="badge_alt" ESCAPE="HTML">"</TMPL_IF> <TMPL_IF NAME="badge_h">height="<TMPL_VAR NAME="badge_h">"</TMPL_IF> <TMPL_IF NAME="badge_w">width="<TMPL_VAR NAME="badge_w">"</TMPL_IF><TMPL_VAR NAME="badge_tagc">&gt;&lt;/a&gt;
+    &lt;a href="<TMPL_VAR NAME="env_home_page" ESCAPE="HTML">check?uri=referer"<TMPL_IF NAME="badge_onclick">
+      <TMPL_VAR NAME="badge_onclick">="this.href=this.href.replace(/referer$/,encodeURIComponent(document.URL))"</TMPL_IF>&gt;&lt;img
+      src="<TMPL_VAR NAME="badge_uri" ESCAPE="HTML">"<TMPL_IF NAME="badge_alt"> alt="<TMPL_VAR NAME="badge_alt" ESCAPE="HTML">"</TMPL_IF><TMPL_IF NAME="badge_h"> height="<TMPL_VAR NAME="badge_h">"</TMPL_IF><TMPL_IF NAME="badge_w"> width="<TMPL_VAR NAME="badge_w">"</TMPL_IF><TMPL_VAR NAME="badge_tagc">&gt;&lt;/a&gt;
   &lt;/p&gt;
   </pre>
   <TMPL_IF NAME="badge_alt_uri">
@@ -89,9 +89,9 @@
   &lt;p<TMPL_IF NAME="badge_rdfa"> about=""
      resource="<TMPL_VAR NAME="badge_rdfa">"
      rel="dc:conformsTo" xmlns:dc="http://purl.org/dc/terms/"</TMPL_IF>&gt;
-    &lt;a href="<TMPL_VAR NAME="env_home_page" ESCAPE="HTML">check?uri=referer"&gt;&lt;img
-        src="<TMPL_VAR NAME="badge_alt_uri" ESCAPE="HTML">"
-        <TMPL_IF NAME="badge_alt">alt="<TMPL_VAR NAME="badge_alt" ESCAPE="HTML">"</TMPL_IF> <TMPL_IF NAME="badge_h">height="<TMPL_VAR NAME="badge_h">"</TMPL_IF> <TMPL_IF NAME="badge_w">width="<TMPL_VAR NAME="badge_w">"</TMPL_IF><TMPL_VAR NAME="badge_tagc">&gt;&lt;/a&gt;
+    &lt;a href="<TMPL_VAR NAME="env_home_page" ESCAPE="HTML">check?uri=referer"<TMPL_IF NAME="badge_onclick">
+      <TMPL_VAR NAME="badge_onclick">="this.href=this.href.replace(/referer$/,encodeURIComponent(document.URL))"</TMPL_IF><&gt;&lt;img
+      src="<TMPL_VAR NAME="badge_alt_uri" ESCAPE="HTML">"<TMPL_IF NAME="badge_alt"> alt="<TMPL_VAR NAME="badge_alt" ESCAPE="HTML">"</TMPL_IF><TMPL_IF NAME="badge_h"> height="<TMPL_VAR NAME="badge_h">"</TMPL_IF><TMPL_IF NAME="badge_w"> width="<TMPL_VAR NAME="badge_w">"</TMPL_IF><TMPL_VAR NAME="badge_tagc">&gt;&lt;/a&gt;
   &lt;/p&gt;
   </pre>
   </TMPL_IF>

Received on Saturday, 21 May 2011 08:52:21 UTC