Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable select2 jQuery plugin on tablets?

I am using the Select2 jQuery plugin to enhance <select> elements in our project. However, on mobile devices (smartphones, tablets), Select2 actually degrades the experience. The native select elements are better, in my opinion.

We're already doing smartphone detection with regexps from http://detectmobilebrowser.com/, but these don't match tablets (and we would like to keep smartphone and tablet detection separate). Is there any reference for tablet regexps like detectmobilebrowswer.com, or another way of detecting tablets?

like image 519
Dag Høidahl Avatar asked Nov 26 '22 10:11

Dag Høidahl


1 Answers

$(document).ready(function() {
    // run test on initial page load
    checkSize();

    // run test on resize of the window
    $(window).resize(checkSize);
});

function checkSize(){
  if (window.matchMedia("(min-width: 1024px)").matches) {
    $("select").select2();
  } else {
    $("select").select2("destroy");
  }
}
like image 113
mufaddal_mw Avatar answered Nov 29 '22 02:11

mufaddal_mw