tipsy live不适用于jQuery 1.9.0 [英] tipsy live does not work with jQuery 1.9.0

查看:107
本文介绍了tipsy live不适用于jQuery 1.9.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近将jQuery升级到了1.9.0,但它破坏了我们棘手的插件.现在,它的live功能会导致错误.

We recently upgraded our jQuery to 1.9.0, but it broke our tipsy plugin. Its live functionality now causes an error.

$('.tooltip, abbr').tipsy({
    live: true
});

TypeError: this[binder] is not a function

是否有针对此的修复程序或补丁?谷歌搜索并没有带来任何有用的结果.

Are there any fixes or patches for this? Googling didn't lead to anything useful.

更新:

感谢您的回答.我决定尝试自己解决此问题,因为我找不到任何补丁.

Thanks for the answers. I decided to try to fix the issue myself, because I couldn't find any patches.

经检查,该错误似乎很容易发现.易用的插件可以轻松进行修补,以使用on功能而不是不推荐使用的live功能.在倾斜的插件中,我替换了以下代码:

Upon inspection the error seemed really easy to trace. The tipsy plugin can easily be patched to use the on functionality instead of the deprecated live functionality. In the tipsy plugin, I replaced the following code:

if (options.trigger != 'manual') {
    var binder = options.live ? 'live' : 'bind',
        eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
        eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
    this[binder](eventIn, enter)[binder](eventOut, leave);
}

具有:

if (options.trigger != 'manual') {
    var eventIn = options.trigger == 'hover' ? 'mouseenter' : 'focus',
        eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
    if (options.live)
        $(document).on(eventIn, this.selector, enter).on(eventOut, this.selector, leave);
    else
        this.bind(eventIn, enter).bind(eventOut, leave);
}

像魅力一样工作. :)

Works like a charm. :)

推荐答案

您需要包括jquery迁移插件,因为您使用的是live:true,它利用了在jQuery 1.9中.

you need to include jquery migration plugin, since you are using live:true it make use of jquery.live which was removed in jquery 1.9.

为了向后兼容,他们创建了一个迁移插件,该插件可以为

For backward compatibility they have created a migration plugin which can be downloaded here and include the migration plugin to add back support for the removed methods and utilities.

我会做类似的事情

if (options.trigger != 'manual') {
    var eventIn  = options.trigger == 'hover' ? 'mouseenter' : 'focus',
        eventOut = options.trigger == 'hover' ? 'mouseleave' : 'blur';
    if(options.live){
      $(this.context).on(eventIn, this.selector, enter).on(eventOut, this.selector, leave);
    } else {
      this.on(eventIn, enter).on(eventOut, leave);
    }
}

这篇关于tipsy live不适用于jQuery 1.9.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