4
4
* Dual licensed under the MIT or GPL Version 2 licenses.
5
5
* http://jquery.org/license
6
6
*/
7
- ( function ( $ , undefined ) {
7
+
8
+ ( function ( $ , undefined ) {
8
9
9
10
$ . widget ( "mobile.page" , $ . mobile . widget , {
10
11
options : {
@@ -33,38 +34,43 @@ $.widget( "mobile.page", $.mobile.widget, {
33
34
var $elem = this . element ,
34
35
o = this . options ;
35
36
36
- this . keepNative = ":jqmData(role='none'), :jqmData(role='nojs')" + ( o . keepNative ? ", " + o . keepNative : "" ) ;
37
+ this . keepNative = ":jqmData(role='none'), :jqmData(role='nojs')" +
38
+ ( o . keepNative ? ", " + o . keepNative : "" ) ;
37
39
38
40
if ( this . _trigger ( "beforeCreate" ) === false ) {
39
41
return ;
40
42
}
41
43
42
- //some of the form elements currently rely on the presence of ui-page and ui-content
44
+ // Some of the form elements currently rely on the presence of ui-page and ui-content
43
45
// classes so we'll handle page and content roles outside of the main role processing
44
46
// loop below.
45
47
$elem . find ( ":jqmData(role='page'), :jqmData(role='content')" ) . andSelf ( ) . each ( function ( ) {
46
- $ ( this ) . addClass ( "ui-" + $ ( this ) . jqmData ( "role" ) ) ;
48
+ var $this = $ ( this ) ;
49
+
50
+ $this . addClass ( "ui-" + $this . jqmData ( "role" ) ) ;
47
51
} ) ;
48
52
49
53
$elem . find ( ":jqmData(role='nojs')" ) . addClass ( "ui-nojs" ) ;
50
54
51
- // pre -find data els
55
+ // Pre -find data els
52
56
var $dataEls = $elem . find ( ":jqmData(role)" ) . andSelf ( ) . each ( function ( ) {
53
57
var $this = $ ( this ) ,
54
58
role = $this . jqmData ( "role" ) ,
55
- theme = $this . jqmData ( "theme" ) ;
59
+ theme = $this . jqmData ( "theme" ) ,
60
+ $headeranchors ,
61
+ leftbtn , rightbtn , backBtn ;
56
62
57
63
//apply theming and markup modifications to page,header,content,footer
58
64
if ( role === "header" || role === "footer" ) {
59
65
$this . addClass ( "ui-bar-" + ( theme || $this . parent ( ":jqmData(role='page')" ) . jqmData ( "theme" ) || "a" ) ) ;
60
66
61
- // add ARIA role
67
+ // Add ARIA role
62
68
$this . attr ( "role" , role === "header" ? "banner" : "contentinfo" ) ;
63
69
64
- //right ,left buttons
65
- var $headeranchors = $this . children ( "a" ) ,
66
- leftbtn = $headeranchors . hasClass ( "ui-btn-left" ) ,
67
- rightbtn = $headeranchors . hasClass ( "ui-btn-right" ) ;
70
+ // Right ,left buttons
71
+ $headeranchors = $this . children ( "a" ) ;
72
+ leftbtn = $headeranchors . hasClass ( "ui-btn-left" ) ;
73
+ rightbtn = $headeranchors . hasClass ( "ui-btn-right" ) ;
68
74
69
75
if ( ! leftbtn ) {
70
76
leftbtn = $headeranchors . eq ( 0 ) . not ( ".ui-btn-right" ) . addClass ( "ui-btn-left" ) . length ;
@@ -74,39 +80,44 @@ $.widget( "mobile.page", $.mobile.widget, {
74
80
rightbtn = $headeranchors . eq ( 1 ) . addClass ( "ui-btn-right" ) . length ;
75
81
}
76
82
77
- // auto -add back btn on pages beyond first view
83
+ // Auto -add back btn on pages beyond first view
78
84
if ( o . addBackBtn && role === "header" &&
79
85
$ ( ".ui-page" ) . length > 1 &&
80
86
$elem . jqmData ( "url" ) !== $ . mobile . path . stripHash ( location . hash ) &&
81
87
! leftbtn && $this . jqmData ( "backbtn" ) !== false ) {
82
88
83
- var backBtn = $ ( "<a href='#' class='ui-btn-left' data-" + $ . mobile . ns + "rel='back' data-" + $ . mobile . ns + "icon='arrow-l'>" + o . backBtnText + "</a>" ) . prependTo ( $this ) ;
84
-
85
- //if theme is provided, override default inheritance
86
- if ( o . backBtnTheme ) {
89
+ backBtn = $ ( "<a href='#' class='ui-btn-left' data-" + $ . mobile . ns + "rel='back' data-" + $ . mobile . ns + "icon='arrow-l'>" + o . backBtnText + "</a>" ) . prependTo ( $this ) ;
90
+
91
+ // If theme is provided, override default inheritance
92
+ if ( o . backBtnTheme ) {
87
93
backBtn . attr ( "data-" + $ . mobile . ns + "theme" , o . backBtnTheme ) ;
88
94
}
89
95
}
90
96
91
- //page title
97
+ // Page title
92
98
$this . children ( "h1, h2, h3, h4, h5, h6" )
93
99
. addClass ( "ui-title" )
94
- //regardless of h element number in src, it becomes h1 for the enhanced page
95
- . attr ( { "tabindex" : "0" , "role" : "heading" , "aria-level" : "1" } ) ;
100
+ // Regardless of h element number in src, it becomes h1 for the enhanced page
101
+ . attr ( {
102
+ "tabindex" : "0" ,
103
+ "role" : "heading" ,
104
+ "aria-level" : "1"
105
+ } ) ;
96
106
97
107
} else if ( role === "content" ) {
108
+
98
109
if ( theme ) {
99
110
$this . addClass ( "ui-body-" + theme ) ;
100
111
}
101
112
102
- // add ARIA role
113
+ // Add ARIA role
103
114
$this . attr ( "role" , "main" ) ;
104
115
105
116
} else if ( role === "page" ) {
106
117
$this . addClass ( "ui-body-" + ( theme || "c" ) ) ;
107
118
}
108
119
109
- switch ( role ) {
120
+ switch ( role ) {
110
121
case "header" :
111
122
case "footer" :
112
123
case "page" :
@@ -129,58 +140,64 @@ $.widget( "mobile.page", $.mobile.widget, {
129
140
//links in bars, or those with data-role become buttons
130
141
$elem . find ( ":jqmData(role='button'), .ui-bar > a, .ui-header > a, .ui-footer > a" )
131
142
. not ( ".ui-btn" )
132
- . not ( this . keepNative )
143
+ . not ( this . keepNative )
133
144
. buttonMarkup ( ) ;
134
145
135
- $elem
136
- . find ( ":jqmData(role='controlgroup')" )
137
- . controlgroup ( { dontFilterOutInvisible : true } ) ;
146
+ $elem . find ( ":jqmData(role='controlgroup')" )
147
+ . controlgroup ( {
148
+ dontFilterOutInvisible : true
149
+ } ) ;
138
150
139
- //links within content areas
151
+ // Links within content areas
140
152
$elem . find ( "a:not(.ui-btn):not(.ui-link-inherit)" )
141
- . not ( this . keepNative )
153
+ . not ( this . keepNative )
142
154
. addClass ( "ui-link" ) ;
143
155
144
- //fix toolbars
156
+ // Fix toolbars
145
157
$elem . fixHeaderFooter ( ) ;
146
158
} ,
147
159
148
160
_typeAttributeRegex : / \s + t y p e = [ " ' ] ? \w + [ ' " ] ? / ,
149
161
150
162
_enhanceControls : function ( ) {
151
- var o = this . options , self = this ;
163
+ var o = this . options , self = this ,
164
+ $this = $ ( this ) ,
165
+ type , optType ,
166
+ allControls , nonNativeControls , textInputs ;
152
167
153
168
// degrade inputs to avoid poorly implemented native functionality
154
169
this . element . find ( "input" ) . not ( this . keepNative ) . each ( function ( ) {
155
- var type = this . getAttribute ( "type" ) ,
156
- optType = o . degradeInputs [ type ] || "text" ;
170
+ type = this . getAttribute ( "type" ) ;
171
+ optType = o . degradeInputs [ type ] || "text" ;
157
172
158
173
if ( o . degradeInputs [ type ] ) {
159
- $ ( this ) . replaceWith (
160
- $ ( "<div>" ) . html ( $ ( this ) . clone ( ) ) . html ( )
161
- . replace ( self . _typeAttributeRegex , " type=\"" + optType + "\" data-" + $ . mobile . ns + "type=\"" + type + "\" " ) ) ;
174
+ $this . replaceWith (
175
+ $ ( "<div>" ) . html ( $this . clone ( ) ) . html ( )
176
+ . replace ( self . _typeAttributeRegex , " type=\"" + optType + "\" data-" + $ . mobile . ns + "type=\"" + type + "\" " )
177
+ ) ;
162
178
}
163
179
} ) ;
164
180
165
181
// We re-find form elements since the degredation code above
166
182
// may have injected new elements. We cache the non-native control
167
183
// query to reduce the number of times we search through the entire page.
168
184
169
- var allControls = this . element . find ( "input, textarea, select, button" ) ,
170
- nonNativeControls = allControls . not ( this . keepNative ) ;
185
+ allControls = this . element . find ( "input, textarea, select, button" ) ;
186
+ nonNativeControls = allControls . not ( this . keepNative ) ;
171
187
172
188
// XXX: Temporary workaround for issue 785. Turn off autocorrect and
173
189
// autocomplete since the popup they use can't be dismissed by
174
190
// the user. Note that we test for the presence of the feature
175
191
// by looking for the autocorrect property on the input element.
176
192
177
- var textInputs = allControls . filter ( "input[type=text]" ) ;
178
- if ( textInputs . length && typeof textInputs [ 0 ] . autocorrect !== "undefined" ) {
179
- textInputs . each ( function ( ) {
193
+ textInputs = allControls . filter ( "input[type=text]" ) ;
194
+
195
+ if ( textInputs . length && typeof textInputs [ 0 ] . autocorrect !== "undefined" ) {
196
+ textInputs . each ( function ( ) {
180
197
// Set the attribute instead of the property just in case there
181
198
// is code that attempts to make modifications via HTML.
182
- this . setAttribute ( "autocorrect" , "off" ) ;
183
- this . setAttribute ( "autocomplete" , "off" ) ;
199
+ this . setAttribute ( "autocorrect" , "off" ) ;
200
+ this . setAttribute ( "autocomplete" , "off" ) ;
184
201
} ) ;
185
202
}
186
203
0 commit comments