From 71223ac95f6b48b8c1cd9f038c6b6a7417ffc01a Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 21 Dec 2015 18:38:11 +0100 Subject: switch on mobile for chat focus; warn one-person game --- index.html | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index fee1f66..5bcbf40 100644 --- a/index.html +++ b/index.html @@ -19,6 +19,8 @@ try { STORAGE_ON=false; } +var IS_MOBILE=checkmobile(); + var COLOURS=["#00F","#F00","#0CC"]; var socket=io(),me=[-1,""],userlist=[],rooms={},visibleroomuidiv=null; @@ -170,7 +172,7 @@ function Room(_roomid){ this.cvs.width=this.cellsz*W+1; this.cvs.height=this.cellsz*H+1; this.cvs.addEventListener("click",function(ev){ - //this.chatinput.focus(); + if(!IS_MOBILE)this.chatinput.focus(); if(!this.canplace)return; if(ev.target!=this.cvs)return; var bbox=ev.target.getBoundingClientRect(); @@ -188,6 +190,11 @@ function Room(_roomid){ this.newgamebtn.type="button"; this.newgamebtn.value="Start new game!"; this.newgamebtn.addEventListener("click",function(){ + if(this.userlist.length<2){ + alert("Be sure to wait until all participants are there, before starting a game!"); + return; + } + if(!IS_MOBILE)this.chatinput.focus(); socket.emit("roomcreategame",this.id); //just a request }.bind(this)); this.uidiv.appendChild(this.newgamebtn); @@ -205,7 +212,7 @@ Room.prototype.becomeVisible=function(){ else document.getElementById("roomuisplash").classList.remove("invisible"); visibleroomuidiv=this.uidiv; this.uidiv.classList.remove("invisible"); - //this.chatinput.focus(); + if(!IS_MOBILE)this.chatinput.focus(); }; Room.prototype.join=function(user){ this.listdiv.innerHTML+=" "+user[1]; @@ -501,6 +508,15 @@ function sounddong(){ sounddong__audioelem.currentTime=0; sounddong__audioelem.play(); } + +function checkmobile(){ + var tabletRegex=/ipad/i; + var phoneRegex=/android|iphone|ipod|blackberry|windows phone/i; + return tabletRegex.test(navigator.userAgent) + ||phoneRegex.test(navigator.userAgent) + ||(window.matchMedia + &&window.matchMedia("only screen and (max-width: 800px)").matches); +}