Skip to content

Instantly share code, notes, and snippets.

@jonathantneal
Created October 26, 2011 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathantneal/1317227 to your computer and use it in GitHub Desktop.
Save jonathantneal/1317227 to your computer and use it in GitHub Desktop.
agnostic-html-shim.htc.html
<PUBLIC:COMPONENT lightWeight="true">
<PUBLIC:ATTACH EVENT="onreadystatechange" FOR="document" ONEVENT="shim()">
<SCRIPT>
// an agnostic html shim
// it doesn't believe in any particular element... yet!
// usage: <style> body { *behavior: url(iepp.htc); } </style> or anything like that
//
function shim() {
// stop if we already believe
var doc = element.document;//, elem = doc.createElement('i'); elem.innerHTML = "<iii>"; if (elem.childNodes.length) return;
// search for the unbelievable
var shim = false, shimmed = {}, es = doc.getElementsByTagName('*'), l = es.length, i = -1, e;
// detect the unbelievable and begin to believe
while (++i < l && (e = es[i].nodeName)) if (e.substr(0,1) === '/' && !shimmed[e] && (shim = shimmed[e] = true)) doc.createElement(e.substr(1));
// reconsider everything after any newfound belief
if (shim) doc.body.innerHTML = doc.body.innerHTML;
}
</SCRIPT>
</PUBLIC:COMPONENT>
@aFarkas
Copy link

aFarkas commented Oct 26, 2011

You go a little bit crazy :-). I think you have to check the readyState, though:

function shim() {
    // stop if we already believe
    var doc = element.document;//, elem = doc.createElement('i'); elem.innerHTML = "<iii>"; if (elem.childNodes.length) return;
    //wait if are not ready yet
    if(doc.readyState != 'complete'){return;}
    // search for the unbelievable
    var shim = false, shimmed = {}, es = doc.getElementsByTagName('*'), l = es.length, i = -1, e;
    // detect the unbelievable and begin to believe
    while (++i < l && (e = es[i].nodeName)) if (e.substr(0,1) === '/' && !shimmed[e] && (shim = shimmed[e] = true)) doc.createElement(e.substr(1));
    // reconsider everything after any newfound belief
    if (shim) doc.body.innerHTML = doc.body.innerHTML;
}

@aFarkas
Copy link

aFarkas commented Oct 26, 2011

oh and the following line should be simply changed for small performance:

while (++i < l && (e = es[i].nodeName)) if (!shimmed[e] && e.substr(0,1) === '/' && (shim = shimmed[e] = true)) doc.createElement(e.substr(1));

@jonathantneal
Copy link
Author

I'm downloading skype to talk now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment