Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2a887e4
Dialog: Improve accessibilty - add an aria-describedby attribute on t…
jzaefferer Oct 26, 2012
8ee8046
Dialog: Keep focus inside modal dialog, by handling focus events on e…
jzaefferer Oct 26, 2012
0a25b2c
Dialog: move to top when opening again, and focus as if opened from s…
jzaefferer Oct 26, 2012
2062a18
Dialog: Inline code review
jzaefferer Oct 27, 2012
4632780
Dialog: Fix yoda-if, remove unnecessary TODOs; add missing callbacks …
jzaefferer Nov 9, 2012
b6cefc7
Dialog: Remove deprecated disableSelection() usage.
jzaefferer Nov 9, 2012
4e03321
Dialog: Trigger focus event when dialog is moved to top.
jzaefferer Nov 9, 2012
324d54d
Dialog: Use $.isEmptyObject() to check if there a button-option prope…
jzaefferer Nov 9, 2012
f7d3a51
Dialog: Only add the new dialogClass, not the base classes when chang…
jzaefferer Nov 9, 2012
6edce86
Dialog: Remove attroperty workaround for title attribute. Make the de…
jzaefferer Nov 9, 2012
0848040
Dialog: Focus tabbable only when dialog lost focus before.
jzaefferer Nov 9, 2012
83a9f21
Dialog: Use button widget for close button (was already listed as dep…
jzaefferer Nov 15, 2012
fed2972
Dialog: Refactor _setOption to call _super early. Move dialogClass up…
jzaefferer Nov 15, 2012
7e964be
Dialog: Have _createButtons access the buttons option directly. Start…
jzaefferer Nov 15, 2012
16a79c1
Dialog: Finish refactoring _setOption, getting rid of unnecessary swi…
jzaefferer Nov 15, 2012
c8aef20
Dialog: Have _makeResizable look at options instead of passing handles.
jzaefferer Nov 15, 2012
1001504
Dialog: Remove outdated TODO
jzaefferer Nov 15, 2012
7a03535
Dialog: Refactor the mousedown-bind call to use _on, removing the nee…
jzaefferer Nov 15, 2012
f0acaac
Dialog: Refactor uiDialogTitlebar variable, use this.uiDialogTitlebar…
jzaefferer Nov 15, 2012
1d6ce64
Dialog: Refactor _create, extracting title bar creation in _createTit…
jzaefferer Nov 15, 2012
4c9caa8
Dialog: Extract button pane creation into _createButtonPane
jzaefferer Nov 15, 2012
625a111
Dialog: Extracting wrapper creation into _createWrapper. Merging the …
jzaefferer Nov 15, 2012
0ae6fc1
Dialog: Remove useless tmp vars.
jzaefferer Nov 15, 2012
972f5c1
Dialog: Button is now a fixed dependency, so remove the check
jzaefferer Nov 15, 2012
0bc73b7
Dialog: Remove busted ui-dialog-disabled class, shouldn't be there. R…
jzaefferer Nov 15, 2012
e3dcaf2
Dialog: Remove uuid and getTitleId. Leftovers from 240b22b1439df22408…
jzaefferer Nov 15, 2012
d8b98ec
Dialog: Tiny code improvements
jzaefferer Nov 16, 2012
9996173
Dialog: Pass through icons and showText (as 'text') options to button…
jzaefferer Nov 16, 2012
b694409
Dialog: Extend visual test to verify DOM position restore on destroy;…
jzaefferer Nov 16, 2012
299681e
Dialog: Cleanup in ticket tests: TODO to merge one test, fix whitespace
jzaefferer Nov 16, 2012
b27db7e
Dialog: Extend autofocus, starting with [autofocus], then :tabbable c…
jzaefferer Nov 16, 2012
0be97bf
Dialog: Removed broken disabled option from dialog, defuse disable/en…
jzaefferer Nov 17, 2012
a0310eb
Dialog: Move array notation support for position option to backCompat…
jzaefferer Nov 17, 2012
41c2afd
Dialog: Refactor overlay handling into two instance methods. Remove u…
jzaefferer Nov 17, 2012
32a8931
Dialog: Improve _destroy method, detaching dialog content from wrappe…
jzaefferer Nov 17, 2012
5aac8f5
Dialog: Add missing unit test for aria-describedby attribute
jzaefferer Nov 17, 2012
73533d9
Dialog: Exclude deprecated units from phantomjs
jzaefferer Nov 17, 2012
f3525af
Dialog: Update focus-tabbable test with a timer workaround to get IE8…
jzaefferer Nov 17, 2012
a09f5c0
Dialog: Follow-up to 9fe3a62d8 - also deprecate string notation for p…
jzaefferer Nov 21, 2012
ec1f1bd
Dialog: Follow-up to c77ca67 - exclude button options from properties…
jzaefferer Nov 22, 2012
d179cba
Dialog: Update position when size is changed. Fixes #8789 - Dialog do…
kborchers Nov 25, 2012
60486ac
Dialog: Don't focus dialog when mousedown is on close button. Fixes #…
jzaefferer Nov 26, 2012
7e9060c
Dialog: Extract setting the title into a _title method, use .text() t…
jzaefferer Nov 26, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Dialog: Inline code review
  • Loading branch information
jzaefferer committed Nov 26, 2012
commit 2062a18db6eb1544c2f28d68b6f55d60eef0fd65
58 changes: 53 additions & 5 deletions ui/jquery.ui.dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,48 @@ $.widget("ui.dialog", {
resizable: true,
show: null,
title: "",
width: 300
width: 300,

// callbacks
beforeClose: null,
close: null,
drag: null,
dragStart: null,
dragStop: null,
focus: null,
open: null,
resize: null,
resizeStart: null,
resizeStop: null
},

_create: function() {
this.originalTitle = this.element.attr( "title" );
// #5742 - .attr() might return a DOMElement
// TODO WTF?
if ( typeof this.originalTitle !== "string" ) {
this.originalTitle = "";
}
this.oldPosition = {
parent: this.element.parent(),
index: this.element.parent().children().index( this.element )
};
// TODO don't overwrite options
this.options.title = this.options.title || this.originalTitle;
var that = this,
options = this.options,

// TODO make this the default for the title option?
title = options.title || " ",
// TODO should use this.uiDialog instead
uiDialog,
// TODO should use this.uiDialogTitlebar instead
uiDialogTitlebar,
uiDialogTitlebarClose,
uiDialogTitle,
uiDialogButtonPane;

// TODO extract into _createWrapper
uiDialog = ( this.uiDialog = $( "<div>" ) )
.addClass( uiDialogClasses + options.dialogClass )
.hide()
Expand All @@ -115,9 +133,10 @@ $.widget("ui.dialog", {
.addClass( "ui-dialog-content ui-widget-content" )
.appendTo( uiDialog );

// TODO extract this and the next three into a _createTitlebar method
uiDialogTitlebar = ( this.uiDialogTitlebar = $( "<div>" ) )
.addClass( "ui-dialog-titlebar ui-widget-header " +
"ui-corner-all ui-helper-clearfix" )
.addClass( "ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" )
// TODO use _on, call _focusTabbable or _keepFocus
.bind( "mousedown", function() {
// Dialog isn't getting focus when dragging (#8063)
uiDialog.focus();
Expand All @@ -144,18 +163,21 @@ $.widget("ui.dialog", {
.html( title )
.prependTo( uiDialogTitlebar );

// TODO extract this one and the next into a _createButtonPane method
uiDialogButtonPane = ( this.uiDialogButtonPane = $( "<div>" ) )
.addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" );

( this.uiButtonSet = $( "<div>" ) )
.addClass( "ui-dialog-buttonset" )
.appendTo( uiDialogButtonPane );

// TODO move into _createWrapper
uiDialog.attr({
role: "dialog",
"aria-labelledby": uiDialogTitle.attr( "id" )
});

// TODO move into _createWrapper
// We assume that any existing aria-describedby attribute means
// that the dialog content is marked up properly
// otherwise we brute force the content as the description
Expand All @@ -165,7 +187,11 @@ $.widget("ui.dialog", {
});
}

// TODO use andSelf()
// TODO get rid of this?! why do we need to disable selection anyway?
uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection();

// TODO use button? or at least a button element, so that SPACE works?
this._hoverable( uiDialogTitlebarClose );
this._focusable( uiDialogTitlebarClose );

Expand All @@ -176,10 +202,14 @@ $.widget("ui.dialog", {
this._makeResizable();
}

// TODO merge with _createButtonPane?
this._createButtons( options.buttons );

this._isOpen = false;

// prevent tabbing out of dialogs
// TODO move into _createWrapper
// TODO fix formatting
this._on( uiDialog, { keydown: function( event ) {
if ( event.keyCode !== $.ui.keyCode.TAB ) {
return;
Expand Down Expand Up @@ -217,13 +247,15 @@ $.widget("ui.dialog", {
.removeUniqueId()
.removeClass( "ui-dialog-content ui-widget-content" )
.hide()
// TODO restore old position directly, instead of appending to body first
.appendTo( "body" );
this.uiDialog.remove();

if ( this.originalTitle ) {
this.element.attr( "title", this.originalTitle );
}

// TODO do this before removing the wrapper
next = oldPosition.parent.children().eq( oldPosition.index );
// Don't try to place the dialog next to itself (#8613)
if ( next.length && next[ 0 ] !== this.element[ 0 ] ) {
Expand All @@ -244,6 +276,7 @@ $.widget("ui.dialog", {
return;
}

// TODO fix yoda-if
if ( false === this._trigger( "beforeClose", event ) ) {
return;
}
Expand All @@ -261,6 +294,7 @@ $.widget("ui.dialog", {
$( this.document[ 0 ].activeElement ).blur();
}

// TODO shouldn't _hide restore `this` to the instance? would also help tooltip
this._hide( this.uiDialog, this.options.hide, function() {
that._trigger( "close", event );
});
Expand All @@ -279,11 +313,14 @@ $.widget("ui.dialog", {

open: function() {
if ( this._isOpen ) {
// TODO don't pass silent flag? should probably trigger focus when moving to top again
this.moveToTop( null, true );
// TODO run this only when dialog wasn't focused?
this._focusTabbable();
return;
}

// TODO remove useless tmp vars
var options = this.options,
uiDialog = this.uiDialog;

Expand All @@ -304,6 +341,7 @@ $.widget("ui.dialog", {
return this;
},

// TODO check if dialog already has focus, merge with _keepFocus
_focusTabbable: function() {
// 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
Expand Down Expand Up @@ -342,6 +380,7 @@ $.widget("ui.dialog", {
this.uiDialogButtonPane.remove();
this.uiButtonSet.empty();

// TODO use jQuery.isEmptyObject()
if ( typeof buttons === "object" && buttons !== null ) {
$.each( buttons, function() {
return !(hasButtons = true);
Expand All @@ -363,6 +402,7 @@ $.widget("ui.dialog", {
button = $( "<button></button>", props )
.appendTo( that.uiButtonSet );
if ( $.fn.button ) {
// TODO allow passing through button options
button.button();
}
});
Expand Down Expand Up @@ -408,6 +448,7 @@ $.widget("ui.dialog", {
});
},

// TODO why are handles passed by _setOption??
_makeResizable: function( handles ) {
handles = (handles === undefined ? this.options.resizable : handles);
var that = this,
Expand Down Expand Up @@ -472,6 +513,7 @@ $.widget("ui.dialog", {
isVisible;

if ( position ) {
// TODO we don't support 1.3.2 anymore, clean this mess up
// deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
// if (typeof position == 'string' || $.isArray(position)) {
// myAt = $.isArray(position) ? position : position.split(' ');
Expand Down Expand Up @@ -551,9 +593,11 @@ $.widget("ui.dialog", {
case "dialogClass":
uiDialog
.removeClass( this.options.dialogClass )
// TODO why adding uiDialogClasses again? we didn't remove those
.addClass( uiDialogClasses + value );
break;
case "disabled":
// TODO use toggleClass( "ui-dialog-disabled", value )
if ( value ) {
uiDialog.addClass( "ui-dialog-disabled" );
} else {
Expand Down Expand Up @@ -591,7 +635,8 @@ $.widget("ui.dialog", {
}
break;
case "title":
// convert whatever was passed in o a string, for html() to not throw up
// convert whatever was passed in to a string, for html() to not throw up
// TODO deduplicate this (see _create)
$( ".ui-dialog-title", this.uiDialogTitlebar )
.html( "" + ( value || "&#160;" ) );
break;
Expand Down Expand Up @@ -643,8 +688,8 @@ $.widget("ui.dialog", {
});

$.extend($.ui.dialog, {
// TODO remove these
uuid: 0,

getTitleId: function($el) {
var id = $el.attr( "id" );
if ( !id ) {
Expand All @@ -654,17 +699,20 @@ $.extend($.ui.dialog, {
return "ui-dialog-title-" + id;
},

// TODO move to dialog instance method
overlay: function( dialog ) {
this.$el = $.ui.dialog.overlay.create( dialog );
}
});

// TODO get rid of instance list, at least the oldInstance stuff, and inline as dialog methods
$.extend( $.ui.dialog.overlay, {
instances: [],
// reuse old instances due to IE memory leak with alpha transparency (see #5185)
oldInstances: [],
create: function( dialog ) {
if ( this.instances.length === 0 ) {
// TODO get rid of the timeout, which should remove the need for the #4065 workaround as well
// prevent use of anchors and inputs
// we use a setTimeout in case the overlay is created from an
// event that we're going to be cancelling (see #2804)
Expand Down