]>
git.wh0rd.org - tt-rss.git/blob - xsl_mop-up.js
1 // -*-coding: latin-1;-*-
2 // Time-stamp: "2006-05-17 22:06:46 ADT" sburke@cpan.org
4 // A workaround for XSL-to-XHTML systems that don't
5 // implement XSL 'disable-output-escaping="yes"'.
7 // sburke@cpan.org, Sean M. Burke.
8 // - I hereby release this JavaScript code into the public domain.
13 function complaining (s
) { alert(s
); return new Error(s
,s
); }
15 if(!( document
.getElementById
&& document
.getElementsByName
))
16 throw complaining("Your browser is too old to render this page properly."
17 + " Consider going to getfirefox.com to upgrade.");
19 function check_decoding () {
20 var d
= document
.getElementById('cometestme');
22 throw complaining("Can't find an id='cometestme' element?");
23 } else if(!('textContent' in d
)) {
24 // It's a browser with a halfassed DOM implementation (like IE6)
25 // that doesn't implement textContent! Assume that if it's that
26 // dumb, it probably doesn't implement disable-content-encoding.
29 var ampy
= d
.textContent
;
30 if(DEBUG
> 1) { alert("Got " + ampy
); }
32 if(ampy
== undefined) throw complaining("'cometestme' element has undefined text content?!");
33 if(ampy
== '' ) throw complaining("'cometestme' element has empty text content?!" );
35 if (ampy
== "\x26" ) { is_decoding
= true; }
36 else if (ampy
== "\x26amp;" ) { is_decoding
= false; }
37 else { throw complaining('Insane value: "' + ampy
+ '"!'); }
41 (is_decoding
== undefined) ? "I can't tell whether the XSL processor supports disable-content-encoding!D"
42 : is_decoding
? "The XSL processor DOES support disable-content-encoding"
43 : "The XSL processor does NOT support disable-content-encoding"
50 function go_decoding () {
54 DEBUG
&& alert("No work needs doing -- already decoded!");
58 var to_decode
= document
.getElementsByName('decodeme');
59 if(!( to_decode
&& to_decode
.length
)) {
60 DEBUG
&& alert("No work needs doing -- no elements to decode!");
64 if(!( ( "innerHTML" in to_decode
[0]) && ( "textContent" in to_decode
[0]) ))
65 throw complaining( "Your JavaScript version doesn't implement DOM " +
66 "properly enough to show this page correctly. " +
67 "Consider going to getfirefox.com to upgrade.");
70 for(var i
= to_decode
.length
- 1; i
>= 0; i
--) {
71 s
= to_decode
[i
].textContent
;
75 (s
.indexOf('&') == -1 && s
.indexOf('<') == -1)
77 // the null or markupless element needs no reworking
79 to_decode
[i
].innerHTML
= s
; // that's the magic