@@ -11,6 +11,7 @@ define( [ "jquery", "../jquery.mobile.widget" ], function( $ ) {
11
11
12
12
$ . widget ( "mobile.dialog" , $ . mobile . widget , {
13
13
options : {
14
+ closeBtn : "left" ,
14
15
closeBtnText : "Close" ,
15
16
overlayTheme : "a" ,
16
17
corners : true ,
@@ -19,7 +20,6 @@ $.widget( "mobile.dialog", $.mobile.widget, {
19
20
_create : function ( ) {
20
21
var self = this ,
21
22
$el = this . element ,
22
- headerCloseButton = $ ( "<a href='#' data-" + $ . mobile . ns + "icon='delete' data-" + $ . mobile . ns + "iconpos='notext'>" + this . options . closeBtnText + "</a>" ) ,
23
23
cornerClass = ! ! this . options . corners ? " ui-corner-all" : "" ,
24
24
dialogWrap = $ ( "<div/>" , {
25
25
"role" : "dialog" ,
@@ -30,21 +30,7 @@ $.widget( "mobile.dialog", $.mobile.widget, {
30
30
31
31
// Class the markup for dialog styling
32
32
// 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 ) ;
48
34
49
35
/* bind events
50
36
- clicks and submits should use the closing transition that the dialog opened with
@@ -75,6 +61,46 @@ $.widget( "mobile.dialog", $.mobile.widget, {
75
61
. page ( "setContainerBackground" , self . options . overlayTheme ) ;
76
62
}
77
63
} ) ;
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
+ }
78
104
} ,
79
105
80
106
// Close method goes back in history
0 commit comments