]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Remove attroperty workaround for title attribute. Make the default null,...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 9 Nov 2012 17:26:30 +0000 (18:26 +0100)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Mon, 26 Nov 2012 09:26:12 +0000 (10:26 +0100)
tests/unit/dialog/dialog_common.js
tests/unit/dialog/dialog_options.js
ui/jquery.ui.dialog.js

index fb29838b70608a4fa30bd5d4c791a18e3baeecb3..47fff101352ed0ded315434fcdd49789991415d7 100644 (file)
@@ -23,7 +23,7 @@ TestHelpers.commonWidgetTests( "dialog", {
                },
                resizable: true,
                show: null,
-               title: '',
+               title: null,
                width: 300,
 
                // callbacks
index 33123031898085b1a7a397a68eb59d33ed89c0ae..899dc1df67015bede4fbbce4a586cd7c7969481b 100644 (file)
@@ -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 = $('<div></div>').dialog();
+       var el = $( '<div></div>' ).dialog();
                // some browsers return a non-breaking space and some return "&nbsp;"
                // so we generate a non-breaking space for comparison
-               equal(titleText(), $( "<span>&#160;</span>" ).html(), "[default]");
-               equal(el.dialog("option", "title"), "", "option not changed");
+               equal( titleText(), $( "<span>&#160;</span>" ).html(), "[default]" );
+               equal( el.dialog( "option", "title" ), null, "option not changed" );
+       el.remove();
+
+       el = $( '<div title="foo">' ).dialog();
+               equal( titleText(), "foo", "title in element attribute" );
+               equal( el.dialog( "option", "title"), "foo", "option updated from attribute" );
        el.remove();
 
-       el = $('<div title="foo">').dialog();
-               equal(titleText(), "foo", "title in element attribute");
-               equal(el.dialog("option", "title"), "foo", "option updated from attribute");
+       el = $( '<div></div>' ).dialog({ title: 'foo' });
+               equal( titleText(), "foo", "title in init options" );
+               equal( el.dialog("option", "title"), "foo", "opiton set from options hash" );
        el.remove();
 
-       el = $('<div></div>').dialog({ title: 'foo' });
-               equal(titleText(), "foo", "title in init options");
-               equal(el.dialog("option", "title"), "foo", "opiton set from options hash");
+       el = $( '<div title="foo">' ).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 = $('<div title="foo">').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 = $( '<div></div>' ).dialog().dialog( 'option', 'title', 'foo' );
+               equal( titleText(), 'foo', 'title after init' );
        el.remove();
 
-       el = $('<div></div>').dialog().dialog('option', 'title', 'foo');
-               equal(titleText(), 'foo', 'title after init');
+       // 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();
 });
 
index ab32219c254412b7c7356f83b06fef14ab43d08b..451203cae5285f1bd15b13b1f3d02debc71cf293 100644 (file)
@@ -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,