如何更改此jQuery小部件(为jQueryUI 1.7编写),使其与jQueryUI 1.8一起使用 [英] How to change this jQuery widget (written for jQueryUI 1.7) so that it works with jQueryUI 1.8

查看:114
本文介绍了如何更改此jQuery小部件(为jQueryUI 1.7编写),使其与jQueryUI 1.8一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此jQuery插件可让用户在div中绘制矩形,并且可与jQueryUI 1.7.2一起使用. /p>

我需要使其与 jQueryUI 1.8.4 一起使用.通过阅读 widget升级指南,我无法确定需要更改的内容.我尝试将_init()重命名为_create(),但没有做任何事情.为了使它正常工作,我还需要更改什么?感谢您的阅读.

解决方案

$.widget签名已更改为在内部进行扩展,因此请进行以下更改:

$.widget("ui.boxer", $.extend({}, $.ui.mouse, {

对此:

$.widget("ui.boxer", $.ui.mouse, {

然后在底部也删除多余的),将}));更改为});


此外,要获得默认选项,最好将它们移入内部,如下所示:

$.widget("ui.boxer", $.ui.mouse, {
  options: {
    appendTo: 'body',
    distance: 0
  },
  ///rest of widget, unchanged...
});

此处是仅 上述更改的更新版本的示例,正在工作.

This jQuery plugin, which lets users draw rectangles in a div, works with jQueryUI 1.7.2.

I need to get it working with jQueryUI 1.8.4. From reading the widget upgrade guide, I can't work out what needs to change. I tried renaming _init() to _create(), but that didn't do anything. What else do I need to change to get it working? Thanks for reading.

解决方案

The $.widget signature changed to do the extend internally, so change this:

$.widget("ui.boxer", $.extend({}, $.ui.mouse, {

To this:

$.widget("ui.boxer", $.ui.mouse, {

And at the bottom, remove the extra ) as well, changing })); to });


Also, to get the default options, it's best to move them right inside, like this:

$.widget("ui.boxer", $.ui.mouse, {
  options: {
    appendTo: 'body',
    distance: 0
  },
  ///rest of widget, unchanged...
});

Here's a sample of the updated version with only the changes above, working.

这篇关于如何更改此jQuery小部件(为jQueryUI 1.7编写),使其与jQueryUI 1.8一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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