Dialog: Remove uses of self var; use that var.

This commit is contained in:
Scott González 2012-05-09 16:00:21 -04:00
parent f76fbb8901
commit 8fcf7ea828

185
ui/jquery.ui.dialog.js vendored
View File

@ -83,13 +83,13 @@ $.widget("ui.dialog", {
index: this.element.parent().children().index( this.element ) index: this.element.parent().children().index( this.element )
}; };
this.options.title = this.options.title || this.originalTitle; this.options.title = this.options.title || this.originalTitle;
var self = this, var that = this,
options = self.options, options = this.options,
title = options.title || " ", title = options.title || " ",
titleId = $.ui.dialog.getTitleId( self.element ), titleId = $.ui.dialog.getTitleId( this.element ),
uiDialog = ( self.uiDialog = $( "<div>" ) ) uiDialog = ( this.uiDialog = $( "<div>" ) )
.addClass( uiDialogClasses + options.dialogClass ) .addClass( uiDialogClasses + options.dialogClass )
.css({ .css({
display: "none", display: "none",
@ -101,7 +101,7 @@ $.widget("ui.dialog", {
.keydown(function( event ) { .keydown(function( event ) {
if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
event.keyCode === $.ui.keyCode.ESCAPE ) { event.keyCode === $.ui.keyCode.ESCAPE ) {
self.close( event ); that.close( event );
event.preventDefault(); event.preventDefault();
} }
}) })
@ -110,17 +110,17 @@ $.widget("ui.dialog", {
"aria-labelledby": titleId "aria-labelledby": titleId
}) })
.mousedown(function( event ) { .mousedown(function( event ) {
self.moveToTop( false, event ); that.moveToTop( false, event );
}) })
.appendTo( "body" ), .appendTo( "body" ),
uiDialogContent = self.element uiDialogContent = this.element
.show() .show()
.removeAttr( "title" ) .removeAttr( "title" )
.addClass( "ui-dialog-content ui-widget-content" ) .addClass( "ui-dialog-content ui-widget-content" )
.appendTo( uiDialog ), .appendTo( uiDialog ),
uiDialogTitlebar = ( self.uiDialogTitlebar = $( "<div>" ) ) uiDialogTitlebar = ( this.uiDialogTitlebar = $( "<div>" ) )
.addClass( "ui-dialog-titlebar ui-widget-header " + .addClass( "ui-dialog-titlebar ui-widget-header " +
"ui-corner-all ui-helper-clearfix" ) "ui-corner-all ui-helper-clearfix" )
.prependTo( uiDialog ), .prependTo( uiDialog ),
@ -130,11 +130,11 @@ $.widget("ui.dialog", {
.attr( "role", "button" ) .attr( "role", "button" )
.click(function( event ) { .click(function( event ) {
event.preventDefault(); event.preventDefault();
self.close( event ); that.close( event );
}) })
.appendTo( uiDialogTitlebar ), .appendTo( uiDialogTitlebar ),
uiDialogTitlebarCloseText = ( self.uiDialogTitlebarCloseText = $( "<span>" ) ) uiDialogTitlebarCloseText = ( this.uiDialogTitlebarCloseText = $( "<span>" ) )
.addClass( "ui-icon ui-icon-closethick" ) .addClass( "ui-icon ui-icon-closethick" )
.text( options.closeText ) .text( options.closeText )
.appendTo( uiDialogTitlebarClose ), .appendTo( uiDialogTitlebarClose ),
@ -150,14 +150,14 @@ $.widget("ui.dialog", {
this._focusable( uiDialogTitlebarClose ); this._focusable( uiDialogTitlebarClose );
if ( options.draggable && $.fn.draggable ) { if ( options.draggable && $.fn.draggable ) {
self._makeDraggable(); this._makeDraggable();
} }
if ( options.resizable && $.fn.resizable ) { if ( options.resizable && $.fn.resizable ) {
self._makeResizable(); this._makeResizable();
} }
self._createButtons( options.buttons ); this._createButtons( options.buttons );
self._isOpen = false; this._isOpen = false;
if ( $.fn.bgiframe ) { if ( $.fn.bgiframe ) {
uiDialog.bgiframe(); uiDialog.bgiframe();
@ -171,28 +171,28 @@ $.widget("ui.dialog", {
}, },
_destroy: function() { _destroy: function() {
var self = this, next, var next,
oldPosition = this.oldPosition; oldPosition = this.oldPosition;
if ( self.overlay ) { if ( this.overlay ) {
self.overlay.destroy(); this.overlay.destroy();
} }
self.uiDialog.hide(); this.uiDialog.hide();
self.element this.element
.removeClass( "ui-dialog-content ui-widget-content" ) .removeClass( "ui-dialog-content ui-widget-content" )
.hide() .hide()
.appendTo( "body" ); .appendTo( "body" );
self.uiDialog.remove(); this.uiDialog.remove();
if ( self.originalTitle ) { if ( this.originalTitle ) {
self.element.attr( "title", self.originalTitle ); this.element.attr( "title", this.originalTitle );
} }
next = oldPosition.parent.children().eq( oldPosition.index ); next = oldPosition.parent.children().eq( oldPosition.index );
if ( next.length ) { if ( next.length ) {
next.before( self.element ); next.before( this.element );
} else { } else {
oldPosition.parent.append( self.element ); oldPosition.parent.append( this.element );
} }
}, },
@ -201,40 +201,40 @@ $.widget("ui.dialog", {
}, },
close: function( event ) { close: function( event ) {
var self = this, var that = this,
maxZ, thisZ; maxZ, thisZ;
if ( !this._isOpen ) { if ( !this._isOpen ) {
return; return;
} }
if ( false === self._trigger( "beforeClose", event ) ) { if ( false === this._trigger( "beforeClose", event ) ) {
return; return;
} }
self._isOpen = false; this._isOpen = false;
if ( self.overlay ) { if ( this.overlay ) {
self.overlay.destroy(); this.overlay.destroy();
} }
self.uiDialog.unbind( "keypress.ui-dialog" ); this.uiDialog.unbind( "keypress.ui-dialog" );
if ( self.options.hide ) { if ( this.options.hide ) {
self.uiDialog.hide( self.options.hide, function() { this.uiDialog.hide( this.options.hide, function() {
self._trigger( "close", event ); that._trigger( "close", event );
}); });
} else { } else {
self.uiDialog.hide(); this.uiDialog.hide();
self._trigger( "close", event ); this._trigger( "close", event );
} }
$.ui.dialog.overlay.resize(); $.ui.dialog.overlay.resize();
// adjust the maxZ to allow other modal dialogs to continue to work (see #4309) // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
if ( self.options.modal ) { if ( this.options.modal ) {
maxZ = 0; maxZ = 0;
$( ".ui-dialog" ).each(function() { $( ".ui-dialog" ).each(function() {
if ( this !== self.uiDialog[0] ) { if ( this !== that.uiDialog[0] ) {
thisZ = $( this ).css( "z-index" ); thisZ = $( this ).css( "z-index" );
if ( !isNaN( thisZ ) ) { if ( !isNaN( thisZ ) ) {
maxZ = Math.max( maxZ, thisZ ); maxZ = Math.max( maxZ, thisZ );
@ -244,7 +244,7 @@ $.widget("ui.dialog", {
$.ui.dialog.maxZ = maxZ; $.ui.dialog.maxZ = maxZ;
} }
return self; return this;
}, },
isOpen: function() { isOpen: function() {
@ -254,37 +254,36 @@ $.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 ) {
var self = this, var options = this.options,
options = self.options,
saveScroll; saveScroll;
if ( ( options.modal && !force ) || if ( ( options.modal && !force ) ||
( !options.stack && !options.modal ) ) { ( !options.stack && !options.modal ) ) {
return self._trigger( "focus", event ); return this._trigger( "focus", event );
} }
if ( options.zIndex > $.ui.dialog.maxZ ) { if ( options.zIndex > $.ui.dialog.maxZ ) {
$.ui.dialog.maxZ = options.zIndex; $.ui.dialog.maxZ = options.zIndex;
} }
if ( self.overlay ) { if ( this.overlay ) {
$.ui.dialog.maxZ += 1; $.ui.dialog.maxZ += 1;
$.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ; $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ;
self.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ ); this.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ );
} }
// Save and then restore scroll // Save and then restore scroll
// Opera 9.5+ resets when parent z-index is changed. // Opera 9.5+ resets when parent z-index is changed.
// http://bugs.jqueryui.com/ticket/3193 // http://bugs.jqueryui.com/ticket/3193
saveScroll = { saveScroll = {
scrollTop: self.element.scrollTop(), scrollTop: this.element.scrollTop(),
scrollLeft: self.element.scrollLeft() scrollLeft: this.element.scrollLeft()
}; };
$.ui.dialog.maxZ += 1; $.ui.dialog.maxZ += 1;
self.uiDialog.css( "z-index", $.ui.dialog.maxZ ); this.uiDialog.css( "z-index", $.ui.dialog.maxZ );
self.element.attr( saveScroll ); this.element.attr( saveScroll );
self._trigger( "focus", event ); this._trigger( "focus", event );
return self; return this;
}, },
open: function() { open: function() {
@ -293,15 +292,14 @@ $.widget("ui.dialog", {
} }
var hasFocus, var hasFocus,
self = this, options = this.options,
options = self.options, uiDialog = this.uiDialog;
uiDialog = self.uiDialog;
self._size(); this._size();
self._position( options.position ); this._position( options.position );
uiDialog.show( options.show ); uiDialog.show( options.show );
self.overlay = options.modal ? new $.ui.dialog.overlay( self ) : null; this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null;
self.moveToTop( true ); this.moveToTop( true );
// prevent tabbing out of modal dialogs // prevent tabbing out of modal dialogs
if ( options.modal ) { if ( options.modal ) {
@ -326,7 +324,7 @@ $.widget("ui.dialog", {
// set focus to the first tabbable element in the content area or the first button // 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 // if there are no tabbable elements, set focus on the dialog itself
hasFocus = self.element.find( ":tabbable" ); hasFocus = this.element.find( ":tabbable" );
if ( !hasFocus.length ) { if ( !hasFocus.length ) {
hasFocus = uiDialog.find( ".ui-dialog-buttonpane :tabbable" ); hasFocus = uiDialog.find( ".ui-dialog-buttonpane :tabbable" );
if ( !hasFocus.length ) { if ( !hasFocus.length ) {
@ -335,19 +333,19 @@ $.widget("ui.dialog", {
} }
hasFocus.eq( 0 ).focus(); hasFocus.eq( 0 ).focus();
self._isOpen = true; this._isOpen = true;
self._trigger( "open" ); this._trigger( "open" );
return self; return this;
}, },
_createButtons: function( buttons ) { _createButtons: function( buttons ) {
var uiDialogButtonPane, uiButtonSet, var uiDialogButtonPane, uiButtonSet,
self = this, that = this,
hasButtons = false; hasButtons = false;
// if we already have a button pane, remove it // if we already have a button pane, remove it
self.uiDialog.find( ".ui-dialog-buttonpane" ).remove(); this.uiDialog.find( ".ui-dialog-buttonpane" ).remove();
if ( typeof buttons === "object" && buttons !== null ) { if ( typeof buttons === "object" && buttons !== null ) {
$.each( buttons, function() { $.each( buttons, function() {
@ -369,23 +367,23 @@ $.widget("ui.dialog", {
.attr( props, true ) .attr( props, true )
.unbind( "click" ) .unbind( "click" )
.click(function() { .click(function() {
props.click.apply( self.element[0], arguments ); props.click.apply( that.element[0], arguments );
}) })
.appendTo( uiButtonSet ); .appendTo( uiButtonSet );
if ( $.fn.button ) { if ( $.fn.button ) {
button.button(); button.button();
} }
}); });
self.uiDialog.addClass( "ui-dialog-buttons" ); this.uiDialog.addClass( "ui-dialog-buttons" );
uiDialogButtonPane.appendTo( self.uiDialog ); uiDialogButtonPane.appendTo( this.uiDialog );
} else { } else {
self.uiDialog.removeClass( "ui-dialog-buttons" ); this.uiDialog.removeClass( "ui-dialog-buttons" );
} }
}, },
_makeDraggable: function() { _makeDraggable: function() {
var self = this, var that = this,
options = self.options; options = this.options;
function filteredUi( ui ) { function filteredUi( ui ) {
return { return {
@ -394,26 +392,26 @@ $.widget("ui.dialog", {
}; };
} }
self.uiDialog.draggable({ this.uiDialog.draggable({
cancel: ".ui-dialog-content, .ui-dialog-titlebar-close", cancel: ".ui-dialog-content, .ui-dialog-titlebar-close",
handle: ".ui-dialog-titlebar", handle: ".ui-dialog-titlebar",
containment: "document", containment: "document",
start: function( event, ui ) { start: function( event, ui ) {
$( this ) $( this )
.addClass( "ui-dialog-dragging" ); .addClass( "ui-dialog-dragging" );
self._trigger( "dragStart", event, filteredUi( ui ) ); that._trigger( "dragStart", event, filteredUi( ui ) );
}, },
drag: function( event, ui ) { drag: function( event, ui ) {
self._trigger( "drag", event, filteredUi( ui ) ); that._trigger( "drag", event, filteredUi( ui ) );
}, },
stop: function( event, ui ) { stop: function( event, ui ) {
options.position = [ options.position = [
ui.position.left - self.document.scrollLeft(), ui.position.left - that.document.scrollLeft(),
ui.position.top - self.document.scrollTop() ui.position.top - that.document.scrollTop()
]; ];
$( this ) $( this )
.removeClass( "ui-dialog-dragging" ); .removeClass( "ui-dialog-dragging" );
self._trigger( "dragStop", event, filteredUi( ui ) ); that._trigger( "dragStop", event, filteredUi( ui ) );
$.ui.dialog.overlay.resize(); $.ui.dialog.overlay.resize();
} }
}); });
@ -421,11 +419,11 @@ $.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 that = this,
options = self.options, options = this.options,
// .ui-resizable has position: relative defined in the stylesheet // .ui-resizable has position: relative defined in the stylesheet
// but dialogs have to use absolute or fixed positioning // but dialogs have to use absolute or fixed positioning
position = self.uiDialog.css( "position" ), position = this.uiDialog.css( "position" ),
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";
@ -439,27 +437,27 @@ $.widget("ui.dialog", {
}; };
} }
self.uiDialog.resizable({ this.uiDialog.resizable({
cancel: ".ui-dialog-content", cancel: ".ui-dialog-content",
containment: "document", containment: "document",
alsoResize: self.element, alsoResize: this.element,
maxWidth: options.maxWidth, maxWidth: options.maxWidth,
maxHeight: options.maxHeight, maxHeight: options.maxHeight,
minWidth: options.minWidth, minWidth: options.minWidth,
minHeight: self._minHeight(), minHeight: this._minHeight(),
handles: resizeHandles, handles: resizeHandles,
start: function( event, ui ) { start: function( event, ui ) {
$( this ).addClass( "ui-dialog-resizing" ); $( this ).addClass( "ui-dialog-resizing" );
self._trigger( "resizeStart", event, filteredUi( ui ) ); that._trigger( "resizeStart", event, filteredUi( ui ) );
}, },
resize: function( event, ui ) { resize: function( event, ui ) {
self._trigger( "resize", event, filteredUi( ui ) ); that._trigger( "resize", event, filteredUi( ui ) );
}, },
stop: function( event, ui ) { stop: function( event, ui ) {
$( this ).removeClass( "ui-dialog-resizing" ); $( this ).removeClass( "ui-dialog-resizing" );
options.height = $( this ).height(); options.height = $( this ).height();
options.width = $( this ).width(); options.width = $( this ).width();
self._trigger( "resizeStop", event, filteredUi( ui ) ); that._trigger( "resizeStop", event, filteredUi( ui ) );
$.ui.dialog.overlay.resize(); $.ui.dialog.overlay.resize();
} }
}) })
@ -525,12 +523,12 @@ $.widget("ui.dialog", {
}, },
_setOptions: function( options ) { _setOptions: function( options ) {
var self = this, var that = this,
resizableOptions = {}, resizableOptions = {},
resize = false; resize = false;
$.each( options, function( key, value ) { $.each( options, function( key, value ) {
self._setOption( key, value ); that._setOption( key, value );
if ( key in sizeRelatedOptions ) { if ( key in sizeRelatedOptions ) {
resize = true; resize = true;
@ -550,20 +548,19 @@ $.widget("ui.dialog", {
_setOption: function( key, value ) { _setOption: function( key, value ) {
var isDraggable, isResizable, var isDraggable, isResizable,
self = this, uiDialog = this.uiDialog;
uiDialog = self.uiDialog;
switch ( key ) { switch ( key ) {
case "buttons": case "buttons":
self._createButtons( value ); this._createButtons( value );
break; break;
case "closeText": case "closeText":
// ensure that we always pass a string // ensure that we always pass a string
self.uiDialogTitlebarCloseText.text( "" + value ); this.uiDialogTitlebarCloseText.text( "" + value );
break; break;
case "dialogClass": case "dialogClass":
uiDialog uiDialog
.removeClass( self.options.dialogClass ) .removeClass( this.options.dialogClass )
.addClass( uiDialogClasses + value ); .addClass( uiDialogClasses + value );
break; break;
case "disabled": case "disabled":
@ -580,11 +577,11 @@ $.widget("ui.dialog", {
} }
if ( !isDraggable && value ) { if ( !isDraggable && value ) {
self._makeDraggable(); this._makeDraggable();
} }
break; break;
case "position": case "position":
self._position( value ); this._position( value );
break; break;
case "resizable": case "resizable":
// currently resizable, becoming non-resizable // currently resizable, becoming non-resizable
@ -600,12 +597,12 @@ $.widget("ui.dialog", {
// currently non-resizable, becoming resizable // currently non-resizable, becoming resizable
if ( !isResizable && value !== false ) { if ( !isResizable && value !== false ) {
self._makeResizable( value ); this._makeResizable( value );
} }
break; break;
case "title": case "title":
// convert whatever was passed in o a string, for html() to not throw up // convert whatever was passed in o a string, for html() to not throw up
$( ".ui-dialog-title", self.uiDialogTitlebar ) $( ".ui-dialog-title", this.uiDialogTitlebar )
.html( "" + ( value || "&#160;" ) ); .html( "" + ( value || "&#160;" ) );
break; break;
} }