What's the best practice to add default function to jQuery Dialog open/close events?
Posted
by BlueFox
on Stack Overflow
See other posts from Stack Overflow
or by BlueFox
Published on 2010-04-08T00:38:18Z
Indexed on
2010/04/08
0:43 UTC
Read the original article
Hit count: 345
jQuery
|jquery-ui-dialog
Hi All, I'm trying to define some default behaviours for my jQuery Dialogs like the following:
(function($) {
/**
* Overriding default options
**/
$.ui.dialog.defaults.bgiframe = true;
$.ui.dialog.defaults.open = function() {
if ($('.ui-widget-overlay').length == 0) return;
if ($.browser.msie) {
// scrollbar fix for IE
$('html').css('overflow-y','hidden');
$('html').css('overflow-x','hidden');
} else {
// disable scrollbar for other browsers
$('body').css('overflow','hidden');
}
};
$.ui.dialog.defaults.beforeclose = function(event, ui) {
if ($('.ui-widget-overlay').length == 0) return;
if ($.browser.msie) {
// scrollbar fix for IE
$('html').css('overflow-y','auto');
$('html').css('overflow-x','auto');
} else {
// disable scrollbar for other browsers
$('body').css('overflow','auto');
}
};
})(jQuery);
The above works when I have no custom open/beforeclose function specified when the dialog is created. So I'm wondering what is the best practice to add these functionality into all my dialogs, while preserving the ability to specify open/beforeclose functions.
© Stack Overflow or respective owner