Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Listviews: code improvement and coding standards.

  • Loading branch information...
commit 73e1e9733c7b730313686db22338a9befbd1dcf7 1 parent 10f8b33
@jaspermdegroot jaspermdegroot authored
View
4 css/structure/jquery.mobile.listview.css
@@ -1,4 +1,5 @@
-.ui-listview { margin: 0; counter-reset: listnumbering; }
+.ui-listview { margin: 0; }
+ol.ui-listview, ol.ui-listview .ui-li-divider { counter-reset: listnumbering; }
.ui-content .ui-listview { margin: -15px; }
.ui-content .ui-listview-inset { margin: 1em 0; }
.ui-listview, .ui-li { list-style:none; padding:0; }
@@ -6,7 +7,6 @@
.ui-li .ui-btn-text a.ui-link-inherit { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.ui-li-static { background-image: none; }
.ui-li-divider { padding: .5em 15px; font-size: 14px; font-weight: bold; }
-.ui-li-divider { counter-reset: listnumbering; }
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) ". "; }
ol.ui-listview .ui-li-jsnumbering:before { content: "" !important; } /* to avoid chance of duplication */
.ui-listview-inset .ui-li { border-right-width: 1px; border-left-width: 1px; }
View
4 js/widgets/listview.autodividers.js
@@ -23,14 +23,14 @@ $.mobile.listview.prototype.options.autodividersSelector = function( elt ) {
$( document ).delegate( "ul,ol", "listviewcreate", function() {
var list = $( this ),
- listview = list.data( "listview" );
+ listview = list.jqmData( "listview" );
if ( !listview.options.autodividers ) {
return;
}
var replaceDividers = function () {
- list.find( 'li:jqmData(role=list-divider)' ).remove();
+ list.find( "li:jqmData(role='list-divider')" ).remove();
var lis = list.find( 'li' ),
lastDividerText = null, li, dividerText;
View
71 js/widgets/listview.js
@@ -65,7 +65,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
if ( this.options.inset ) {
$li = this.element.children( "li" );
// at create time the li are not visible yet so we need to rely on .ui-screen-hidden
- $visibleli = create?$li.not( ".ui-screen-hidden" ):$li.filter( ":visible" );
+ $visibleli = create ? $li.not( ".ui-screen-hidden" ) : $li.filter( ":visible" );
this._removeCorners( $li );
@@ -74,9 +74,9 @@ $.widget( "mobile.listview", $.mobile.widget, {
.addClass( "ui-corner-top" );
$topli.add( $topli.find( ".ui-btn-inner" )
- .not( ".ui-li-link-alt span:first-child" ) )
- .addClass( "ui-corner-top" )
- .end()
+ .not( ".ui-li-link-alt span:first-child" ) )
+ .addClass( "ui-corner-top" )
+ .end()
.find( ".ui-li-link-alt, .ui-li-link-alt span:first-child" )
.addClass( "ui-corner-tr" )
.end()
@@ -160,28 +160,29 @@ $.widget( "mobile.listview", $.mobile.widget, {
listsplittheme = $list.jqmData( "splittheme" ),
listspliticon = $list.jqmData( "spliticon" ),
li = this._getChildrenByTagName( $list[ 0 ], "li", "LI" ),
- jsCount = $.support.cssPseudoElement || !$.nodeName( $list[ 0 ], "ol" ) ? false : true,
+ ol = !!$.nodeName( $list[ 0 ], "ol" ),
+ jsCount = !$.support.cssPseudoElement,
start = $list.attr( "start" ),
itemClassDict = {},
item, itemClass, itemTheme,
- a, last, splittheme, counter, countParent, icon, imgParents, img, linkIcon;
+ a, last, splittheme, counter, startCount, newStartCount, countParent, icon, imgParents, img, linkIcon;
- if ( jsCount ) {
+ if ( ol && jsCount ) {
$list.find( ".ui-li-dec" ).remove();
}
-
- // Check if a start attribute has been set and take a value of 0 into account
- if ( typeof start !== "undefined" && start !== false ) {
- if ( !jsCount ) {
- var startCount = parseFloat( start ) - 1;
- $list.css( "counter-reset", "listnumbering " + startCount );
- } else {
- counter = parseFloat( start );
- }
- } else {
- if ( jsCount ) {
- counter = 1;
- }
+
+ if ( ol ) {
+ // Check if a start attribute has been set while taking a value of 0 into account
+ if ( typeof start !== "undefined" && start !== false ) {
+ if ( !jsCount ) {
+ startCount = parseFloat( start ) - 1;
+ $list.css( "counter-reset", "listnumbering " + startCount );
+ } else {
+ counter = parseFloat( start );
+ }
+ } else if ( jsCount ) {
+ counter = 1;
+ }
}
if ( !o.theme ) {
@@ -223,7 +224,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
splittheme = listsplittheme || last.jqmData( "theme" ) || o.splitTheme;
linkIcon = last.jqmData( "icon" );
- last.appendTo(item)
+ last.appendTo( item )
.attr( "title", last.getEncodedText() )
.addClass( "ui-li-link-alt" )
.empty()
@@ -251,26 +252,26 @@ $.widget( "mobile.listview", $.mobile.widget, {
itemClass += " ui-li-divider ui-bar-" + dividertheme;
item.attr( "role", "heading" );
- //reset counter when a divider heading is encountered
- if ( typeof start !== "undefined" && start !== false ) {
- if ( !jsCount ) {
- var newStartCount = parseFloat( start ) - 1;
- item.css( "counter-reset", "listnumbering " + newStartCount );
- } else {
- counter = parseFloat( start );
- }
- } else {
- if ( jsCount ) {
- counter = 1;
- }
+ if ( ol ) {
+ //reset counter when a divider heading is encountered
+ if ( typeof start !== "undefined" && start !== false ) {
+ if ( !jsCount ) {
+ newStartCount = parseFloat( start ) - 1;
+ item.css( "counter-reset", "listnumbering " + newStartCount );
+ } else {
+ counter = parseFloat( start );
+ }
+ } else if ( jsCount ) {
+ counter = 1;
+ }
}
-
+
} else {
itemClass += " ui-li-static ui-btn-up-" + itemTheme;
}
}
- if ( jsCount && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
+ if ( ol && jsCount && itemClass.indexOf( "ui-li-divider" ) < 0 ) {
countParent = itemClass.indexOf( "ui-li-static" ) > 0 ? item : item.find( ".ui-link-inherit" );
countParent.addClass( "ui-li-jsnumbering" )
Please sign in to comment.
Something went wrong with that request. Please try again.