mirror of
https://github.com/Erreur32/html5demos.git
synced 2024-09-30 09:21:28 +02:00
53 lines
1.8 KiB
JavaScript
53 lines
1.8 KiB
JavaScript
// For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/
|
|
(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,canvas,datalist,details,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while (i--){document.createElement(e[i])}})();
|
|
|
|
var addEvent = (function () {
|
|
if (document.addEventListener) {
|
|
return function (el, type, fn) {
|
|
if (el && el.nodeName || el === window) {
|
|
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) {
|
|
if (el && el.nodeName || el === window) {
|
|
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);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
})();
|
|
|
|
(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')) {
|
|
pre.innerHTML = ('<!DOCTYPE html>\n<html>\n' + document.documentElement.innerHTML + '\n</html>').replace(/[<>]/g, function (m) { return {'<':'<','>':'>'}[m]});
|
|
document.body.appendChild(pre);
|
|
}
|
|
document.body.className = 'view-source';
|
|
|
|
var sourceTimer = setInterval(function () {
|
|
if (window.location.hash != '#view-source') {
|
|
clearInterval(sourceTimer);
|
|
document.body.className = '';
|
|
}
|
|
}, 200);
|
|
}
|
|
});
|
|
|
|
})();
|