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

Commit bbe5b8c

Browse files
author
Gabriel Schulhof
committed
[listview] Update first/last classes using common behaviour
1 parent 32e427b commit bbe5b8c

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

js/widgets/listview.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//>>css.structure: ../css/structure/jquery.mobile.listview.css
66
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
77

8-
define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.buttonMarkup", "./page", "./page.sections" ], function( $ ) {
8+
define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.buttonMarkup", "./page", "./page.sections", "./addFirstLastClasses" ], function( $ ) {
99
//>>excludeEnd("jqmBuildExclude");
1010
(function( $, undefined ) {
1111

@@ -49,28 +49,6 @@ $.widget( "mobile.listview", $.mobile.widget, {
4949
t.refresh( true );
5050
},
5151

52-
_addFirstLastClasses: function( create ) {
53-
var lis = this.element.children( "li" ),
54-
visiblelis;
55-
56-
lis.removeClass( "ui-first-child ui-last-child" );
57-
// At create time and when autodividers calls refresh the li are not visible yet so we need to rely on .ui-screen-hidden
58-
if ( create ) {
59-
visiblelis = lis.not( ".ui-screen-hidden" );
60-
} else {
61-
visiblelis = lis.filter( ":visible" );
62-
if ( visiblelis.length === 0 ) {
63-
visiblelis = lis.not( ".ui-screen-hidden" );
64-
}
65-
}
66-
67-
visiblelis.eq( 0 ).addClass( "ui-first-child" ).end().last().addClass( "ui-last-child" );
68-
69-
if ( !create ) {
70-
this.element.trigger( "updatelayout" );
71-
}
72-
},
73-
7452
// This is a generic utility method for finding the first
7553
// node with a given nodeName. It uses basic DOM traversal
7654
// to be fast and is meant to be a substitute for simple
@@ -301,7 +279,7 @@ $.widget( "mobile.listview", $.mobile.widget, {
301279
this._addThumbClasses( li );
302280
this._addThumbClasses( $list.find( ".ui-link-inherit" ) );
303281

304-
this._addFirstLastClasses( create );
282+
this._addFirstLastClasses( li, this._getVisibles( li, create ), create );
305283
// autodividers binds to this to redraw dividers after the listview refresh
306284
this._trigger( "afterrefresh" );
307285
},
@@ -402,6 +380,8 @@ $.widget( "mobile.listview", $.mobile.widget, {
402380
}
403381
});
404382

383+
$.widget( "mobile.listview", $.mobile.listview, $.mobile.behaviors.addFirstLastClasses );
384+
405385
//auto self-init widgets
406386
$( document ).bind( "pagecreate create", function( e ) {
407387
$.mobile.listview.prototype.enhanceWithin( e.target );

0 commit comments

Comments
 (0)