views:

169

answers:

1

Since I updated jQueryUI to 1.8 I found a couple of issues in our implementations and I could fix it myself without waiting for a fix on their end if I could find out how to subclass a specific method of the datepicker widget so I call the parent code and then execute my code.

I was reading on $.widget but I just can't wrap my head around how that is suppose to work.

I tried something like this:

$.widget("ui.datepicker", {
  _showDatepicker: function(input) {
   alert('Yo');
   $.datepicker.prototype._showDatepicker.apply(this,arguments);
   alert('Hey!');
  }
 });

And all sorts of other variations and beging to think I just don't understand the 'extendability' of jQueryUI or it just can't be done.

Anybody knows how I can achieve this ?

Thx

+1  A: 

The datepicker in 1.8 doesn't use the widget factory. The other widgets do but the datepicker hasn't been refactored to use the widget factory yet, something that will happen for 1.9.

You can do something like for the datepicker:

var old_showDatepicker = $.datepicker._showDatepicker;
$.datepicker._showDatepicker = function(input){
    console.log('hello');
    old_showDatepicker.apply(this,arguments);
    console.log('goodbye');
}

And this for the slider:

$.widget("my.slider", $.ui.slider, {
    _value: function(input) {
        console.log('Yo');
        $.ui.slider.prototype.value.apply(this,arguments);
        console.log('Hey!');
    }
});
PetersenDidIt
I'm getting a f is not a constructor in function remove (from jquery-ui-1.8.custom.min.js) line 37 when it gets to execute this line.
SBUJOLD
Well that was stupid of me, the datepicker doesn't use the widget factory yet, updated my answer.
PetersenDidIt
aaaahhhhhh that explains a whole lot! I ended up this morning doing what you suggested, although was invoking the function directly and not with apply, DOH! Where did you find out that the datepicker does not use the widget factory ? I am so frustrated with the huge gap in maturity and documentation of jQueryUI VS jQuery.
SBUJOLD
I have been working on refactoring the datepicker to use the widget factory it a github branch. I just had a brain laps. The best documentation you can have is the source code, I am always looking at the source of both jQuery and jQuery UI.
PetersenDidIt