@@ -69,20 +69,20 @@ p5.prototype._updateTouchCoords = function(e) {
6969 if ( e . type === 'mousedown' ||
7070 e . type === 'mousemove' ||
7171 e . type === 'mouseup' ) {
72- this . _updatePMouseCoords ( ) ;
7372 this . _setProperty ( 'touchX' , this . mouseX ) ;
7473 this . _setProperty ( 'touchY' , this . mouseY ) ;
7574 } else {
76- this . _updatePTouchCoords ( ) ;
77- var touchInfo = getTouchInfo ( this . _curElement . elt , e , 0 ) ;
78- this . _setProperty ( 'touchX' , touchInfo . x ) ;
79- this . _setProperty ( 'touchY' , touchInfo . y ) ;
75+ if ( this . _curElement !== null ) {
76+ var touchInfo = getTouchInfo ( this . _curElement . elt , e , 0 ) ;
77+ this . _setProperty ( 'touchX' , touchInfo . x ) ;
78+ this . _setProperty ( 'touchY' , touchInfo . y ) ;
8079
81- var touches = [ ] ;
82- for ( var i = 0 ; i < e . touches . length ; i ++ ) {
83- touches [ i ] = getTouchInfo ( this . _curElement . elt , e , i ) ;
80+ var touches = [ ] ;
81+ for ( var i = 0 ; i < e . touches . length ; i ++ ) {
82+ touches [ i ] = getTouchInfo ( this . _curElement . elt , e , i ) ;
83+ }
84+ this . _setProperty ( 'touches' , touches ) ;
8485 }
85- this . _setProperty ( 'touches' , touches ) ;
8686 }
8787} ;
8888
@@ -146,6 +146,7 @@ p5.prototype._ontouchstart = function(e) {
146146 var context = this . _isGlobal ? window : this ;
147147 var executeDefault ;
148148 this . _updateTouchCoords ( e ) ;
149+ this . _updateMouseCoords ( e ) ;
149150 this . _setProperty ( 'touchIsDown' , true ) ;
150151 if ( typeof context . touchStarted === 'function' ) {
151152 executeDefault = context . touchStarted ( e ) ;
@@ -203,6 +204,7 @@ p5.prototype._ontouchmove = function(e) {
203204 var context = this . _isGlobal ? window : this ;
204205 var executeDefault ;
205206 this . _updateTouchCoords ( e ) ;
207+ this . _updateMouseCoords ( e ) ;
206208 if ( typeof context . touchMoved === 'function' ) {
207209 executeDefault = context . touchMoved ( e ) ;
208210 if ( executeDefault === false ) {
@@ -213,7 +215,6 @@ p5.prototype._ontouchmove = function(e) {
213215 if ( executeDefault === false ) {
214216 e . preventDefault ( ) ;
215217 }
216- this . _updateMouseCoords ( e ) ;
217218 }
218219} ;
219220
@@ -258,6 +259,7 @@ p5.prototype._ontouchmove = function(e) {
258259 */
259260p5 . prototype . _ontouchend = function ( e ) {
260261 this . _updateTouchCoords ( e ) ;
262+ this . _updateMouseCoords ( e ) ;
261263 if ( this . touches . length === 0 ) {
262264 this . _setProperty ( 'touchIsDown' , false ) ;
263265 }
@@ -273,7 +275,6 @@ p5.prototype._ontouchend = function(e) {
273275 if ( executeDefault === false ) {
274276 e . preventDefault ( ) ;
275277 }
276- this . _updateMouseCoords ( e ) ;
277278 }
278279} ;
279280
0 commit comments