Skip to content

Instantly share code, notes, and snippets.

@quickredfox
Created July 27, 2010 18:35
Show Gist options
  • Save quickredfox/492634 to your computer and use it in GitHub Desktop.
Save quickredfox/492634 to your computer and use it in GitHub Desktop.
/*
Innershiv from J.D. Bartlett
*/
window.innerShiv = (function() {
var d, r;
return function(h, u) {
if (!d) {
d = document.createElement('div');
r = document.createDocumentFragment();
/*@cc_on d.style.display = 'none';@*/
}
var e = d.cloneNode(true);
/*@cc_on document.body.appendChild(e);@*/
e.innerHTML = h;
/*@cc_on document.body.removeChild(e);@*/
if (u === false) return e.childNodes;
var f = r.cloneNode(true), i = e.childNodes.length;
while (i--) f.appendChild(e.firstChild);
return f;
}
}());
/*
Duck Punched into jQuery methods...
*/
var injectors = ['after','before','append','prepend','replaceWith'];
$.each( injectors, function(index,fname){
$.fn['_old_'+fname]=$.fn[fname];
$.fn[fname] = function(html){
if(typeof html == 'string' && (/^[^<]*(<[\w\W]+>)[^>]*$/).test(html)){
arguments[0] = innerShiv(html,false);
};
return $.fn['_old_'+fname].apply(this,arguments);
};
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment