r2475 - Dialog: Using local variables to improve minification.
Author: scott.gonzalez
Date: Sat Apr 18 08:01:13 2009
New Revision: 2475
Modified:
trunk/ui/ui.dialog.js
Log:
Dialog: Using local variables to improve minification.
Modified: trunk/ui/ui.dialog.js
==============================================================================
--- trunk/ui/ui.dialog.js (original)
+++ trunk/ui/ui.dialog.js Sat Apr 18 08:01:13 2009
@@ -39,12 +39,12 @@
this.originalTitle = this.element.attr('title');
var self = this,
- options = this.options,
+ options = self.options,
- title = options.title || this.originalTitle || ' ',
- titleId = $.ui.dialog.getTitleId(this.element),
+ title = options.title || self.originalTitle || ' ',
+ titleId = $.ui.dialog.getTitleId(self.element),
- uiDialog = (this.uiDialog = $('<div/>'))
+ uiDialog = (self.uiDialog = $('<div/>'))
.appendTo(document.body)
.hide()
.addClass(uiDialogClasses + options.dialogClass)
@@ -67,7 +67,7 @@
self.moveToTop(false, event);
}),
- uiDialogContent = this.element
+ uiDialogContent = self.element
.show()
.removeAttr('title')
.addClass(
@@ -75,7 +75,7 @@
'ui-widget-content')
.appendTo(uiDialog),
- uiDialogTitlebar = (this.uiDialogTitlebar = $('<div></div>'))
+ uiDialogTitlebar = (self.uiDialogTitlebar = $('<div></div>'))
.addClass(
'ui-dialog-titlebar ' +
'ui-widget-header ' +
@@ -113,7 +113,7 @@
})
.appendTo(uiDialogTitlebar),
- uiDialogTitlebarCloseText = (this.uiDialogTitlebarCloseText =
$('<span/>'))
+ uiDialogTitlebarCloseText = (self.uiDialogTitlebarCloseText =
$('<span/>'))
.addClass(
'ui-icon ' +
'ui-icon-closethick'
@@ -129,29 +129,31 @@
uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection();
- (options.draggable && $.fn.draggable && this._makeDraggable());
- (options.resizable && $.fn.resizable && this._makeResizable());
+ (options.draggable && $.fn.draggable && self._makeDraggable());
+ (options.resizable && $.fn.resizable && self._makeResizable());
- this._createButtons(options.buttons);
- this._isOpen = false;
+ self._createButtons(options.buttons);
+ self._isOpen = false;
(options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe());
- (options.autoOpen && this.open());
+ (options.autoOpen && self.open());
},
destroy: function() {
- (this.overlay && this.overlay.destroy());
- this.uiDialog.hide();
- this.element
+ var self = this;
+
+ (self.overlay && self.overlay.destroy());
+ self.uiDialog.hide();
+ self.element
.unbind('.dialog')
.removeData('dialog')
.removeClass('ui-dialog-content ui-widget-content')
.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) {
@@ -195,38 +197,42 @@
// the force parameter allows us to move modal dialogs to their correct
// position on open
moveToTop: function(force, event) {
- if ((this.options.modal && !force)
- || (!this.options.stack && !this.options.modal)) {
- return this._trigger('focus', event);
+ var self = this,
+ options = self.options;
+
+ if ((options.modal && !force)
+ || (!options.stack && !options.modal)) {
+ return self._trigger('focus', event);
}
- if (this.options.zIndex > $.ui.dialog.maxZ) {
- $.ui.dialog.maxZ = this.options.zIndex;
+ if (options.zIndex > $.ui.dialog.maxZ) {
+ $.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.
// http://ui.jquery.com/bugs/ticket/3193
- var saveScroll = { scrollTop: this.element.attr('scrollTop'),
scrollLeft: this.element.attr('scrollLeft') };
- this.uiDialog.css('z-index', ++$.ui.dialog.maxZ);
- this.element.attr(saveScroll);
- this._trigger('focus', event);
+ var saveScroll = { scrollTop: self.element.attr('scrollTop'),
scrollLeft: self.element.attr('scrollLeft') };
+ self.uiDialog.css('z-index', ++$.ui.dialog.maxZ);
+ self.element.attr(saveScroll);
+ self._trigger('focus', event);
- return this;
+ return self;
},
open: function() {
if (this._isOpen) { return; }
- var options = this.options,
- uiDialog = this.uiDialog;
+ var self = this,
+ 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'));
- this._size();
- this._position(options.position);
+ self._size();
+ self._position(options.position);
uiDialog.show(options.show);
- this.moveToTop(true);
+ self.moveToTop(true);
// prevent tabbing out of modal dialogs
(options.modal && uiDialog.bind('keypress.ui-dialog', function(event) {
@@ -258,10 +264,10 @@
.filter(':first')
.focus();
- this._trigger('open');
- this._isOpen = true;
+ self._trigger('open');
+ self._isOpen = true;
- return this;
+ return self;
},
_createButtons: function(buttons) {
@@ -275,7 +281,7 @@
);
// 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 &&
$.each(buttons, function() { return !(hasButtons = true); }));
@@ -304,16 +310,16 @@
})
.appendTo(uiDialogButtonPane);
});
- uiDialogButtonPane.appendTo(this.uiDialog);
+ uiDialogButtonPane.appendTo(self.uiDialog);
}
},
_makeDraggable: function() {
var self = this,
- options = this.options,
+ options = self.options,
heightBeforeDrag;
- this.uiDialog.draggable({
+ self.uiDialog.draggable({
cancel: '.ui-dialog-content',
handle: '.ui-dialog-titlebar',
containment: 'document',
@@ -336,14 +342,14 @@
_makeResizable: function(handles) {
handles = (handles === undefined ? this.options.resizable : handles);
var self = this,
- options = this.options,
+ options = self.options,
resizeHandles = typeof handles == 'string'
? handles
: 'n,e,s,w,se,sw,ne,nw';
- this.uiDialog.resizable({
+ self.uiDialog.resizable({
cancel: '.ui-dialog-content',
- alsoResize: this.element,
+ alsoResize: self.element,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
minWidth: options.minWidth,
@@ -370,7 +376,8 @@
_position: function(pos) {
var wnd = $(window), doc = $(document),
pTop = doc.scrollTop(), pLeft = doc.scrollLeft(),
- minTop = pTop;
+ minTop = pTop,
+ uiDialog = this.uiDialog;
if ($.inArray(pos, ['center','top','right','bottom','left']) >= 0) {
pos = [
@@ -389,11 +396,11 @@
pLeft += 0;
break;
case 'right':
- pLeft += wnd.width() - this.uiDialog.outerWidth();
+ pLeft += wnd.width() - uiDialog.outerWidth();
break;
default:
case 'center':
- pLeft += (wnd.width() - this.uiDialog.outerWidth()) / 2;
+ pLeft += (wnd.width() - uiDialog.outerWidth()) / 2;
}
}
if (pos[1].constructor == Number) {
@@ -404,48 +411,50 @@
pTop += 0;
break;
case 'bottom':
- pTop += wnd.height() - this.uiDialog.outerHeight();
+ pTop += wnd.height() - uiDialog.outerHeight();
break;
default:
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
// is accessible)
pTop = Math.max(pTop, minTop);
- this.uiDialog.css({top: pTop, left: pLeft});
+ uiDialog.css({top: pTop, left: pLeft});
},
_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) {
case "buttons":
- this._createButtons(value);
+ self._createButtons(value);
break;
case "closeText":
- this.uiDialogTitlebarCloseText.text(value);
+ self.uiDialogTitlebarCloseText.text(value);
break;
case "dialogClass":
- this.uiDialog
- .removeClass(this.options.dialogClass)
+ uiDialog
+ .removeClass(self.options.dialogClass)
.addClass(uiDialogClasses + value);
break;
case "draggable":
(value
- ? this._makeDraggable()
- : this.uiDialog.draggable('destroy'));
+ ? self._makeDraggable()
+ : uiDialog.draggable('destroy'));
break;
case "height":
- this.uiDialog.height(value);
+ uiDialog.height(value);
break;
case "position":
- this._position(value);
+ self._position(value);
break;
case "resizable":
- var uiDialog = this.uiDialog,
- isResizable = this.uiDialog.is(':data(resizable)');
+ var isResizable = uiDialog.is(':data(resizable)');
// currently resizable, becoming non-resizable
(isResizable && !value && uiDialog.resizable('destroy'));
@@ -455,17 +464,17 @@
uiDialog.resizable('option', 'handles', value));
// currently non-resizable, becoming resizable
- (isResizable || this._makeResizable(value));
+ (isResizable || self._makeResizable(value));
break;
case "title":
- $(".ui-dialog-title", this.uiDialogTitlebar).html(value || ' ');
+ $(".ui-dialog-title", self.uiDialogTitlebar).html(value || ' ');
break;
case "width":
- this.uiDialog.width(value);
+ uiDialog.width(value);
break;
}
- $.widget.prototype._setData.apply(this, arguments);
+ $.widget.prototype._setData.apply(self, arguments);
},
_size: function() {