start.js 910 B

12345678910111213141516171819202122232425262728
  1. $(document).ready(function () {
  2. var $token, $time, $increment;
  3. $socket.on('created', function (data) {
  4. $token = data.token;
  5. $('#game_link').val($URL + '/play/' + $token + '/' + $time + '/' + $increment); // create game link
  6. $('#game_link').click(function() {
  7. $(this).select(); // when clicked, link is automatically selected for convenience
  8. });
  9. });
  10. $socket.on('ready', function (data) {
  11. document.location = $URL + '/play/' + $token + '/' + $time + '/' + $increment;
  12. });
  13. $('#play').click(function (ev) {
  14. var min = parseInt($('#minutes').val());
  15. var sec = parseInt($('#seconds').val());
  16. if (!isNaN(min) && min > 0 && min <= 50 && !isNaN(sec) && sec >= 0 && sec <= 50) {
  17. $time = min;
  18. $increment = sec;
  19. $socket.emit('start');
  20. $('#waiting').slideDown(400); // show waiting for opponent message
  21. ev.preventDefault();
  22. }
  23. });
  24. });