Skip to content

Commit

Permalink
Add checking for touchscreens
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiulodro committed Aug 29, 2017
1 parent 2cbfbcc commit 6b47531
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 9 deletions.
13 changes: 12 additions & 1 deletion dist/js/select2.full.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,14 @@ S2.define('select2/utils',[
$element.append($nodes);
};

// Determine whether the browser is on a touchscreen device.
Utils.isTouchscreen = function() {
if ('undefined' === typeof Utils._isTouchscreenCache) {
Utils._isTouchscreenCache = 'ontouchstart' in document.documentElement;
}
return Utils._isTouchscreenCache;
}

return Utils;
});

Expand Down Expand Up @@ -5466,7 +5474,10 @@ S2.define('select2/core',[
};

Select2.prototype.focusOnActiveElement = function () {
this.$results.find('li.select2-results__option--highlighted').focus();
// Don't mess with the focus on touchscreens because it causes havoc with on-screen keyboards.
if (! Utils.isTouchscreen()) {
this.$results.find('li.select2-results__option--highlighted').focus();
}
};

Select2.prototype._syncAttributes = function () {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/select2.full.min.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion dist/js/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,14 @@ S2.define('select2/utils',[
$element.append($nodes);
};

// Determine whether the browser is on a touchscreen device.
Utils.isTouchscreen = function() {
if ('undefined' === typeof Utils._isTouchscreenCache) {
Utils._isTouchscreenCache = 'ontouchstart' in document.documentElement;
}
return Utils._isTouchscreenCache;
}

return Utils;
});

Expand Down Expand Up @@ -5466,7 +5474,10 @@ S2.define('select2/core',[
};

Select2.prototype.focusOnActiveElement = function () {
this.$results.find('li.select2-results__option--highlighted').focus();
// Don't mess with the focus on touchscreens because it causes havoc with on-screen keyboards.
if (! Utils.isTouchscreen()) {
this.$results.find('li.select2-results__option--highlighted').focus();
}
};

Select2.prototype._syncAttributes = function () {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/select2.min.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion dist/js/selectWoo.full.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,14 @@ S2.define('select2/utils',[
$element.append($nodes);
};

// Determine whether the browser is on a touchscreen device.
Utils.isTouchscreen = function() {
if ('undefined' === typeof Utils._isTouchscreenCache) {
Utils._isTouchscreenCache = 'ontouchstart' in document.documentElement;
}
return Utils._isTouchscreenCache;
}

return Utils;
});

Expand Down Expand Up @@ -5466,7 +5474,10 @@ S2.define('select2/core',[
};

Select2.prototype.focusOnActiveElement = function () {
this.$results.find('li.select2-results__option--highlighted').focus();
// Don't mess with the focus on touchscreens because it causes havoc with on-screen keyboards.
if (! Utils.isTouchscreen()) {
this.$results.find('li.select2-results__option--highlighted').focus();
}
};

Select2.prototype._syncAttributes = function () {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/selectWoo.full.min.js

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion dist/js/selectWoo.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,14 @@ S2.define('select2/utils',[
$element.append($nodes);
};

// Determine whether the browser is on a touchscreen device.
Utils.isTouchscreen = function() {
if ('undefined' === typeof Utils._isTouchscreenCache) {
Utils._isTouchscreenCache = 'ontouchstart' in document.documentElement;
}
return Utils._isTouchscreenCache;
}

return Utils;
});

Expand Down Expand Up @@ -5466,7 +5474,10 @@ S2.define('select2/core',[
};

Select2.prototype.focusOnActiveElement = function () {
this.$results.find('li.select2-results__option--highlighted').focus();
// Don't mess with the focus on touchscreens because it causes havoc with on-screen keyboards.
if (! Utils.isTouchscreen()) {
this.$results.find('li.select2-results__option--highlighted').focus();
}
};

Select2.prototype._syncAttributes = function () {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/selectWoo.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/js/select2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ define([
};

Select2.prototype.focusOnActiveElement = function () {
this.$results.find('li.select2-results__option--highlighted').focus();
// Don't mess with the focus on touchscreens because it causes havoc with on-screen keyboards.
if (! Utils.isTouchscreen()) {
this.$results.find('li.select2-results__option--highlighted').focus();
}
};

Select2.prototype._syncAttributes = function () {
Expand Down
8 changes: 8 additions & 0 deletions src/js/select2/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,5 +272,13 @@ define([
$element.append($nodes);
};

// Determine whether the browser is on a touchscreen device.
Utils.isTouchscreen = function() {
if ('undefined' === typeof Utils._isTouchscreenCache) {
Utils._isTouchscreenCache = 'ontouchstart' in document.documentElement;
}
return Utils._isTouchscreenCache;
}

return Utils;
});

0 comments on commit 6b47531

Please sign in to comment.