From 22384c9ba908409febaea569f46c0d3b2403ae65 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Sun, 17 Mar 2013 00:02:53 +0200 Subject: [PATCH] Dialog: Make options work on-the-fly. --- js/widgets/dialog.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/js/widgets/dialog.js b/js/widgets/dialog.js index 5dbd91c9190..bdc43d37485 100644 --- a/js/widgets/dialog.js +++ b/js/widgets/dialog.js @@ -29,8 +29,7 @@ $.widget( "mobile.dialog", $.mobile.widget, { }, _create: function() { - var self = this, - $el = this.element, + var $el = this.element, cornerClass = !!this.options.corners ? " ui-corner-all" : "", dialogWrap = $( "
", { "role" : "dialog", @@ -72,6 +71,25 @@ $.widget( "mobile.dialog", $.mobile.widget, { this._setCloseBtn( this.options.closeBtn ); }, + _setCorners: function( value ) { + this.element.children().toggleClass( "ui-corner-all", value ); + }, + + _setOverlayTheme: function( value ) { + this.element + .removeClass( "ui-overlay-" + this.options.overlayTheme ) + .addClass( "ui-overlay-" + value ); + if ( $.mobile.activePage[ 0 ] === this.element[ 0 ] ) { + this.options.overlayTheme = value; + this._handlePageBeforeShow(); + } + }, + + _setCloseBtnText: function( value ) { + this.options.closeBtnText = value; + this._setCloseBtn( this.options.closeBtn ); + }, + _setCloseBtn: function( value ) { var self = this, btn, location; @@ -104,9 +122,12 @@ $.widget( "mobile.dialog", $.mobile.widget, { }, _setOption: function( key, value ) { - if ( key === "closeBtn" ) { - this._setCloseBtn( value ); + var setter = "_set" + key.charAt( 0 ).toUpperCase() + key.slice( 1 ); + + if ( this[ setter ] !== undefined ) { + this[ setter ]( value ); } + this._super( key, value ); },