Skip to content

Commit

Permalink
Dialog: Using local variables to improve minification.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed Apr 18, 2009
1 parent ddff678 commit a3c2a25
Showing 1 changed file with 75 additions and 66 deletions.
141 changes: 75 additions & 66 deletions ui/ui.dialog.js
Expand Up @@ -39,12 +39,12 @@ $.widget("ui.dialog", {
this.originalTitle = this.element.attr('title'); this.originalTitle = this.element.attr('title');


var self = this, var self = this,
options = this.options, options = self.options,


title = options.title || this.originalTitle || ' ', title = options.title || self.originalTitle || ' ',
titleId = $.ui.dialog.getTitleId(this.element), titleId = $.ui.dialog.getTitleId(self.element),


uiDialog = (this.uiDialog = $('<div/>')) uiDialog = (self.uiDialog = $('<div/>'))
.appendTo(document.body) .appendTo(document.body)
.hide() .hide()
.addClass(uiDialogClasses + options.dialogClass) .addClass(uiDialogClasses + options.dialogClass)
Expand All @@ -67,15 +67,15 @@ $.widget("ui.dialog", {
self.moveToTop(false, event); self.moveToTop(false, event);
}), }),


uiDialogContent = this.element uiDialogContent = self.element
.show() .show()
.removeAttr('title') .removeAttr('title')
.addClass( .addClass(
'ui-dialog-content ' + 'ui-dialog-content ' +
'ui-widget-content') 'ui-widget-content')
.appendTo(uiDialog), .appendTo(uiDialog),


uiDialogTitlebar = (this.uiDialogTitlebar = $('<div></div>')) uiDialogTitlebar = (self.uiDialogTitlebar = $('<div></div>'))
.addClass( .addClass(
'ui-dialog-titlebar ' + 'ui-dialog-titlebar ' +
'ui-widget-header ' + 'ui-widget-header ' +
Expand Down Expand Up @@ -113,7 +113,7 @@ $.widget("ui.dialog", {
}) })
.appendTo(uiDialogTitlebar), .appendTo(uiDialogTitlebar),


