(function($) {
function showThrobber(element) {
$(element).after("");
$(element).attr('disabled', 'disabled');
}
function hideThrobber(element) {
$(element).next().remove();
$(element).removeAttr('disabled');
}
var ujsDialogElement = null; // the element that opened the dialog
// called from dialog button value
function ujsSubmitDialogForm() {
$('.ui-dialog:visible form').first().submit();
}
// called from dialog button value
function ujsDialogClose() {
$('.ui-dialog-content:visible').dialog('destroy')
.addClass('ujs-dialog-hidden');
}
function ujsDialogOpen() {
if ($(this).parent().height() > $(window).height()) {
$(this).height($(window).height() * 0.8);
$(this).parent().css('top',
($(window).height() - $(this).parent().height()) / 2
);
$(this).css('overflow-y', 'auto');
}
var x = $(this).find('.ujs-dialog-x');
if (x.length) {
$(this).parent().append(x); // to keep it fixed to the dialog
// don't let the dialog be resized - the resize functionality
// clashes with the X close functionality
$(this).dialog('option', 'resizable', false);
}
}
function ujsDialogClick(event) {
ujsDialogElement = $(this);
var dialogID = $(this).data('dialog-id');
var dialogElement = $('#' + dialogID);
if (dialogID == 'next') dialogElement = $(this).next();
if ($(this).data('close-x')) {
dialogElement.prepend('');
}
var dialogOptions = $(this).data('dialog-options');
var open = dialogOptions['open'];
dialogOptions = $.extend(dialogOptions, {
'close': function() {
$(this).dialog('destroy').addClass('ujs-dialog-hidden');
},
'open': function() {
ujsDialogOpen.call(this);
if (open) {
var openFunc = eval(open);
openFunc.call(this);
}
}
});
if (dialogOptions.buttons) {
$.each(dialogOptions.buttons, function(index, element) {
if (element == 'submit') {
dialogOptions.buttons[index] = ujsSubmitDialogForm;
}
else if (element.click == 'submit') {
dialogOptions.buttons[index].click = ujsSubmitDialogForm;
}
else if (element == 'close') {
dialogOptions.buttons[index] = ujsDialogClose;
}
else if (element.click == 'close') {
dialogOptions.buttons[index].click = ujsDialogClose;
}
});
}
var url = $(this).data('dialog-url');
if (url) {
$(this).trigger('jqr.beforedialogopen');
$(document.body).append('