Skip to content

Commit

Permalink
avoid virtual keyboard popup on iOS/android devices
Browse files Browse the repository at this point in the history
  • Loading branch information
biasmv committed Aug 3, 2015
1 parent 8e52738 commit d9c868e
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ on how to unblock it.\
var vec3 = glMatrix.vec3;
var mat4 = glMatrix.mat4;

function isiOS() {
return (/(iPad|iPhone|iPod)/g).test(navigator.userAgent);
}

function isAndroid() {
return /Android/i.test(navigator.userAgent);
}
function shouldUseHighPrecision() {
// high precision for shaders is only required on iOS, all the other browsers
// are doing just fine with mediump.
return (/(iPad|iPhone|iPod)/g).test( navigator.userAgent );
return isiOS();
}

var requestAnimFrame = (function(){
Expand Down Expand Up @@ -438,6 +445,10 @@ Viewer.prototype = {
},

_initKeyboardInput: function() {
if (isiOS() || isAndroid()) {
this._keyInput = document;
return;
}
// this function creates a textarea element inside a div with height
// and width of zero. When the user clicks on the viewer, we set
// focus on the text area to receive text input. This makes sure we
Expand All @@ -451,7 +462,9 @@ Viewer.prototype = {
},

focus : function() {
this._keyInput.focus();
if (this._keyInput !== document) {
this._keyInput.focus();
}
},

_initCanvas : function() {
Expand All @@ -468,11 +481,7 @@ Viewer.prototype = {
this._mouseHandler = new MouseHandler(this._canvas, this, this._cam,
this._options.animateTime);
this._canvas.domElement()
.addEventListener('mousedown', utils.bind(this, this._gainFocus));
},

_gainFocus : function() {
this._keyInput.focus();
.addEventListener('mousedown', utils.bind(this, this.focus));
},

setRotation : function(rotation, ms) {
Expand Down Expand Up @@ -576,7 +585,6 @@ Viewer.prototype = {
if (eventName === 'keypress' ||
eventName === 'keydown' ||
eventName === 'keyup') {
console.log('keypress');
// attach keyboard events to key input text area. We will
// only receive these events in case the text area has focus.
this._keyInput.addEventListener(eventName, callback, false);
Expand Down

0 comments on commit d9c868e

Please sign in to comment.