最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery 1.9.0 breaks $.attrFn object - Stack Overflow

programmeradmin2浏览0评论

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)
Share Improve this question edited Jan 17, 2013 at 18:04 BenM asked Jan 17, 2013 at 17:43 BenMBenM 53.2k26 gold badges115 silver badges171 bronze badges 1
  • If you check the 1.8 source code, it's pretty obvious :-) – Pointy Commented Jan 17, 2013 at 17:48
Add a comment  | 

2 Answers 2

Reset to default 12

That 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()
发布评论

评论列表(0)

  1. 暂无评论