From b80fb723c5feb1cdedf545c6867d4d56511e24e6 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 3 Jun 2008 23:45:25 +0000 Subject: Dialog: restructured init method. --- ui/source/ui.dialog.js | 151 ++++++++++++++++++++++++------------------------- 1 file changed, 74 insertions(+), 77 deletions(-) (limited to 'ui/source/ui.dialog.js') diff --git a/ui/source/ui.dialog.js b/ui/source/ui.dialog.js index 9976c192a..d09cfc205 100644 --- a/ui/source/ui.dialog.js +++ b/ui/source/ui.dialog.js @@ -31,69 +31,61 @@ var setDataSwitch = { $.widget("ui.dialog", { init: function() { - var self = this; - var options = this.options; - - var uiDialogContent = this.element.addClass('ui-dialog-content'); + var self = this, + options = this.options, + + uiDialogContent = this.element + .addClass('ui-dialog-content') + .wrap('
') + .wrap('
'), + + uiDialogContainer = uiDialogContent.parent() + .addClass('ui-dialog-container') + .css({position: 'relative'}), + + title = options.title || uiDialogContent.attr('title') || '', + uiDialogTitlebar = (this.uiDialogTitlebar = + $('
')) + .append('' + title + '') + .append('X') + .prependTo(uiDialogContainer), + + uiDialog = (this.uiDialog = uiDialogContainer.parent()) + .hide() + .appendTo(document.body) + .addClass('ui-dialog') + .addClass(options.dialogClass) + // add content classes to dialog + // to inherit theme at top level of element + .addClass(uiDialogContent.attr('className')) + .removeClass('ui-dialog-content') + .css({ + position: 'absolute', + width: options.width, + height: options.height, + 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(ev) { + if (options.closeOnEscape) { + var ESC = 27; + (ev.keyCode && ev.keyCode == ESC && self.close()); + } + }) + .mousedown(function() { + self.moveToTop(); + }); - if (!uiDialogContent.parent().length) { - uiDialogContent.appendTo('body'); - } - uiDialogContent - .wrap(document.createElement('div')) - .wrap(document.createElement('div')); - var uiDialogContainer = uiDialogContent.parent().addClass('ui-dialog-container').css({position: 'relative'}); - var uiDialog = (this.uiDialog = uiDialogContainer.parent()).hide() - .addClass('ui-dialog').addClass(options.dialogClass) - .css({ - position: 'absolute', - width: options.width, - height: options.height, - overflow: 'hidden', - zIndex: options.zIndex - }); - - var classNames = uiDialogContent.attr('className').split(' '); - - // Add content classes to dialog, to inherit theme at top level of element - $.each(classNames, function(i, className) { - ((className != 'ui-dialog-content') - && uiDialog.addClass(className)); - }); - - if ($.fn.resizable) { - uiDialog.append('
') - .append('
') - .append('
') - .append('
') - .append('
') - .append('
') - .append('
') - .append('
'); - uiDialog.resizable({ - maxWidth: options.maxWidth, - maxHeight: options.maxHeight, - minWidth: options.minWidth, - minHeight: options.minHeight, - start: options.resizeStart, - resize: options.resize, - stop: function(e, ui) { - (options.resizeStop && options.resizeStop.apply(this, arguments)); - $.ui.dialog.overlay.resize(); - } - }); - (!options.resizable && uiDialog.resizable('disable')); - } - - uiDialogContainer.prepend('
'); - var uiDialogTitlebar = $('.ui-dialog-titlebar', uiDialogContainer); - this.uiDialogTitlebar = uiDialogTitlebar; - var title = (options.title) ? options.title : (uiDialogContent.attr('title')) ? uiDialogContent.attr('title') : ''; - uiDialogTitlebar.append('' + title + ''); - uiDialogTitlebar.append('X'); this.uiDialogTitlebarClose = $('.ui-dialog-titlebar-close', uiDialogTitlebar) - .hover(function() { $(this).addClass('ui-dialog-titlebar-close-hover'); }, - function() { $(this).removeClass('ui-dialog-titlebar-close-hover'); } + .hover( + function() { + $(this).addClass('ui-dialog-titlebar-close-hover'); + }, + function() { + $(this).removeClass('ui-dialog-titlebar-close-hover'); + } ) .mousedown(function(ev) { ev.stopPropagation(); @@ -103,22 +95,13 @@ $.widget("ui.dialog", { return false; }); - // setting tabindex makes the div focusable - // setting outline to 0 prevents a border on focus in Mozilla - uiDialog.attr('tabindex', -1).css('outline', 0).keydown(function(ev) { - if (options.closeOnEscape) { - var ESC = 27; - (ev.keyCode && ev.keyCode == ESC && self.close()); - } - }); - var hasButtons = false; $.each(options.buttons, function() { return !(hasButtons = true); }); if (hasButtons) { var uiDialogButtonPane = $('
') .appendTo(uiDialog); $.each(options.buttons, function(name, fn) { - $(document.createElement('button')) + $('