From 6edce867339c5808eda428fa2566aa40da4b0202 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Fri, 9 Nov 2012 18:26:30 +0100 Subject: [PATCH] Dialog: Remove attroperty workaround for title attribute. Make the default null, as it should be. No back-compat, as the behaviour doesn't change. --- tests/unit/dialog/dialog_common.js | 2 +- tests/unit/dialog/dialog_options.js | 42 +++++++++++++++++------------ ui/jquery.ui.dialog.js | 9 ++----- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/tests/unit/dialog/dialog_common.js b/tests/unit/dialog/dialog_common.js index fb29838b7..47fff1013 100644 --- a/tests/unit/dialog/dialog_common.js +++ b/tests/unit/dialog/dialog_common.js @@ -23,7 +23,7 @@ TestHelpers.commonWidgetTests( "dialog", { }, resizable: true, show: null, - title: '', + title: null, width: 300, // callbacks diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index 331230318..899dc1df6 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -415,37 +415,45 @@ test("resizable", function() { el.remove(); }); -test("title", function() { - expect(9); +test( "title", function() { + expect( 11 ); function titleText() { - return el.dialog('widget').find(".ui-dialog-title").html(); + return el.dialog('widget').find( ".ui-dialog-title" ).html(); } - var el = $('
').dialog(); + var el = $( '
' ).dialog(); // some browsers return a non-breaking space and some return " " // so we generate a non-breaking space for comparison - equal(titleText(), $( " " ).html(), "[default]"); - equal(el.dialog("option", "title"), "", "option not changed"); + equal( titleText(), $( " " ).html(), "[default]" ); + equal( el.dialog( "option", "title" ), null, "option not changed" ); + el.remove(); + + el = $( '
' ).dialog(); + equal( titleText(), "foo", "title in element attribute" ); + equal( el.dialog( "option", "title"), "foo", "option updated from attribute" ); el.remove(); - el = $('
').dialog(); - equal(titleText(), "foo", "title in element attribute"); - equal(el.dialog("option", "title"), "foo", "option updated from attribute"); + el = $( '
' ).dialog({ title: 'foo' }); + equal( titleText(), "foo", "title in init options" ); + equal( el.dialog("option", "title"), "foo", "opiton set from options hash" ); el.remove(); - el = $('
').dialog({ title: 'foo' }); - equal(titleText(), "foo", "title in init options"); - equal(el.dialog("option", "title"), "foo", "opiton set from options hash"); + el = $( '
' ).dialog({ title: 'bar' }); + equal( titleText(), "bar", "title in init options should override title in element attribute" ); + equal( el.dialog("option", "title"), "bar", "opiton set from options hash" ); el.remove(); - el = $('
').dialog({ title: 'bar' }); - equal(titleText(), "bar", "title in init options should override title in element attribute"); - equal(el.dialog("option", "title"), "bar", "opiton set from options hash"); + el = $( '
' ).dialog().dialog( 'option', 'title', 'foo' ); + equal( titleText(), 'foo', 'title after init' ); el.remove(); - el = $('
').dialog().dialog('option', 'title', 'foo'); - equal(titleText(), 'foo', 'title after init'); + // make sure attroperties are properly ignored - #5742 - .attr() might return a DOMElement + el = $( '
' ).dialog(); + // some browsers return a non-breaking space and some return " " + // so we get the text to normalize to the actual non-breaking space + equal( titleText(), $( " " ).html(), "[default]" ); + equal( el.dialog( "option", "title" ), null, "option not changed" ); el.remove(); }); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index ab32219c2..451203cae 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -67,7 +67,7 @@ $.widget("ui.dialog", { }, resizable: true, show: null, - title: "", + title: null, width: 300, // callbacks @@ -85,16 +85,11 @@ $.widget("ui.dialog", { _create: function() { this.originalTitle = this.element.attr( "title" ); - // #5742 - .attr() might return a DOMElement - // TODO WTF? - if ( typeof this.originalTitle !== "string" ) { - this.originalTitle = ""; - } + this.options.title = this.options.title || this.originalTitle; this.oldPosition = { parent: this.element.parent(), index: this.element.parent().children().index( this.element ) }; - this.options.title = this.options.title || this.originalTitle; var that = this, options = this.options, -- 2.39.5