16 Nov 2011, 07:07
event.layerX and event.layerY are broken and deprecated in WebKit.If you’ve been testing any web development against Chrome developer builds, you’ve quite possibly seen this warning show up in your console:
event.layerX and event.layerY are broken and deprecated in WebKit.They will be removed from the engine in the near future.
I found a handy little Javascript that will alleviate this problem (though I can’t seem to find the source of it now; if you do, please let me know). It looks like this:
// Prevent "event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future."
// in latest Chrome builds.
(function () {
// remove layerX and layerY
var all = $.event.props,
len = all.length,
res = [];
while (len--) {
var el = all[len];
if (el != 'layerX' && el != 'layerY') res.push(el);
}
$.event.props = res;
} ());
This self executing function goes through jQuery’s $.event
properties and removes the references to event.layerX
and event.layerY
so that jQuery won’t try to copy them to new objects in the future.
The root of the problem is that whenever jQuery binds events, it copies those properties. If you execute this function before you do any event binding with jQuery, those properties don’t exist to be copied. Bye bye warnings!
Updates:
This address the problem for jQuery >= 1.7:
> jQuery Ticket #10531: Consider removing layerX
and layerY
from $.event.props
The source of the snippet appears to be http://jsperf.com/removing-event-props/2 via http://stackoverflow.com/questions/7825448/webkit-issues-with-event-layerx-and-event-layery.