Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery v1.8 compatibility #5

Open
barchard opened this issue Aug 21, 2012 · 0 comments
Open

jQuery v1.8 compatibility #5

barchard opened this issue Aug 21, 2012 · 0 comments

Comments

@barchard
Copy link

Hi-

As of version 1.8, Live Search is broken.

The error is here:
https://github.com/nakajima/jquery-livesearch/blob/master/src/jquery.livesearch.js#L5

To fix, please see:
http://stackoverflow.com/questions/2196641/how-do-i-make-jquery-contains-case-insensitive-including-jquery-1-8

Code:

jQuery.expr[":"].Contains = jQuery.expr.createPseudo(function(arg) {
    return function( elem ) {
        return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
    };
});

To maintain 1.7 compatibility, I wrote a little if test using the jQuery version function here:
http://stackoverflow.com/questions/2655308/jquery-version-compatibility-detection/3113707#3113707

  /** jQuery < 1.8 */
  if ($.isVersion('1.8', '<'))
  {
      $.extend($.expr[':'], {
        'containsi': function(elem, i, match, array) {
          return $(elem).text().toLowerCase()
            .indexOf((match[3] || "").toLowerCase()) >= 0;
        }
      });
  } else
  {  
      /** jQuery > 1.8 */
      jQuery.expr[":"].containsi = jQuery.expr.createPseudo(function(arg) {
        return function( elem ) {
            return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
        };
      });
  }

Of course, using the if statement is okay for my project but it may add unnecessary weight to the live search plugin.

-Greg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant