| 1 |
// -*-coding: latin-1;-*-
|
| 2 |
// Time-stamp: "2006-05-17 22:06:46 ADT" sburke@cpan.org
|
| 3 |
|
| 4 |
// A workaround for XSL-to-XHTML systems that don't
|
| 5 |
// implement XSL 'disable-output-escaping="yes"'.
|
| 6 |
//
|
| 7 |
// sburke@cpan.org, Sean M. Burke.
|
| 8 |
// - I hereby release this JavaScript code into the public domain.
|
| 9 |
|
| 10 |
var is_decoding;
|
| 11 |
var DEBUG = 0;
|
| 12 |
|
| 13 |
function complaining (s) { alert(s); return new Error(s,s); }
|
| 14 |
|
| 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.");
|
| 18 |
|
| 19 |
function check_decoding () {
|
| 20 |
var d = document.getElementById('cometestme');
|
| 21 |
if(!d) {
|
| 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.
|
| 27 |
|
| 28 |
} else {
|
| 29 |
var ampy = d.textContent;
|
| 30 |
if(DEBUG > 1) { alert("Got " + ampy); }
|
| 31 |
|
| 32 |
if(ampy == undefined) throw complaining("'cometestme' element has undefined text content?!");
|
| 33 |
if(ampy == '' ) throw complaining("'cometestme' element has empty text content?!" );
|
| 34 |
|
| 35 |
if (ampy == "\x26" ) { is_decoding = true; }
|
| 36 |
else if (ampy == "\x26amp;" ) { is_decoding = false; }
|
| 37 |
else { throw complaining('Insane value: "' + ampy + '"!'); }
|
| 38 |
}
|
| 39 |
|
| 40 |
var msg =
|
| 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"
|
| 44 |
;
|
| 45 |
if(DEBUG) alert(msg);
|
| 46 |
return msg;
|
| 47 |
}
|
| 48 |
|
| 49 |
|
| 50 |
function go_decoding () {
|
| 51 |
check_decoding();
|
| 52 |
|
| 53 |
if(is_decoding) {
|
| 54 |
DEBUG && alert("No work needs doing -- already decoded!");
|
| 55 |
return;
|
| 56 |
}
|
| 57 |
|
| 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!");
|
| 61 |
return;
|
| 62 |
}
|
| 63 |
|
| 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.");
|
| 68 |
|
| 69 |
var s;
|
| 70 |
for(var i = to_decode.length - 1; i >= 0; i--) {
|
| 71 |
s = to_decode[i].textContent;
|
| 72 |
|
| 73 |
if(
|
| 74 |
s == undefined ||
|
| 75 |
(s.indexOf('&') == -1 && s.indexOf('<') == -1)
|
| 76 |
) {
|
| 77 |
// the null or markupless element needs no reworking
|
| 78 |
} else {
|
| 79 |
to_decode[i].innerHTML = s; // that's the magic
|
| 80 |
}
|
| 81 |
}
|
| 82 |
|
| 83 |
return;
|
| 84 |
}
|
| 85 |
|
| 86 |
//End
|