How to change this jQuery widget (written for jQueryUI 1.7) so that it works with jQueryUI 1.8

对着背影说爱祢 提交于 2019-11-28 02:20:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4310189/how-to-change-this-jquery-widget-written-for-jqueryui-1-7-so-that-it-works-wit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!