I have written a library of useful 'mobile' events (available here). It essentially unifies touch events so that a single event can be bound to an element, and it will trigger regardless of the user's device (i.e. mobile or desktop).
The code has been working well, but while debugging a user's problem, I noticed that the library no longer functions when jQuery 1.9.0 is used (all previous versions of jQuery don't cause a problem).
The problematic code is as follows:
// Add Event shortcuts:
$.each(('tapstart tapend tap singletap doubletap taphold swipe swipeup swiperight swipedown swipeleft scrollstart scrollend orientationchange').split(' '), function(i, name) {
$.fn[name] = function(fn)
{
return fn ? this.bind(name, fn) : this.trigger(name);
};
$.attrFn[name] = true;
});
The error Uncaught TypeError: Cannot set property 'tapstart' of undefined
on the following line:
$.attrFn[name] = true;
Can anyone point me in the direction of producing a fix for this?
I have put together 2 jsFiddle demos to show the problem:
- Working version (using jQuery 1.8.3)
- Non-working version (using jQuery 1.9.0)
If I define $.attrFn
, this fixes code for the swipe*
events, but then causes problems with others such as tap
and doubletap
. For example, binding tap
now produces the error: Uncaught TypeError: Cannot call method 'call' of undefined
, with the problematic line being:
$.event.handle.call( obj, event );
Once again, there are two jsFiddles for reference:
- Working version (using jQuery 1.8.3)
- Non-working version (using jQuery 1.9.0 with
$.attrFn = $.attrFn || {};
fix)
I have written a library of useful 'mobile' events (available here). It essentially unifies touch events so that a single event can be bound to an element, and it will trigger regardless of the user's device (i.e. mobile or desktop).
The code has been working well, but while debugging a user's problem, I noticed that the library no longer functions when jQuery 1.9.0 is used (all previous versions of jQuery don't cause a problem).
The problematic code is as follows:
// Add Event shortcuts:
$.each(('tapstart tapend tap singletap doubletap taphold swipe swipeup swiperight swipedown swipeleft scrollstart scrollend orientationchange').split(' '), function(i, name) {
$.fn[name] = function(fn)
{
return fn ? this.bind(name, fn) : this.trigger(name);
};
$.attrFn[name] = true;
});
The error Uncaught TypeError: Cannot set property 'tapstart' of undefined
on the following line:
$.attrFn[name] = true;
Can anyone point me in the direction of producing a fix for this?
I have put together 2 jsFiddle demos to show the problem:
- Working version (using jQuery 1.8.3)
- Non-working version (using jQuery 1.9.0)
If I define $.attrFn
, this fixes code for the swipe*
events, but then causes problems with others such as tap
and doubletap
. For example, binding tap
now produces the error: Uncaught TypeError: Cannot call method 'call' of undefined
, with the problematic line being:
$.event.handle.call( obj, event );
Once again, there are two jsFiddles for reference:
- Working version (using jQuery 1.8.3)
- Non-working version (using jQuery 1.9.0 with
$.attrFn = $.attrFn || {};
fix)
- If you check the 1.8 source code, it's pretty obvious :-) – Pointy Commented Jan 17, 2013 at 17:48
2 Answers
Reset to default 12That object (.attrFn
) was just a stub in 1.8; it's gone in 1.9.
If your code worked in 1.8, you should be able to add
$.attrFn = $.attrFn || {};
somewhere to fix it.
From the jQuery 1.9 Release Notes
Other undocumented properties and methods
The following internal properties and methods were never documented and have been removed in 1.9. Any code that depends on them should be rewritten.
- jQuery.deletedIds
- jQuery.uuid
- jQuery.attrFn
- jQuery.clean()
- jQuery.event.handle()
- jQuery.offset.bodyOffset()