Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 8b691bc

Browse files
Listview: code improvement and coding standards.
1 parent 3c43c7c commit 8b691bc

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

css/structure/jquery.mobile.listview.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.ui-listview { margin: 0; counter-reset: listnumbering; }
1+
.ui-listview { margin: 0; }
2+
ol.ui-listview, ol.ui-listview .ui-li-divider { counter-reset: listnumbering; }
23
.ui-content .ui-listview { margin: -15px; }
34
.ui-content .ui-listview-inset { margin: 1em 0; }
45
.ui-listview, .ui-li { list-style:none; padding:0; }
@@ -8,7 +9,6 @@
89
/* Fixes #4254 to prevent inherit font-size from .ui-li-divider, .ui-li-static */
910
.ui-li-divider .ui-btn-text, .ui-li-static .ui-btn-text { font-size: 16px; }
1011
.ui-li-divider .ui-mini .ui-btn-text, .ui-li-static .ui-mini .ui-btn-text { font-size: inherit; }
11-
.ui-li-divider { counter-reset: listnumbering; }
1212
ol.ui-listview .ui-link-inherit:before, ol.ui-listview .ui-li-static:before, .ui-li-dec { font-size: .8em; display: inline-block; padding-right: .3em; font-weight: normal; counter-increment: listnumbering; content: counter(listnumbering) ". "; }
1313
ol.ui-listview .ui-li-jsnumbering:before { content: "" !important; } /* to avoid chance of duplication */
1414
.ui-listview-inset .ui-li { border-right-width: 1px; border-left-width: 1px; }

