Skip to content

Instantly share code, notes, and snippets.

@sstephenson
Created February 12, 2010 20:06
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 sstephenson/302923 to your computer and use it in GitHub Desktop.
Save sstephenson/302923 to your computer and use it in GitHub Desktop.
(function() {
var queue = [];
function checkQueue() {
if (queue.any())
queue.pop().fire("dom:modified");
}
var notify;
function deferFire(element) {
if (!queue.include(element))
queue.push(element);
if (notify)
window.clearTimeout(notify);
notify = checkQueue.defer();
}
function fireModifiedEvent() {
var args = $A(arguments), proceed = args.shift(), parent = $(args.first()).up();
var element = proceed.apply(this, args);
if (Object.isElement(element) && element.up("html")) {
deferFire(element);
} else if (Object.isElement(parent) && parent.up("html")) {
deferFire(parent);
}
return element;
}
Element.addMethods({
insert: Element.Methods.insert.wrap(fireModifiedEvent),
replace: Element.Methods.replace.wrap(fireModifiedEvent),
update: Element.Methods.update.wrap(fireModifiedEvent)
});
document.observe("dom:loaded", function() {
$(document.body).fire("dom:modified");
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment