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

Commit

Permalink
addFirstLastClasses: .not( ".ui-screen-hidden" ) -> custom function
Browse files Browse the repository at this point in the history
http://jsperf.com/dot-not-vs-loop

(cherry picked from commit 7b818d8)

Closes gh-7228
Fixes gh-7227
  • Loading branch information
Gabriel Schulhof committed May 29, 2014
1 parent eaf53c6 commit df691e6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions js/widgets/addFirstLastClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,31 @@ define( [ "jquery", "../jquery.mobile.core" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

var uiScreenHiddenRegex = /\bui-screen-hidden\b/;
function noHiddenClass( elements ) {
var index,
length = elements.length,
result = [];

for ( index = 0; index < length; index++ ) {
if ( !elements[ index ].className.match( uiScreenHiddenRegex ) ) {
result.push( elements[ index ] );
}
}

return $( result );
}

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

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

Expand Down

0 comments on commit df691e6

Please sign in to comment.