I'm trying to figure out how to fix this code for jQueryUI 1.8.5 and jQuery 1.5.1 and am out of luck with such advanced stuff, can anyone lend a hand?
The problem is with the code below:
$.extend($.ui.boxer, {
defaults: $.extend({}, $.ui.mouse.defaults, {
appendTo: 'body',
distance: 0
})
});
It开发者_C百科 doesn't initialize options with appendTo and distance values for some reason.
Though I haven't worked with jQuery UI before, I took a stab at this one for the night. It appears that you have two problems with the code you showed in jsfiddle. The first is that in UI 1.8, you no longer have to do extend when creating a widget,
$.widget("ui.boxer", $.ui.mouse, {
...
});
Switching to this new style of declaring a widget, the error for this._mouseInit()
goes away. This was needed to be done before we can address the question you had, which was why defaults did not work. In this commit https://github.com/jquery/jquery-ui/commit/90fb45dffafc2e891b1ebca948ad33e6b94de112, ui.mouse.defaults
was replaced with options
. Since options
is part of the widget, you now have to extend the prototype,
$.extend($.ui.boxer.prototype, {
options: $.extend({}, $.ui.mouse.prototype.options, {
appendTo: 'body',
distance: 0
})
});
These changes resulted in something that works ( http://jsfiddle.net/wqvJG/1/ ). BTW, what this code does is awesome :).
That part seems to be working (I debugged it and made sure the appendTo is being said as expected.) There was a warning about the tmp variable being used twice so I fixed that. With that change, the demo seems to be working as I would think it should. Is there anything wrong with it:
http://jsbin.com/aqowa/150/edit#javascript,html
精彩评论