controldeck.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. $(function(){
  2. var iosocket = io.connect();
  3. iosocket.on('connect', function () {
  4. // console.log('connected');
  5. });
  6. iosocket.on('disconnect', function() {
  7. // console.log('disconnected');
  8. });
  9. $(window).keydown(function(e) {
  10. // console.log('Sending keyboard command: '+e.keyCode);
  11. iosocket.emit("key down", { keyCode: e.keyCode, shiftKey: e.shiftKey, altKey: e.altKey, ctrlKey: e.ctrlKey, metaKey: e.metaKey });
  12. });
  13. $(window).keyup(function(e) {
  14. // console.log('Sending keyboard command: '+e.keyCode);
  15. iosocket.emit("key up", { keyCode: e.keyCode, shiftKey: e.shiftKey, altKey: e.altKey, ctrlKey: e.ctrlKey, metaKey: e.metaKey });
  16. });
  17. var press = Modernizr.touch ? 'touchstart' : 'click';
  18. $('body').on(press,'.btn', function(e) {
  19. e.preventDefault();
  20. if ($(this).attr('data-key')) {
  21. // console.log('sending button command: '+$(this).attr('data-key'));
  22. iosocket.send($(this).attr('data-key'));
  23. }
  24. else if ($(this).attr('data-goto')) {
  25. iosocket.send('goto:'+$(this).attr('data-goto'));
  26. }
  27. else if ($(this).attr('data-command')) {
  28. iosocket.send($(this).attr('data-command'));
  29. }
  30. });
  31. iosocket.on('flowtime minimap complete', function(data){
  32. var minimap = $('<div class="minimap ft-default-progress"></div>');
  33. $('body').append(minimap);
  34. minimap.append(data.dom);
  35. var ftThumbs = document.querySelectorAll('.ft-page-thumb');
  36. $('body').on(press,'.ft-page-thumb', function(e) {
  37. e.preventDefault();
  38. for (var i = 0; i < ftThumbs.length; i++) {
  39. ftThumbs[i].classList.remove('actual');
  40. }
  41. e.target.classList.add('actual');
  42. var s = e.target.getAttribute('data-section').replace('__', '');
  43. var p = e.target.getAttribute('data-page').replace('__', '');
  44. iosocket.emit("navigate", { section: Number(s), page: Number(p) });
  45. console.log("e.target", s, p);
  46. });
  47. iosocket.on('navigate', function(data){
  48. for (var i = 0; i < ftThumbs.length; i++) {
  49. ftThumbs[i].classList.remove('actual');
  50. }
  51. var actualThumb = document.querySelector('.ft-page-thumb[data-section=__' + data.section + '][data-page=__' + data.page + ']');
  52. actualThumb.classList.add('actual');
  53. });
  54. });
  55. });