@@ -11,6 +11,7 @@ define( [ "jquery", "../jquery.mobile.widget" ], function( $ ) {
1111
1212$ . widget ( "mobile.dialog" , $ . mobile . widget , {
1313 options : {
14+ closeBtn : "left" ,
1415 closeBtnText : "Close" ,
1516 overlayTheme : "a" ,
1617 corners : true ,
@@ -19,7 +20,6 @@ $.widget( "mobile.dialog", $.mobile.widget, {
1920 _create : function ( ) {
2021 var self = this ,
2122 $el = this . element ,
22- headerCloseButton = $ ( "<a href='#' data-" + $ . mobile . ns + "icon='delete' data-" + $ . mobile . ns + "iconpos='notext'>" + this . options . closeBtnText + "</a>" ) ,
2323 cornerClass = ! ! this . options . corners ? " ui-corner-all" : "" ,
2424 dialogWrap = $ ( "<div/>" , {
2525 "role" : "dialog" ,
@@ -30,21 +30,7 @@ $.widget( "mobile.dialog", $.mobile.widget, {
3030
3131 // Class the markup for dialog styling
3232 // Set aria role
33- $el
34- . wrapInner ( dialogWrap )
35- . children ( )
36- . find ( ":jqmData(role='header')" )
37- . prepend ( headerCloseButton ) ;
38-
39- // this must be an anonymous function so that select menu dialogs can replace
40- // the close method. This is a change from previously just defining data-rel=back
41- // on the button and letting nav handle it
42- //
43- // Use click rather than vclick in order to prevent the possibility of unintentionally
44- // reopening the dialog if the dialog opening item was directly under the close button.
45- headerCloseButton . bind ( "click" , function ( ) {
46- self . close ( ) ;
47- } ) ;
33+ $el . wrapInner ( dialogWrap ) ;
4834
4935 /* bind events
5036 - clicks and submits should use the closing transition that the dialog opened with
@@ -75,6 +61,46 @@ $.widget( "mobile.dialog", $.mobile.widget, {
7561 . page ( "setContainerBackground" , self . options . overlayTheme ) ;
7662 }
7763 } ) ;
64+
65+ this . _setCloseBtn ( this . options . closeBtn ) ;
66+ } ,
67+
68+ _setCloseBtn : function ( value ) {
69+ var self = this , btn , location ;
70+
71+ if ( this . _headerCloseButton ) {
72+ this . _headerCloseButton . remove ( ) ;
73+ this . _headerCloseButton = null ;
74+ }
75+ if ( value !== "none" ) {
76+ // Sanitize value
77+ location = ( value === "left" ? "left" : "right" ) ;
78+ btn = $ ( "<a href='#' class='ui-btn-" + location + "' data-" + $ . mobile . ns + "icon='delete' data-" + $ . mobile . ns + "iconpos='notext'>" + this . options . closeBtnText + "</a>" ) ;
79+ if ( $ . fn . buttonMarkup ) {
80+ btn . buttonMarkup ( ) ;
81+ }
82+ this . element . children ( ) . find ( ":jqmData(role='header')" ) . prepend ( btn ) ;
83+
84+ // this must be an anonymous function so that select menu dialogs can replace
85+ // the close method. This is a change from previously just defining data-rel=back
86+ // on the button and letting nav handle it
87+ //
88+ // Use click rather than vclick in order to prevent the possibility of unintentionally
89+ // reopening the dialog if the dialog opening item was directly under the close button.
90+ btn . bind ( "click" , function ( ) {
91+ self . close ( ) ;
92+ } ) ;
93+
94+ this . _headerCloseButton = btn ;
95+ }
96+ } ,
97+
98+ _setOption : function ( key , value ) {
99+ if ( key === "closeBtn" ) {
100+ this . _setCloseBtn ( value ) ;
101+ this . _super ( key , value ) ;
102+ this . element . attr ( "data-" + ( $ . mobile . ns || "" ) + "close-btn" , value ) ;
103+ }
78104 } ,
79105
80106 // Close method goes back in history
0 commit comments