var DialogResult = {
None: 0,
OK: 1,
Cancel: 2,
Abort: 3,
Retry: 4,
Ignore: 5,
Yes: 6,
No: 7,
ConvertToString: function(value) {
switch (value) {
case DialogResult.None:
return 'None';
case DialogResult.OK:
return 'OK';
case DialogResult.Cancel:
return 'Cancel';
case DialogResult.Abort:
return 'Abort';
case DialogResult.Retry:
return 'Retry';
case DialogResult.Ignore:
return 'Ignore';
case DialogResult.Yes:
return 'Yes';
case DialogResult.No:
return 'No';
default:
return null;
}
}
}
var setDataSwitch = {
dragStart: "start.draggable",
drag: "drag.draggable",
dragStop: "stop.draggable",
maxHeight: "maxHeight.resizable",
minHeight: "minHeight.resizable",
maxWidth: "maxWidth.resizable",
minWidth: "minWidth.resizable",
resizeStart: "start.resizable",
resize: "drag.resizable",
resizeStop: "stop.resizable"
},
uiDialogClasses =
'ui-dialog ' +
'ui-widget ' +
'ui-widget-content ' +
'ui-corner-all ';
$.extend($.ui.dialog.prototype, {
open: function(callbackMethod) {
if (this._isOpen) { return; }
if (callbackMethod != null)
this.closeCallback = callbackMethod;
var options = this.options,
uiDialog = this.uiDialog;
this.overlay = options.modal ? new $.ui.dialog.overlay(this) : null;
//Sike Mullivan - Changed from document.body to forms[0] to allow button submit
(uiDialog.next().length && uiDialog.appendTo(document.forms[0]));
this._size();
this._position(options.position);
uiDialog.show(options.show);
this.moveToTop(true);
// prevent tabbing out of modal dialogs
(options.modal && uiDialog.bind('keypress.ui-dialog', function(event) {
if (event.keyCode != $.ui.keyCode.TAB) {
return;
}
var tabbables = $(':tabbable', this),
first = tabbables.filter(':first')[0],
last = tabbables.filter(':last')[0];
if (event.target == last && !event.shiftKey) {
setTimeout(function() {
first.focus();
}, 1);
} else if (event.target == first && event.shiftKey) {
setTimeout(function() {
last.focus();
}, 1);
}
}));
// set focus to the first tabbable element in the content area or the first button
// if there are no tabbable elements, set focus on the dialog itself
$([])
.add(uiDialog.find('.ui-dialog-content :tabbable:first'))
.add(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'))
.add(uiDialog)
.filter(':first')
.focus();
this._trigger('open');
this._isOpen = true;
//Disable Close Button in Title Bar.
var closeButtons = this.uiDialogTitlebar[0].getElementsByTagName("a");
for (var i = 0; i < closeButtons.length; i++) {
closeButtons[i].style.visibility = "hidden";
closeButtons[i].style.display = "none";
}
},
setCloseCallback: function(callbackMethod) {
this.closeCallback = callbackMethod;
},
close: function(event, result) {
var self = this;
if (result == null)
result = DialogResult.Cancel;
if (false === self._trigger('beforeclose', event)) {
return;
}
(self.overlay && self.overlay.destroy());
self.uiDialog.unbind('keypress.ui-dialog');
(self.options.hide
? self.uiDialog.hide(self.options.hide, function() {
self._trigger('close', event);
})
: self.uiDialog.hide() && self._trigger('close', event));
$.ui.dialog.overlay.resize();
self._isOpen = false;
if (this.closeCallback)
this.closeCallback(this, result);
},
_init: function() {
this.originalTitle = this.element.attr('title');
var self = this,
options = this.options,
title = options.title || this.originalTitle || ' ',
titleId = $.ui.dialog.getTitleId(this.element),
uiDialog = (this.uiDialog = $('<div/>'))
//Sike Mullivan - Changed from document.body to forms[0] to allow button submit
.appendTo(document.forms[0])
.hide()
.addClass(uiDialogClasses + options.dialogClass)
.css({
position: 'absolute',
overflow: 'hidden',
zIndex: options.zIndex
})
// setting tabIndex makes the div focusable
// setting outline to 0 prevents a border on focus in Mozilla
.attr('tabIndex', -1).css('outline', 0).keydown(function(event) {
(options.closeOnEscape && event.keyCode
&& event.keyCode == $.ui.keyCode.ESCAPE && self.close(event));
})
.attr({
role: 'dialog',
'aria-labelledby': titleId
})
.mousedown(function(event) {
self.moveToTop(false, event);
}),
uiDialogContent = this.element
.show()
.removeAttr('title')
.addClass(
'ui-dialog-content ' +
'ui-widget-content')
.appendTo(uiDialog),
uiDialogTitlebar = (this.uiDialogTitlebar = $('<div></div>'))
.addClass(
'ui-dialog-titlebar ' +
'ui-widget-header ' +
'ui-corner-all ' +
'ui-helper-clearfix'
)
.prependTo(uiDialog),
uiDialogTitlebarClose = $('<a href="#"/>')
.addClass(
'ui-dialog-titlebar-close ' +
'ui-corner-all'
)
.attr('role', 'button')
.hover(
function() {
uiDialogTitlebarClose.addClass('ui-state-hover');
},
function() {
uiDialogTitlebarClose.removeClass('ui-state-hover');
}
)
.focus(function() {
uiDialogTitlebarClose.addClass('ui-state-focus');
})
.blur(function() {
uiDialogTitlebarClose.removeClass('ui-state-focus');
})
.mousedown(function(ev) {
ev.stopPropagation();
})
.click(function(event) {
self.close(event);
return false;
})
.appendTo(uiDialogTitlebar),
uiDialogTitlebarCloseText = (this.uiDialogTitlebarCloseText = $('<span/>'))
.addClass(
'ui-icon ' +
'ui-icon-closethick'
)
.text(options.closeText)
.appendTo(uiDialogTitlebarClose),
uiDialogTitle = $('<span/>')
.addClass('ui-dialog-title')
.attr('id', titleId)
.html(title)
.prependTo(uiDialogTitlebar);
uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection();
(options.draggable && $.fn.draggable && this._makeDraggable());
(options.resizable && $.fn.resizable && this._makeResizable());
this._createButtons(options.buttons);
this._isOpen = false;
(options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe());
(options.autoOpen && this.open());
},
destroy: function() {
(this.overlay && this.overlay.destroy());
this.uiDialog.hide();
this.element
.unbind('.dialog')
.removeData('dialog')
.removeClass('ui-dialog-content ui-widget-content')
.hide()
//Sike Mullivan - Changed from document.body to forms[0] to allow button submit
.appendTo(document.forms[0]);
this.uiDialog.remove();
(this.originalTitle && this.element.attr('title', this.originalTitle));
}
});
$.extend($.ui.dialog.overlay, {
create: function(dialog) {
if (this.instances.length === 0) {
// prevent use of anchors and inputs
// we use a setTimeout in case the overlay is created from an
// event that we're going to be cancelling (see #2804)
setTimeout(function() {
$(document).bind($.ui.dialog.overlay.events, function(event) {
var dialogZ = $(event.target).parents('.ui-dialog').css('zIndex') || 0;
return (dialogZ > $.ui.dialog.overlay.maxZ);
});
}, 1);
// allow closing by pressing the escape key
$(document).bind('keydown.dialog-overlay', function(event) {
(dialog.options.closeOnEscape && event.keyCode
&& event.keyCode == $.ui.keyCode.ESCAPE && dialog.close(event));
});
// handle window resize
$(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
}
//Sike Mullivan - Changed from document.body to forms[0] to allow button submit
var $el = $('<div></div>').appendTo(document.forms[0])
.addClass('ui-widget-overlay').css({
width: this.width(),
height: this.height()
});
(dialog.options.bgiframe && $.fn.bgiframe && $el.bgiframe());
this.instances.push($el);
return $el;
}
});