Created
November 26, 2012 03:29
-
-
Save elijahmanor/4146463 to your computer and use it in GitHub Desktop.
jQuery Mobile Smart Filtering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.mobile.listview.prototype.options.filterCallback = function( test, searchValue, item ) { | |
| var list = item.closest( "[data-role='listview']" ), | |
| selector, matches, compare, caseSensitive; | |
| selector = list.data( "selector" ); | |
| if ( selector ) { | |
| text = item.find( selector ).text(); | |
| } else { | |
| text = item.jqmData( "filtertext" ) || item.text(); | |
| } | |
| text = $.trim( text ); | |
| caseSensitive = list.data( "caseSensitive" ) || false; | |
| if ( !caseSensitive ) { | |
| searchValue = searchValue.toLowerCase(); | |
| text = text.toLowerCase(); | |
| } | |
| compare = list.data( "compare" ) || "*="; | |
| if ( compare === "*=" ) { | |
| matches = text.indexOf( searchValue ) >= 0; | |
| } else if ( compare === "^=" ) { | |
| matches = text.indexOf( searchValue ) === 0; | |
| } else if ( compare === "$=" ) { | |
| matches = text.lastIndexOf( searchValue ) === ( text.length - searchValue.length ); | |
| } | |
| return !matches; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ul id="members" data-role="listview" data-filter="true" data-selector="h3" data-compare="^="> | |
| <li> | |
| <a href="index.html"> | |
| <h3>Rey Bango</h3> | |
| <p><strong>Evangelist</strong></p> | |
| <p>Florida, United States</p> | |
| </a> | |
| </li> | |
| <!-- ... --> | |
| </ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment