Created
July 15, 2013 01:55
-
-
Save jookyboi/5997006 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var win = window; | |
var doc = win.document; | |
var attrModifiedWorks = false; | |
var listener = function () { attrModifiedWorks = true; }; | |
doc.documentElement.addEventListener("DOMAttrModified", listener, false); | |
doc.documentElement.setAttribute("___TEST___", true); | |
doc.documentElement.removeAttribute("___TEST___", true); | |
doc.documentElement.removeEventListener("DOMAttrModified", listener, false); | |
if (!attrModifiedWorks) | |
{ | |
This.DOMAttrModifiedUnsupported = true; | |
win.HTMLElement.prototype.__setAttribute = win.HTMLElement.prototype.setAttribute; | |
win.HTMLElement.prototype.setAttribute = function fixDOMAttrModifiedSetAttr (attrName, newVal) | |
{ | |
var prevVal = this.getAttribute(attrName); | |
this.__setAttribute(attrName, newVal); | |
newVal = this.getAttribute(attrName); | |
if (newVal != prevVal) | |
{ | |
var evt = doc.createEvent("MutationEvent"); | |
evt.initMutationEvent | |
( "DOMAttrModified" | |
, true | |
, false | |
, this | |
, prevVal || "" | |
, newVal || "" | |
, attrName | |
, (prevVal == null) ? win.MutationEvent.ADDITION : win.MutationEvent.MODIFICATION | |
); | |
this.dispatchEvent(evt); | |
} | |
} | |
win.HTMLElement.prototype.__removeAttribute = win.HTMLElement.prototype.removeAttribute; | |
win.HTMLElement.prototype.removeAttribute = function fixDOMAttrModifiedRemoveAttr (attrName) | |
{ | |
var prevVal = this.getAttribute(attrName); | |
this.__removeAttribute(attrName); | |
var evt = doc.createEvent("MutationEvent"); | |
evt.initMutationEvent("DOMAttrModified", true, false, this, prevVal, "", attrName, win.MutationEvent.REMOVAL); | |
this.dispatchEvent(evt); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment