Skip to content

Commit dfea9e2

Browse files
committed
jQuery core style guide conformance: jquery.mobile.page.js
1 parent a7074bc commit dfea9e2

File tree

1 file changed

+58
-41
lines changed

1 file changed

+58
-41
lines changed

js/jquery.mobile.page.js

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* Dual licensed under the MIT or GPL Version 2 licenses.
55
* http://jquery.org/license
66
*/
7-
(function($, undefined ) {
7+
8+
(function( $, undefined ) {
89

910
$.widget( "mobile.page", $.mobile.widget, {
1011
options: {
@@ -33,38 +34,43 @@ $.widget( "mobile.page", $.mobile.widget, {
3334
var $elem = this.element,
3435
o = this.options;
3536

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 : "" );
3739

3840
if ( this._trigger( "beforeCreate" ) === false ) {
3941
return;
4042
}
4143

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
4345
// classes so we'll handle page and content roles outside of the main role processing
4446
// loop below.
4547
$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" ) );
4751
});
4852

4953
$elem.find( ":jqmData(role='nojs')" ).addClass( "ui-nojs" );
5054

51-
// pre-find data els
55+
// Pre-find data els
5256
var $dataEls = $elem.find( ":jqmData(role)" ).andSelf().each(function() {
5357
var $this = $( this ),
5458
role = $this.jqmData( "role" ),
55-
theme = $this.jqmData( "theme" );
59+
theme = $this.jqmData( "theme" ),
60+
$headeranchors,
61+
leftbtn, rightbtn, backBtn;
5662

5763
//apply theming and markup modifications to page,header,content,footer
5864
if ( role === "header" || role === "footer" ) {
5965
$this.addClass( "ui-bar-" + (theme || $this.parent( ":jqmData(role='page')" ).jqmData( "theme" ) || "a") );
6066

61-
// add ARIA role
67+
// Add ARIA role
6268
$this.attr( "role", role === "header" ? "banner" : "contentinfo" );
6369

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" );
6874

6975
if ( !leftbtn ) {
7076
leftbtn = $headeranchors.eq( 0 ).not( ".ui-btn-right" ).addClass( "ui-btn-left" ).length;
@@ -74,39 +80,44 @@ $.widget( "mobile.page", $.mobile.widget, {
7480
rightbtn = $headeranchors.eq( 1 ).addClass( "ui-btn-right" ).length;
7581
}
7682

77-
// auto-add back btn on pages beyond first view
83+
// Auto-add back btn on pages beyond first view
7884
if ( o.addBackBtn && role === "header" &&
7985
$( ".ui-page" ).length > 1 &&
8086
$elem.jqmData( "url" ) !== $.mobile.path.stripHash( location.hash ) &&
8187
!leftbtn && $this.jqmData( "backbtn" ) !== false ) {
8288

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 ) {
8793
backBtn.attr( "data-"+ $.mobile.ns +"theme", o.backBtnTheme );
8894
}
8995
}
9096

91-
//page title
97+
// Page title
9298
$this.children( "h1, h2, h3, h4, h5, h6" )
9399
.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+
});
96106

97107
} else if ( role === "content" ) {
108+
98109
if ( theme ) {
99110
$this.addClass( "ui-body-" + theme );
100111
}
101112

102-
// add ARIA role
113+
// Add ARIA role
103114
$this.attr( "role", "main" );
104115

105116
} else if ( role === "page" ) {
106117
$this.addClass( "ui-body-" + (theme || "c") );
107118
}
108119

109-
switch(role) {
120+
switch ( role ) {
110121
case "header":
111122
case "footer":
112123
case "page":
@@ -129,58 +140,64 @@ $.widget( "mobile.page", $.mobile.widget, {
129140
//links in bars, or those with data-role become buttons
130141
$elem.find( ":jqmData(role='button'), .ui-bar > a, .ui-header > a, .ui-footer > a" )
131142
.not( ".ui-btn" )
132-
.not(this.keepNative)
143+
.not( this.keepNative )
133144
.buttonMarkup();
134145

135-
$elem
136-
.find(":jqmData(role='controlgroup')")
137-
.controlgroup({dontFilterOutInvisible: true});
146+
$elem.find( ":jqmData(role='controlgroup')" )
147+
.controlgroup({
148+
dontFilterOutInvisible: true
149+
});
138150

139-
//links within content areas
151+
// Links within content areas
140152
$elem.find( "a:not(.ui-btn):not(.ui-link-inherit)" )
141-
.not(this.keepNative)
153+
.not( this.keepNative )
142154
.addClass( "ui-link" );
143155

144-
//fix toolbars
156+
// Fix toolbars
145157
$elem.fixHeaderFooter();
146158
},
147159

148160
_typeAttributeRegex: /\s+type=["']?\w+['"]?/,
149161

150162
_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;
152167

153168
// degrade inputs to avoid poorly implemented native functionality
154169
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";
157172

158173
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+
);
162178
}
163179
});
164180

165181
// We re-find form elements since the degredation code above
166182
// may have injected new elements. We cache the non-native control
167183
// query to reduce the number of times we search through the entire page.
168184

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);
171187

172188
// XXX: Temporary workaround for issue 785. Turn off autocorrect and
173189
// autocomplete since the popup they use can't be dismissed by
174190
// the user. Note that we test for the presence of the feature
175191
// by looking for the autocorrect property on the input element.
176192

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() {
180197
// Set the attribute instead of the property just in case there
181198
// 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" );
184201
});
185202
}
186203

0 commit comments

Comments
 (0)