start.js 1.0 KB

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