Dialog: Remove attroperty workaround for title attribute. Make the default null, as it should be. No back-compat, as the behaviour doesn't change.

This commit is contained in:
Jörn Zaefferer 2012-11-09 18:26:30 +01:00
parent 628ae73e6c
commit f003dffb57
3 changed files with 28 additions and 25 deletions

View File

@ -23,7 +23,7 @@ TestHelpers.commonWidgetTests( "dialog", {
}, },
resizable: true, resizable: true,
show: null, show: null,
title: '', title: null,
width: 300, width: 300,
// callbacks // callbacks

View File

@ -415,37 +415,45 @@ test("resizable", function() {
el.remove(); el.remove();
}); });
test("title", function() { test( "title", function() {
expect(9); expect( 11 );
function titleText() { function titleText() {
return el.dialog('widget').find(".ui-dialog-title").html(); return el.dialog('widget').find( ".ui-dialog-title" ).html();
} }
var el = $('<div></div>').dialog(); var el = $( '<div></div>' ).dialog();
// some browsers return a non-breaking space and some return "&nbsp;" // some browsers return a non-breaking space and some return "&nbsp;"
// so we generate a non-breaking space for comparison // so we generate a non-breaking space for comparison
equal(titleText(), $( "<span>&#160;</span>" ).html(), "[default]"); equal( titleText(), $( "<span>&#160;</span>" ).html(), "[default]" );
equal(el.dialog("option", "title"), "", "option not changed"); equal( el.dialog( "option", "title" ), null, "option not changed" );
el.remove(); el.remove();
el = $('<div title="foo">').dialog(); el = $( '<div title="foo">' ).dialog();
equal(titleText(), "foo", "title in element attribute"); equal( titleText(), "foo", "title in element attribute" );
equal(el.dialog("option", "title"), "foo", "option updated from attribute"); equal( el.dialog( "option", "title"), "foo", "option updated from attribute" );
el.remove(); el.remove();
el = $('<div></div>').dialog({ title: 'foo' }); el = $( '<div></div>' ).dialog({ title: 'foo' });
equal(titleText(), "foo", "title in init options"); equal( titleText(), "foo", "title in init options" );
equal(el.dialog("option", "title"), "foo", "opiton set from options hash"); equal( el.dialog("option", "title"), "foo", "opiton set from options hash" );
el.remove(); el.remove();
el = $('<div title="foo">').dialog({ title: 'bar' }); el = $( '<div title="foo">' ).dialog({ title: 'bar' });
equal(titleText(), "bar", "title in init options should override title in element attribute"); equal( titleText(), "bar", "title in init options should override title in element attribute" );
equal(el.dialog("option", "title"), "bar", "opiton set from options hash"); equal( el.dialog("option", "title"), "bar", "opiton set from options hash" );
el.remove(); el.remove();
el = $('<div></div>').dialog().dialog('option', 'title', 'foo'); el = $( '<div></div>' ).dialog().dialog( 'option', 'title', 'foo' );
equal(titleText(), 'foo', 'title after init'); equal( titleText(), 'foo', 'title after init' );
el.remove();
// make sure attroperties are properly ignored - #5742 - .attr() might return a DOMElement
el = $( '<form><input name="title"></form>' ).dialog();
// some browsers return a non-breaking space and some return "&nbsp;"
// so we get the text to normalize to the actual non-breaking space
equal( titleText(), $( "<span>&#160;</span>" ).html(), "[default]" );
equal( el.dialog( "option", "title" ), null, "option not changed" );
el.remove(); el.remove();
}); });

View File

@ -67,7 +67,7 @@ $.widget("ui.dialog", {
}, },
resizable: true, resizable: true,
show: null, show: null,
title: "", title: null,
width: 300, width: 300,
// callbacks // callbacks
@ -85,16 +85,11 @@ $.widget("ui.dialog", {
_create: function() { _create: function() {
this.originalTitle = this.element.attr( "title" ); this.originalTitle = this.element.attr( "title" );
// #5742 - .attr() might return a DOMElement this.options.title = this.options.title || this.originalTitle;
// TODO WTF?
if ( typeof this.originalTitle !== "string" ) {
this.originalTitle = "";
}
this.oldPosition = { this.oldPosition = {
parent: this.element.parent(), parent: this.element.parent(),
index: this.element.parent().children().index( this.element ) index: this.element.parent().children().index( this.element )
}; };
this.options.title = this.options.title || this.originalTitle;
var that = this, var that = this,
options = this.options, options = this.options,