2010-02-03 09:59:46 +01:00
// For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/
2010-03-20 20:15:31 +01:00
/*@cc_on'abbr article aside audio canvas details figcaption figure footer header hgroup mark menu meter nav output progress section summary time video'.replace(/\w+/g,function(n){document.createElement(n)})@*/
2010-02-03 09:59:46 +01:00
var addEvent = ( function ( ) {
if ( document . addEventListener ) {
return function ( el , type , fn ) {
2010-02-10 09:10:21 +01:00
if ( el && el . nodeName || el === window ) {
2010-02-03 09:59:46 +01:00
el . addEventListener ( type , fn , false ) ;
} else if ( el && el . length ) {
for ( var i = 0 ; i < el . length ; i ++ ) {
addEvent ( el [ i ] , type , fn ) ;
}
}
} ;
} else {
return function ( el , type , fn ) {
2010-02-10 09:10:21 +01:00
if ( el && el . nodeName || el === window ) {
2010-02-03 09:59:46 +01:00
el . attachEvent ( 'on' + type , function ( ) { return fn . call ( el , window . event ) ; } ) ;
} else if ( el && el . length ) {
for ( var i = 0 ; i < el . length ; i ++ ) {
addEvent ( el [ i ] , type , fn ) ;
}
}
} ;
}
} ) ( ) ;
2010-03-04 17:00:10 +01:00
( function ( ) {
var pre = document . createElement ( 'pre' ) ;
pre . id = "view-source"
// private scope to avoid conflicts with demos
addEvent ( window , 'click' , function ( event ) {
if ( event . target . hash == '#view-source' ) {
// event.preventDefault();
if ( ! document . getElementById ( 'view-source' ) ) {
2010-10-19 21:07:30 +02:00
// pre.innerHTML = ('<!DOCTYPE html>\n<html>\n' + document.documentElement.innerHTML + '\n</html>').replace(/[<>]/g, function (m) { return {'<':'<','>':'>'}[m]});
var xhr = new XMLHttpRequest ( ) ;
// original source - rather than rendered source
xhr . onreadystatechange = function ( ) {
if ( this . readyState == 4 && this . status == 200 ) {
pre . innerHTML = this . responseText . replace ( /[<>]/g , function ( m ) { return { '<' : '<' , '>' : '>' } [ m ] } ) ;
prettyPrint ( ) ;
}
} ;
document . body . appendChild ( pre ) ;
// really need to be sync? - I like to think so
xhr . open ( "GET" , window . location , true ) ;
xhr . send ( ) ;
2010-03-04 17:00:10 +01:00
}
document . body . className = 'view-source' ;
var sourceTimer = setInterval ( function ( ) {
if ( window . location . hash != '#view-source' ) {
clearInterval ( sourceTimer ) ;
document . body . className = '' ;
}
} , 200 ) ;
}
} ) ;
} ) ( ) ;