javascript - jQuery.data no longer works with window? -


i upgraded our project's jquery file 1.4.2 1.4.4 , appears of 1.4.3 way have been using jquery.data has stopped working.

we have code:

var events = $(window).data('events');  if (events.scroll) if (!events.scroll.include(handler))   $(window).scroll(handler); 

the purpose prevent particular handler being bound multiple times.

in 1.4.2, works fine. in 1.4.4, events undefined.

function handler() {   //do }  $(document).ready(function(){   $(window).scroll(handler);   $('div#test').scroll(handler);    $(window).data('events') -> undefined   $('div#test').data('events') -> object }); 

what changed api? how should list events window?


i have changed first line this:

var events = $(window).data('__events__').events; 

a bit messy-looking, ability wire events plain objects compelling.

there change in jquery 1.4.3+ event types, avoid object name collisions, window (or other plain object) use key "__events__" instead, this:

var events = $(window).data('__events__'); 

the same __events__ key used objects don't have .nodetype property (which window doesn't, it's treated plain object here).


to clear conscious, intentional change, it's included in the jquery 1.4.3 release notes:

javascript objects
number of changes made when .data() used on javascript objects (or, more accurately, isn’t dom node). start whenever set data on javascript object data set directly on object – instead of going internal data object store. additionally events attached objects put in new __events__ property function. done allow events attached directly object, garbage collected when object collected, , not serialized json serializer. these changes should make jquery’s data , event systems more useful on javascript objects.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -