Created
April 1, 2010 18:48
-
-
Save atesgoral/352210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Hack to allow jQuery to work within XHTML documents that define an xmlns | |
*/ | |
/** | |
* Use the given object to override the given methods in its prototype | |
* with namespace-aware equivalents | |
*/ | |
function addNS(obj, methods) { | |
var proto = obj.constructor.prototype; | |
var ns = document.documentElement.namespaceURI; | |
for (var methodName in methods) { | |
(function () { | |
var methodNS = proto[methodName + "NS"]; | |
if (methodNS) { | |
proto[methodName] = function () { | |
var args = Array.prototype.slice.call(arguments, 0); | |
args.unshift(ns); | |
return methodNS.apply(this, args); | |
}; | |
} | |
})(); | |
} | |
} | |
// Play nice with IE -- who doesn't need this hack in the first place | |
if (document.constructor) { | |
// Override document methods that are used by jQuery | |
addNS(document, { | |
createElement: 1, | |
getElementsByTagName: 1 | |
}); | |
// Override element methods that are used by jQuery | |
addNS(document.createElement("div"), { | |
getElementsByTagName: 1, | |
getAttribute: 1, | |
getAttributeNode: 1, | |
removeAttribute: 1, | |
setAttribute: 1 | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you provide a usage example? For example, how would I use this to read a fb:loginbutton tag with jQuery?