Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Am I monkeypatching jQueryUI ProgressBar correctly in this example?

I've got a full bore copy of jQuery UI in the app, so it doesn't matter if I'm loading from the CDN or locally, all I know is it's loaded. (because if we load from the CDN our only option is to monkeypatch the live version, yes?)

I see from: https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.progressbar.js that this.min is unfortunately not a settable option (this.options.max in contrast). I need this.min to be -1 in my case (and yes, application wide, we have discussed this internally on the team and we understand the reason for the jQuery decision, we just need it to be otherwise), so my only options seem to be to monkeypatch the prototype or maintain my own plugin. I also see that they are using the "widget" architecture now, for loading the jQuery UI objects.

In this particular application, my scripts are roughly loaded like so:

/javascripts/lib/jquery.min.js
/javascripts/lib/jquery-ui.min.js
...
/javascripts/company.utils.js
/javascripts/company.helpers.js
...
page level includes of javascript libraries
...
page level javascript

So I'm thinking of going into company.utils.js and define a monkeypatch like so:

$.ui.progressbar.prototype.min = -1;

However, I'm curious if this is the right way to monkeypatch this object. Pretty sure it is, but thought I would ask the wider StackOverflow community, and offer something googlable for future searchers.

like image 800
jcolebrand Avatar asked Dec 17 '12 15:12

jcolebrand


1 Answers

Yes, that's correct. Alternatively, if you're using jQuery UI 1.9, you can use the widget factory to define your extension:

$.widget( "ui.progressbar", $.ui.progressbar, {
    min: -1
});

Though it is slightly more verbose.

like image 155
Scott González Avatar answered Nov 14 '22 07:11

Scott González