js/jquery.mobile.listview.js

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
6565
if ( this.options.inset ) {
6666
$li = this.element.children( "li" );
6767
// at create time the li are not visible yet so we need to rely on .ui-screen-hidden
68-
$visibleli = create?$li.not( ".ui-screen-hidden" ):$li.filter( ":visible" );
68+
$visibleli = create ? $li.not( ".ui-screen-hidden" ) : $li.filter( ":visible" );
6969

7070
this._removeCorners( $li );
7171

@@ -74,14 +74,14 @@ $.widget( "mobile.listview", $.mobile.widget, {
7474
.addClass( "ui-corner-top" );
7575

7676
$topli.add( $topli.find( ".ui-btn-inner" )
77-
.not( ".ui-li-link-alt span:first-child" ) )
78-
.addClass( "ui-corner-top" )
79-
.end()
77+
.not( ".ui-li-link-alt span:first-child" ) )
78+
.addClass( "ui-corner-top" )
79+
.end()
8080
.find( ".ui-li-link-alt, .ui-li-link-alt span:first-child" )
8181
.addClass( "ui-corner-tr" )
8282
.end()
8383
.find( ".ui-li-thumb" )
84-
.not(".ui-li-icon")
84+
.not( ".ui-li-icon" )
8585
.addClass( "ui-corner-tl" );
8686

8787
// Select the last visible li element
@@ -160,28 +160,29 @@ $.widget( "mobile.listview", $.mobile.widget, {
160160
listsplittheme = $list.jqmData( "splittheme" ),
161161
listspliticon = $list.jqmData( "spliticon" ),
162162
li = this._getChildrenByTagName( $list[ 0 ], "li", "LI" ),
163-
jsCount = $.support.cssPseudoElement || !$.nodeName( $list[ 0 ], "ol" ) ? false : true,
163+
ol = !!$.nodeName( $list[ 0 ], "ol" ),
164+
jsCount = !$.support.cssPseudoElement,
164165
start = $list.attr( "start" ),
165166
itemClassDict = {},
166167
item, itemClass, itemTheme,
167-
a, last, splittheme, counter, countParent, icon, imgParents, img, linkIcon;
168+
a, last, splittheme, counter, startCount, newStartCount, countParent, icon, imgParents, img, linkIcon;
168169

169-
if ( jsCount ) {
170+
if ( ol && jsCount ) {
170171
$list.find( ".ui-li-dec" ).remove();
171172
}
172173

173-
// Check if a start attribute has been set and take a value of 0 into account
174-
if ( typeof start !== "undefined" && start !== false ) {
175-
if ( !jsCount ) {
176-
var startCount = parseFloat( start ) - 1;
177-
$list.css( "counter-reset", "listnumbering " + startCount );
178-
} else {
179-
counter = parseFloat( start );
180-
}
181-
} else {
182-
if ( jsCount ) {
183-
counter = 1;
184-
}
174+
if ( ol ) {
175+
// Check if a start attribute has been set while taking a value of 0 into account
176+
if ( typeof start !== "undefined" && start !== false ) {
177+
if ( !jsCount ) {
178+
startCount = parseFloat( start ) - 1;
179+
$list.css( "counter-reset", "listnumbering " + startCount );
180+
} else {
181+
counter = parseFloat( start );
182+
}
183+
} else if ( jsCount ) {
184+
counter = 1;
185+
}
185186
}
186187

187188
if ( !o.theme ) {
@@ -194,12 +195,12 @@ $.widget( "mobile.listview", $.mobile.widget, {
194195

195196
// If we're creating the element, we update it regardless
196197
if ( create || !item.hasClass( "ui-li" ) ) {
197-
itemTheme = item.jqmData("theme") || o.theme;
198+
itemTheme = item.jqmData( "theme" ) || o.theme;
198199
a = this._getChildrenByTagName( item[ 0 ], "a", "A" );
199200
var isDivider = ( item.jqmData( "role" ) === "list-divider" );
200201

201202
if ( a.length && !isDivider ) {
202-
icon = item.jqmData("icon");
203+
icon = item.jqmData( "icon" );
203204

204205
item.buttonMarkup({
205206
wrapperEls: "div",
@@ -221,9 +222,9 @@ $.widget( "mobile.listview", $.mobile.widget, {
221222

222223
last = a.last();
223224
splittheme = listsplittheme || last.jqmData( "theme" ) || o.splitTheme;
224-
linkIcon = last.jqmData("icon");
225+
linkIcon = last.jqmData( "icon" );
225226

226-
last.appendTo(item)
227+
last.appendTo( item )
227228
.attr( "title", last.getEncodedText() )
228229
.addClass( "ui-li-link-alt" )
229230
.empty()
@@ -251,26 +252,26 @@ $.widget( "mobile.listview", $.mobile.widget, {
251252
itemClass += " ui-li-divider ui-bar-" + dividertheme;
252253
item.attr( "role", "heading" );
253254

254-
//reset counter when a divider heading is encountered
255-
if ( typeof start !== "undefined" && start !== false ) {
256-
if ( !jsCount ) {
257-
var newStartCount = parseFloat( start ) - 1;
258-
item.css( "counter-reset", "listnumbering " + newStartCount );
259-
} else {
260-
counter = parseFloat( start );
261-
}
262-
} else {
263-
if ( jsCount ) {
264-
counter = 1;
265-
}
255+
if ( ol ) {
256+
//reset counter when a divider heading is encountered
257+
if ( typeof start !== "undefined" && start !== false ) {
258+
if ( !jsCount ) {
259+
newStartCount = parseFloat( start ) - 1;
260+
item.css( "counter-reset", "listnumbering " + newStartCount );
261+
} else {
262+
counter = parseFloat( start );
263+
}
264+
} else if ( jsCount ) {
265+
counter = 1;
266+
}
266267
}
267268

268269
} else {
269270
itemClass += " ui-li-static ui-body-" + itemTheme;
270271
}
271272
}
272273

273-
if ( jsCount && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
274+
if ( ol && jsCount && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
274275
countParent = itemClass.indexOf( "ui-li-static" ) > 0 ? item : item.find( ".ui-link-inherit" );
275276

276277
countParent.addClass( "ui-li-jsnumbering" )

0 commit comments

Comments
 (0)