Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override jQueryUI dialog default options

Tags:

I want to be able to create modal dialogs, with, for example

close: function() {     $(this).remove(); } 

default option, without need to specify those on dialog creation, but somehow override those parameters on one place.

Is this possible?

like image 824
umpirsky Avatar asked Feb 18 '10 08:02

umpirsky


2 Answers

I, too, needed to override default options and took me a while to figure out for jQuery UI 1.8:

$.extend($.ui.dialog.prototype.options, {     modal: true,     resizable: false,     draggable: false }); 

The above code will allow you to drop anything on top of the dialog options. The above method should work for most UI components (it will also let you prototype over the functions that exist, or add to).

like image 115
James W Avatar answered Sep 23 '22 02:09

James W


You should create an abstration that calls the jQuery dialog function then.

Basically, instead of creating the options literal everyplace you want to use the jQuery dialog, create a function which creates the options that you want and then call the jQuery dialog function from that.

Then, in all areas of your code, call the function you wrote that encapsulated the code.

This process is known as encapsulation and applies to most (if not all) software development languages. One of the major benefits is that it makes your code easier to maintain.

like image 33
casperOne Avatar answered Sep 23 '22 02:09

casperOne