From fed2972027f362181a614750fbaa7e252d1c1cb2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Zaefferer?= Date: Thu, 15 Nov 2012 22:51:26 +0100 Subject: [PATCH] Dialog: Refactor _setOption to call _super early. Move dialogClass update above that to access old option value. --- tests/unit/dialog/dialog_options.js | 5 ++++- ui/jquery.ui.dialog.js | 15 ++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index 2df7196dc..0be8c2b7f 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -148,7 +148,7 @@ test("closeText", function() { }); test("dialogClass", function() { - expect(4); + expect( 6 ); var el = $('
').dialog(); equal(el.dialog('widget').is(".foo"), false, 'dialogClass not specified. foo class added'); @@ -156,6 +156,9 @@ test("dialogClass", function() { el = $('
').dialog({ dialogClass: "foo" }); equal(el.dialog('widget').is(".foo"), true, 'dialogClass in init. foo class added'); + el.dialog( "option", "dialogClass", "foobar" ); + equal( el.dialog('widget').is(".foo"), false, "dialogClass changed, previous one was removed" ); + equal( el.dialog('widget').is(".foobar"), true, "dialogClass changed, new one was added" ); el.remove(); el = $('
').dialog({ dialogClass: "foo bar" }); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 055040b32..cb4230eac 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -565,6 +565,14 @@ $.widget("ui.dialog", { var isDraggable, isResizable, uiDialog = this.uiDialog; + if ( key === "dialogClass" ) { + uiDialog + .removeClass( this.options.dialogClass ) + .addClass( value ); + } + + this._super( key, value ); + switch ( key ) { case "buttons": this._createButtons( value ); @@ -575,11 +583,6 @@ $.widget("ui.dialog", { label: "" + value }); break; - case "dialogClass": - uiDialog - .removeClass( this.options.dialogClass ) - .addClass( value ); - break; case "disabled": // TODO use toggleClass( "ui-dialog-disabled", value ) if ( value ) { @@ -625,8 +628,6 @@ $.widget("ui.dialog", { .html( "" + ( value || " " ) ); break; } - - this._super( key, value ); }, _size: function() { -- 2.39.5