Permalink
Browse files

Listview: code improvement and coding standards.

  • Loading branch information...
jaspermdegroot committed Jul 13, 2012
1 parent 3c43c7c commit 8b691bc41b0b3ecc342008a6802855caf1d6479f
Showing with 40 additions and 39 deletions.
  1. +2 −2 css/structure/jquery.mobile.listview.css
  2. +38 −37 js/jquery.mobile.listview.js
@@ -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; }
@@ -8,7 +9,6 @@
/* Fixes #4254 to prevent inherit font-size from .ui-li-divider, .ui-li-static */
.ui-li-divider .ui-btn-text, .ui-li-static .ui-btn-text { font-size: 16px; }
.ui-li-divider .ui-mini .ui-btn-text, .ui-li-static .ui-mini .ui-btn-text { font-size: inherit; }
.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; }
@@ -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,14 +74,14 @@ $.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()
.find( ".ui-li-thumb" )
.not(".ui-li-icon")
.not( ".ui-li-icon" )
.addClass( "ui-corner-tl" );
// Select the last visible li element
@@ -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 ) {
@@ -194,12 +195,12 @@ $.widget( "mobile.listview", $.mobile.widget, {
// If we're creating the element, we update it regardless
if ( create || !item.hasClass( "ui-li" ) ) {
itemTheme = item.jqmData("theme") || o.theme;
itemTheme = item.jqmData( "theme" ) || o.theme;
a = this._getChildrenByTagName( item[ 0 ], "a", "A" );
var isDivider = ( item.jqmData( "role" ) === "list-divider" );
if ( a.length && !isDivider ) {
icon = item.jqmData("icon");
icon = item.jqmData( "icon" );
item.buttonMarkup({
wrapperEls: "div",
@@ -221,9 +222,9 @@ $.widget( "mobile.listview", $.mobile.widget, {
last = a.last();
splittheme = listsplittheme || last.jqmData( "theme" ) || o.splitTheme;
linkIcon = last.jqmData("icon");
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-body-" + 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" )

0 comments on commit 8b691bc

Please sign in to comment.