Skip to content

Commit f003dff

Browse files
committed
Dialog: Remove attroperty workaround for title attribute. Make the default null, as it should be. No back-compat, as the behaviour doesn't change.
1 parent 628ae73 commit f003dff

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

tests/unit/dialog/dialog_common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TestHelpers.commonWidgetTests( "dialog", {
2323
},
2424
resizable: true,
2525
show: null,
26-
title: '',
26+
title: null,
2727
width: 300,
2828

2929
// callbacks

tests/unit/dialog/dialog_options.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -415,37 +415,45 @@ test("resizable", function() {
415415
el.remove();
416416
});
417417

418-
test("title", function() {
419-
expect(9);
418+
test( "title", function() {
419+
expect( 11 );
420420

421421
function titleText() {
422-
return el.dialog('widget').find(".ui-dialog-title").html();
422+
return el.dialog('widget').find( ".ui-dialog-title" ).html();
423423
}
424424

425-
var el = $('<div></div>').dialog();
425+
var el = $( '<div></div>' ).dialog();
426426
// some browsers return a non-breaking space and some return "&nbsp;"
427427
// so we generate a non-breaking space for comparison
428-
equal(titleText(), $( "<span>&#160;</span>" ).html(), "[default]");
429-
equal(el.dialog("option", "title"), "", "option not changed");
428+
equal( titleText(), $( "<span>&#160;</span>" ).html(), "[default]" );
429+
equal( el.dialog( "option", "title" ), null, "option not changed" );
430+
el.remove();
431+
432+
el = $( '<div title="foo">' ).dialog();
433+
equal( titleText(), "foo", "title in element attribute" );
434+
equal( el.dialog( "option", "title"), "foo", "option updated from attribute" );
430435
el.remove();
431436

432-
el = $('<div title="foo">').dialog();
433-
equal(titleText(), "foo", "title in element attribute");
434-
equal(el.dialog("option", "title"), "foo", "option updated from attribute");
437+
el = $( '<div></div>' ).dialog({ title: 'foo' });
438+
equal( titleText(), "foo", "title in init options" );
439+
equal( el.dialog("option", "title"), "foo", "opiton set from options hash" );
435440
el.remove();
436441

437-
el = $('<div></div>').dialog({ title: 'foo' });
438-
equal(titleText(), "foo", "title in init options");
439-
equal(el.dialog("option", "title"), "foo", "opiton set from options hash");
442+
el = $( '<div title="foo">' ).dialog({ title: 'bar' });
443+
equal( titleText(), "bar", "title in init options should override title in element attribute" );
444+
equal( el.dialog("option", "title"), "bar", "opiton set from options hash" );
440445
el.remove();
441446

442-
el = $('<div title="foo">').dialog({ title: 'bar' });
443-
equal(titleText(), "bar", "title in init options should override title in element attribute");
444-
equal(el.dialog("option", "title"), "bar", "opiton set from options hash");
447+
el = $( '<div></div>' ).dialog().dialog( 'option', 'title', 'foo' );
448+
equal( titleText(), 'foo', 'title after init' );
445449
el.remove();
446450

447-
el = $('<div></div>').dialog().dialog('option', 'title', 'foo');
448-
equal(titleText(), 'foo', 'title after init');
451+
// make sure attroperties are properly ignored - #5742 - .attr() might return a DOMElement
452+
el = $( '<form><input name="title"></form>' ).dialog();
453+
// some browsers return a non-breaking space and some return "&nbsp;"
454+
// so we get the text to normalize to the actual non-breaking space
455+
equal( titleText(), $( "<span>&#160;</span>" ).html(), "[default]" );
456+
equal( el.dialog( "option", "title" ), null, "option not changed" );
449457
el.remove();
450458
});
451459

ui/jquery.ui.dialog.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ $.widget("ui.dialog", {
6767
},
6868
resizable: true,
6969
show: null,
70-
title: "",
70+
title: null,
7171
width: 300,
7272

7373
// callbacks
@@ -85,16 +85,11 @@ $.widget("ui.dialog", {
8585

8686
_create: function() {
8787
this.originalTitle = this.element.attr( "title" );
88-
// #5742 - .attr() might return a DOMElement
89-
// TODO WTF?
90-
if ( typeof this.originalTitle !== "string" ) {
91-
this.originalTitle = "";
92-
}
88+
this.options.title = this.options.title || this.originalTitle;
9389
this.oldPosition = {
9490
parent: this.element.parent(),
9591
index: this.element.parent().children().index( this.element )
9692
};
97-
this.options.title = this.options.title || this.originalTitle;
9893
var that = this,
9994
options = this.options,
10095

0 commit comments

Comments
 (0)