(function($) { var e = { 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 '; $.widget("ui.dialog", { _init: function() { this.originalTitle = this.element.attr('title'); var b = this, options = this.options, title = options.title || this.originalTitle || '&nbsp;', titleId = $.ui.dialog.getTitleId(this.element), uiDialog = (this.uiDialog = $('<div/>')).appendTo(document.body).hide().addClass(uiDialogClasses + options.dialogClass).css({ position: 'absolute', top: '0', left: '0', width: '99%', overflow: 'hidden', zIndex: options.zIndex }).attr('tabIndex', -1).css('outline', 0).keydown(function(a) { (options.closeOnEscape && a.keyCode && a.keyCode == $.ui.keyCode.ESCAPE && b.close(a)) }).attr({ role: 'dialog', 'aria-labelledby': titleId }).mousedown(function(a) { b.moveToTop(false, a) }), 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), 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().appendTo('body'); this.uiDialog.remove(); (this.originalTitle && this.element.attr('title', this.originalTitle)) }, close: function(a) { var b = this; if (false === b._trigger('beforeclose', a)) { return } (b.overlay && b.overlay.destroy()); b.uiDialog.unbind('keypress.ui-dialog'); (b.options.hide ? b.uiDialog.hide(b.options.hide, function() { b._trigger('close', a) }) : b.uiDialog.hide() && b._trigger('close', a)); $.ui.dialog.overlay.resize(); b._isOpen = false; if (b.options.modal) { var c = 0; $('.ui-dialog').each(function() { if (this != b.uiDialog[0]) { c = Math.max(c, $(this).css('z-index')) } }); $.ui.dialog.maxZ = c } }, isOpen: function() { return this._isOpen }, moveToTop: function(a, b) { if ((this.options.modal && !a) || (!this.options.stack && !this.options.modal)) { return this._trigger('focus', b) } if (this.options.zIndex > $.ui.dialog.maxZ) { $.ui.dialog.maxZ = this.options.zIndex } (this.overlay && this.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = ++$.ui.dialog.maxZ)); var c = { scrollTop: this.element.attr('scrollTop'), scrollLeft: this.element.attr('scrollLeft') }; this.uiDialog.css('z-index', ++$.ui.dialog.maxZ); this.element.attr(c); this._trigger('focus', b) }, open: function() { if (this._isOpen) { return } var c = this.options, uiDialog = this.uiDialog; this.overlay = c.modal ? new $.ui.dialog.overlay(this) : null; (uiDialog.next().length && uiDialog.appendTo('body')); this._size(); this._position(c.position); uiDialog.show(c.show); this.moveToTop(true); (c.modal && uiDialog.bind('keypress.ui-dialog', function(a) { if (a.keyCode != $.ui.keyCode.TAB) { return } var b = $(':tabbable', this), first = b.filter(':first')[0], last = b.filter(':last')[0]; if (a.target == last && !a.shiftKey) { setTimeout(function() { first.focus() }, 1) } else if (a.target == first && a.shiftKey) { setTimeout(function() { last.focus() }, 1) } })); $([]).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 }, _createButtons: function(c) { var d = this, hasButtons = false, uiDialogButtonPane = $('<div></div>').addClass('ui-dialog-buttonpane ' + 'ui-widget-content ' + 'ui-helper-clearfix'); this.uiDialog.find('.ui-dialog-buttonpane').remove(); (typeof c == 'object' && c !== null && $.each(c, function() { return !(hasButtons = true) })); if (hasButtons) { $.each(c, function(a, b) { $('<button type="button"></button>').addClass('ui-state-default ' + 'ui-corner-all').text(a).click(function() { b.apply(d.element[0], arguments) }).hover(function() { $(this).addClass('ui-state-hover') }, function() { $(this).removeClass('ui-state-hover') }).focus(function() { $(this).addClass('ui-state-focus') }).blur(function() { $(this).removeClass('ui-state-focus') }).appendTo(uiDialogButtonPane) }); uiDialogButtonPane.appendTo(this.uiDialog) } }, _makeDraggable: function() { var a = this, options = this.options, heightBeforeDrag; this.uiDialog.draggable({ cancel: '.ui-dialog-content', handle: '.ui-dialog-titlebar', containment: 'document', start: function() { heightBeforeDrag = options.height; $(this).height($(this).height()).addClass("ui-dialog-dragging"); (options.dragStart && options.dragStart.apply(a.element[0], arguments)) }, drag: function() { (options.drag && options.drag.apply(a.element[0], arguments)) }, stop: function() { $(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag); (options.dragStop && options.dragStop.apply(a.element[0], arguments)); $.ui.dialog.overlay.resize() } }) }, _makeResizable: function(a) { a = (a === undefined ? this.options.resizable : a); var b = this, options = this.options, resizeHandles = typeof a == 'string' ? a : 'n,e,s,w,se,sw,ne,nw'; this.uiDialog.resizable({ cancel: '.ui-dialog-content', alsoResize: this.element, maxWidth: options.maxWidth, maxHeight: options.maxHeight, minWidth: options.minWidth, minHeight: options.minHeight, start: function() { $(this).addClass("ui-dialog-resizing"); (options.resizeStart && options.resizeStart.apply(b.element[0], arguments)) }, resize: function() { (options.resize && options.resize.apply(b.element[0], arguments)) }, handles: resizeHandles, stop: function() { $(this).removeClass("ui-dialog-resizing"); options.height = $(this).height(); options.width = $(this).width(); (options.resizeStop && options.resizeStop.apply(b.element[0], arguments)); $.ui.dialog.overlay.resize() } }).find('.ui-resizable-se').addClass('ui-icon ui-icon-grip-diagonal-se') }, _position: function(a) { var b = $(window), doc = $(document), pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), minTop = pTop; if ($.inArray(a, ['center', 'top', 'right', 'bottom', 'left']) >= 0) { a = [a == 'right' || a == 'left' ? a : 'center', a == 'top' || a == 'bottom' ? a : 'middle'] } if (a.constructor != Array) { a = ['center', 'middle'] } if (a[0].constructor == Number) { pLeft += a[0] } else { switch (a[0]) { case 'left': pLeft += 0; break; case 'right': pLeft += b.width() - this.uiDialog.outerWidth(); break; default: case 'center': pLeft += (b.width() - this.uiDialog.outerWidth()) / 2 } } if (a[1].constructor == Number) { pTop += a[1] } else { switch (a[1]) { case 'top': pTop += 0; break; case 'bottom': pTop += b.height() - this.uiDialog.outerHeight(); break; default: case 'middle': pTop += (b.height() - this.uiDialog.outerHeight()) / 2 } } pTop = Math.max(pTop, minTop); this.uiDialog.css({ top: pTop, left: pLeft }) }, _setData: function(a, b) { (e[a] && this.uiDialog.data(e[a], b)); switch (a) { case "buttons": this._createButtons(b); break; case "closeText": this.uiDialogTitlebarCloseText.text(b); break; case "dialogClass": this.uiDialog.removeClass(this.options.dialogClass).addClass(uiDialogClasses + b); break; case "draggable": (b ? this._makeDraggable() : this.uiDialog.draggable('destroy')); break; case "height": this.uiDialog.height(b); break; case "position": this._position(b); break; case "resizable": var c = this.uiDialog, isResizable = this.uiDialog.is(':data(resizable)'); (isResizable && !b && c.resizable('destroy')); (isResizable && typeof b == 'string' && c.resizable('option', 'handles', b)); (isResizable || this._makeResizable(b)); break; case "title": $(".ui-dialog-title", this.uiDialogTitlebar).html(b || '&nbsp;'); break; case "width": this.uiDialog.width(b); break } $.widget.prototype._setData.apply(this, arguments) }, _size: function() { var a = this.options; this.element.css({ height: 0, minHeight: 0, width: 'auto' }); var b = this.uiDialog.css({ height: 'auto', width: a.width }).height(); this.element.css({ minHeight: Math.max(a.minHeight - b, 0), height: a.height == 'auto' ? 'auto' : Math.max(a.height - b, 0) }) } }); $.extend($.ui.dialog, { version: "1.7.2", defaults: { autoOpen: true, bgiframe: false, buttons: {}, closeOnEscape: true, closeText: 'close', dialogClass: '', draggable: true, hide: null, height: 'auto', maxHeight: false, maxWidth: false, minHeight: 150, minWidth: 150, modal: false, position: 'center', resizable: true, show: null, stack: true, title: '', width: 300, zIndex: 1000 }, getter: 'isOpen', uuid: 0, maxZ: 0, getTitleId: function(a) { return 'ui-dialog-title-' + (a.attr('id') || ++this.uuid) }, overlay: function(a) { this.$el = $.ui.dialog.overlay.create(a) } }); $.extend($.ui.dialog.overlay, { instances: [], maxZ: 0, events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','), function(a) { return a + '.dialog-overlay' }).join(' '), create: function(c) { if (this.instances.length === 0) { setTimeout(function() { if ($.ui.dialog.overlay.instances.length) { $(document).bind($.ui.dialog.overlay.events, function(a) { var b = $(a.target).parents('.ui-dialog').css('zIndex') || 0; return (b > $.ui.dialog.overlay.maxZ) }) } }, 1); $(document).bind('keydown.dialog-overlay', function(a) { (c.options.closeOnEscape && a.keyCode && a.keyCode == $.ui.keyCode.ESCAPE && c.close(a)) }); $(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize) } var d = $('<div></div>').appendTo(document.body).addClass('ui-widget-overlay').css({ width: this.width(), height: this.height() }); (c.options.bgiframe && $.fn.bgiframe && d.bgiframe()); this.instances.push(d); return d }, destroy: function(a) { this.instances.splice($.inArray(this.instances, a), 1); if (this.instances.length === 0) { $([document, window]).unbind('.dialog-overlay') } a.remove(); var b = 0; $.each(this.instances, function() { b = Math.max(b, this.css('z-index')) }); this.maxZ = b }, height: function() { if ($.browser.msie && $.browser.version < 7) { var a = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight); var b = Math.max(document.documentElement.offsetHeight, document.body.offsetHeight); if (a < b) { return $(window).height() + 'px' } else { return a + 'px' } } else { return $(document).height() + 'px' } }, width: function() { if ($.browser.msie && $.browser.version < 7) { var a = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth); var b = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth); if (a < b) { return $(window).width() + 'px' } else { return a + 'px' } } else { return $(document).width() + 'px' } }, resize: function() { var a = $([]); $.each($.ui.dialog.overlay.instances, function() { a = a.add(this) }); a.css({ width: 0, height: 0 }).css({ width: $.ui.dialog.overlay.width(), height: $.ui.dialog.overlay.height() }) } }); $.extend($.ui.dialog.overlay.prototype, { destroy: function() { $.ui.dialog.overlay.destroy(this.$el) } }) })(jQuery);
