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

Commit

Permalink
[addFirstLastClasses] Common behaviour for determining the first/last…
Browse files Browse the repository at this point in the history
… visible item
  • Loading branch information
Gabriel Schulhof committed Nov 9, 2012
1 parent aafd5f2 commit 4c9cb3d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/index.php
Expand Up @@ -34,6 +34,7 @@
'widgets/dialog.js',
'widgets/page.sections.js',
'widgets/collapsible.js',
'widgets/addFirstLastClasses.js',
'widgets/collapsibleSet.js',
'jquery.mobile.fieldContain.js',
'jquery.mobile.grid.js',
Expand Down
38 changes: 38 additions & 0 deletions js/widgets/addFirstLastClasses.js
@@ -0,0 +1,38 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Mark first and last visible item with classes ui-first-child resp. ui-last-child.
//>>label: addFirstLastClasses
//>>group: Widgets

define( [ "jquery", "../../jquery.mobile.core" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

$.mobile.behaviors.addFirstLastClasses = {
_getVisibles: function( $els, create ) {
var visibles;

if ( create ) {
visibles = $els.not( ".ui-screen-hidden" );
} else {
visibles = $els.filter( ":visible" );
if ( visibles.length === 0 ) {
visibles = $els.not( ".ui-screen-hidden" );
}
}

return visibles;
},

_addFirstLastClasses: function( $els, $visibles, create ) {
$els.removeClass( "ui-first-child ui-last-child" );
$visibles.eq( 0 ).addClass( "ui-first-child" ).end().last().addClass( "ui-last-child" );
if ( !create ) {
this.element.trigger( "updatelayout" );
}
}
};

})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");

0 comments on commit 4c9cb3d

Please sign in to comment.