uiDialogTitlebarCloseText = (this.uiDialogTitlebarCloseText = $('<span/>')) uiDialogTitlebarCloseText = (self.uiDialogTitlebarCloseText = $('<span/>'))
.addClass( .addClass(
'ui-icon ' + 'ui-icon ' +
'ui-icon-closethick' 'ui-icon-closethick'
Expand All @@ -129,29 +129,31 @@ $.widget("ui.dialog", {


uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection(); uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection();


(options.draggable && $.fn.draggable && this._makeDraggable()); (options.draggable && $.fn.draggable && self._makeDraggable());
(options.resizable && $.fn.resizable && this._makeResizable()); (options.resizable && $.fn.resizable && self._makeResizable());


this._createButtons(options.buttons); self._createButtons(options.buttons);
this._isOpen = false; self._isOpen = false;


(options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe()); (options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe());
(options.autoOpen && this.open()); (options.autoOpen && self.open());
}, },


destroy: function() { destroy: function() {
(this.overlay && this.overlay.destroy()); var self = this;
this.uiDialog.hide();
this.element (self.overlay && self.overlay.destroy());
self.uiDialog.hide();
self.element
.unbind('.dialog') .unbind('.dialog')
.removeData('dialog') .removeData('dialog')
.removeClass('ui-dialog-content ui-widget-content') .removeClass('ui-dialog-content ui-widget-content')
.hide().appendTo('body'); .hide().appendTo('body');
this.uiDialog.remove(); self.uiDialog.remove();


(this.originalTitle && this.element.attr('title', this.originalTitle)); (self.originalTitle && self.element.attr('title', self.originalTitle));


return this; return self;
}, },


close: function(event) { close: function(event) {
Expand Down Expand Up @@ -195,38 +197,42 @@ $.widget("ui.dialog", {
// the force parameter allows us to move modal dialogs to their correct // the force parameter allows us to move modal dialogs to their correct
// position on open // position on open
moveToTop: function(force, event) { moveToTop: function(force, event) {
if ((this.options.modal && !force) var self = this,
|| (!this.options.stack && !this.options.modal)) { options = self.options;
return this._trigger('focus', event);
if ((options.modal && !force)
|| (!options.stack && !options.modal)) {
return self._trigger('focus', event);
} }


if (this.options.zIndex > $.ui.dialog.maxZ) { if (options.zIndex > $.ui.dialog.maxZ) {
$.ui.dialog.maxZ = this.options.zIndex; $.ui.dialog.maxZ = options.zIndex;
} }
(this.overlay && this.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = ++$.ui.dialog.maxZ)); (self.overlay && self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = ++$.ui.dialog.maxZ));


//Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed. //Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
// http://ui.jquery.com/bugs/ticket/3193 // http://ui.jquery.com/bugs/ticket/3193
var saveScroll = { scrollTop: this.element.attr('scrollTop'), scrollLeft: this.element.attr('scrollLeft') }; var saveScroll = { scrollTop: self.element.attr('scrollTop'), scrollLeft: self.element.attr('scrollLeft') };
this.uiDialog.css('z-index', ++$.ui.dialog.maxZ); self.uiDialog.css('z-index', ++$.ui.dialog.maxZ);
this.element.attr(saveScroll); self.element.attr(saveScroll);
this._trigger('focus', event); self._trigger('focus', event);


return this; return self;
}, },


open: function() { open: function() {
if (this._isOpen) { return; } if (this._isOpen) { return; }


var options = this.options, var self = this,
uiDialog = this.uiDialog; options = self.options,
uiDialog = self.uiDialog;


this.overlay = options.modal ? new $.ui.dialog.overlay(this) : null; self.overlay = options.modal ? new $.ui.dialog.overlay(self) : null;
(uiDialog.next().length && uiDialog.appendTo('body')); (uiDialog.next().length && uiDialog.appendTo('body'));
this._size(); self._size();
this._position(options.position); self._position(options.position);
uiDialog.show(options.show); uiDialog.show(options.show);
this.moveToTop(true); self.moveToTop(true);


// prevent tabbing out of modal dialogs // prevent tabbing out of modal dialogs
(options.modal && uiDialog.bind('keypress.ui-dialog', function(event) { (options.modal && uiDialog.bind('keypress.ui-dialog', function(event) {
Expand Down Expand Up @@ -258,10 +264,10 @@ $.widget("ui.dialog", {
.filter(':first') .filter(':first')
.focus(); .focus();


this._trigger('open'); self._trigger('open');
this._isOpen = true; self._isOpen = true;


return this; return self;
}, },


_createButtons: function(buttons) { _createButtons: function(buttons) {
Expand All @@ -275,7 +281,7 @@ $.widget("ui.dialog", {
); );


// if we already have a button pane, remove it // if we already have a button pane, remove it
this.uiDialog.find('.ui-dialog-buttonpane').remove(); self.uiDialog.find('.ui-dialog-buttonpane').remove();


(typeof buttons == 'object' && buttons !== null && (typeof buttons == 'object' && buttons !== null &&
$.each(buttons, function() { return !(hasButtons = true); })); $.each(buttons, function() { return !(hasButtons = true); }));
Expand Down Expand Up @@ -304,16 +310,16 @@ $.widget("ui.dialog", {
}) })
.appendTo(uiDialogButtonPane); .appendTo(uiDialogButtonPane);
}); });
uiDialogButtonPane.appendTo(this.uiDialog); uiDialogButtonPane.appendTo(self.uiDialog);
} }
}, },


_makeDraggable: function() { _makeDraggable: function() {
var self = this, var self = this,
options = this.options, options = self.options,
heightBeforeDrag; heightBeforeDrag;


this.uiDialog.draggable({ self.uiDialog.draggable({
cancel: '.ui-dialog-content', cancel: '.ui-dialog-content',
handle: '.ui-dialog-titlebar', handle: '.ui-dialog-titlebar',
containment: 'document', containment: 'document',
Expand All @@ -336,14 +342,14 @@ $.widget("ui.dialog", {
_makeResizable: function(handles) { _makeResizable: function(handles) {
handles = (handles === undefined ? this.options.resizable : handles); handles = (handles === undefined ? this.options.resizable : handles);
var self = this, var self = this,
options = this.options, options = self.options,
resizeHandles = typeof handles == 'string' resizeHandles = typeof handles == 'string'
? handles ? handles
: 'n,e,s,w,se,sw,ne,nw'; : 'n,e,s,w,se,sw,ne,nw';


this.uiDialog.resizable({ self.uiDialog.resizable({
cancel: '.ui-dialog-content', cancel: '.ui-dialog-content',
alsoResize: this.element, alsoResize: self.element,
maxWidth: options.maxWidth, maxWidth: options.maxWidth,
maxHeight: options.maxHeight, maxHeight: options.maxHeight,
minWidth: options.minWidth, minWidth: options.minWidth,
Expand All @@ -370,7 +376,8 @@ $.widget("ui.dialog", {
_position: function(pos) { _position: function(pos) {
var wnd = $(window), doc = $(document), var wnd = $(window), doc = $(document),
pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), pTop = doc.scrollTop(), pLeft = doc.scrollLeft(),
minTop = pTop; minTop = pTop,
uiDialog = this.uiDialog;


if ($.inArray(pos, ['center','top','right','bottom','left']) >= 0) { if ($.inArray(pos, ['center','top','right','bottom','left']) >= 0) {
pos = [ pos = [
Expand All @@ -389,11 +396,11 @@ $.widget("ui.dialog", {
pLeft += 0; pLeft += 0;
break; break;
case 'right': case 'right':
pLeft += wnd.width() - this.uiDialog.outerWidth(); pLeft += wnd.width() - uiDialog.outerWidth();
break; break;
default: default:
case 'center': case 'center':
pLeft += (wnd.width() - this.uiDialog.outerWidth()) / 2; pLeft += (wnd.width() - uiDialog.outerWidth()) / 2;
} }
} }
if (pos[1].constructor == Number) { if (pos[1].constructor == Number) {
Expand All @@ -404,48 +411,50 @@ $.widget("ui.dialog", {
pTop += 0; pTop += 0;
break; break;
case 'bottom': case 'bottom':
pTop += wnd.height() - this.uiDialog.outerHeight(); pTop += wnd.height() - uiDialog.outerHeight();
break; break;
default: default:
case 'middle': case 'middle':
pTop += (wnd.height() - this.uiDialog.outerHeight()) / 2; pTop += (wnd.height() - uiDialog.outerHeight()) / 2;
} }
} }


// prevent the dialog from being too high (make sure the titlebar // prevent the dialog from being too high (make sure the titlebar
// is accessible) // is accessible)
pTop = Math.max(pTop, minTop); pTop = Math.max(pTop, minTop);
this.uiDialog.css({top: pTop, left: pLeft}); uiDialog.css({top: pTop, left: pLeft});
}, },


_setData: function(key, value){ _setData: function(key, value){
(setDataSwitch[key] && this.uiDialog.data(setDataSwitch[key], value)); var self = this,
uiDialog = self.uiDialog;

(setDataSwitch[key] && uiDialog.data(setDataSwitch[key], value));
switch (key) { switch (key) {
case "buttons": case "buttons":
this._createButtons(value); self._createButtons(value);
break; break;
case "closeText": case "closeText":
this.uiDialogTitlebarCloseText.text(value); self.uiDialogTitlebarCloseText.text(value);
break; break;
case "dialogClass": case "dialogClass":
this.uiDialog uiDialog
.removeClass(this.options.dialogClass) .removeClass(self.options.dialogClass)
.addClass(uiDialogClasses + value); .addClass(uiDialogClasses + value);
break; break;
case "draggable": case "draggable":
(value (value
? this._makeDraggable() ? self._makeDraggable()
: this.uiDialog.draggable('destroy')); : uiDialog.draggable('destroy'));
break; break;
case "height": case "height":
this.uiDialog.height(value); uiDialog.height(value);
break; break;
case "position": case "position":
this._position(value); self._position(value);
break; break;
case "resizable": case "resizable":
var uiDialog = this.uiDialog, var isResizable = uiDialog.is(':data(resizable)');
isResizable = this.uiDialog.is(':data(resizable)');


// currently resizable, becoming non-resizable // currently resizable, becoming non-resizable
(isResizable && !value && uiDialog.resizable('destroy')); (isResizable && !value && uiDialog.resizable('destroy'));
Expand All @@ -455,17 +464,17 @@ $.widget("ui.dialog", {
uiDialog.resizable('option', 'handles', value)); uiDialog.resizable('option', 'handles', value));


// currently non-resizable, becoming resizable // currently non-resizable, becoming resizable
(isResizable || this._makeResizable(value)); (isResizable || self._makeResizable(value));
break; break;
case "title": case "title":
$(".ui-dialog-title", this.uiDialogTitlebar).html(value || '&nbsp;'); $(".ui-dialog-title", self.uiDialogTitlebar).html(value || '&nbsp;');
break; break;
case "width": case "width":
this.uiDialog.width(value); uiDialog.width(value);
break; break;
} }


$.widget.prototype._setData.apply(this, arguments); $.widget.prototype._setData.apply(self, arguments);
}, },


_size: function() { _size: function() {
Expand Down

0 comments on commit a3c2a25

Please sign in to comment.