main.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. window.onload = function () {
  2. var socket = io();
  3. socket.on('disconnect', function () {
  4. console.log('Disconnected from server');
  5. });
  6. socket.on('search', function (res) {
  7. console.log(res);
  8. });
  9. var data = {
  10. user: {
  11. id: null
  12. },
  13. modals: {
  14. register: {
  15. visible: false,
  16. email: "",
  17. username: "",
  18. password: ""
  19. },
  20. account: {
  21. visible: false
  22. },
  23. donate: {
  24. visible: false
  25. },
  26. project: {
  27. visible: false
  28. }
  29. },
  30. home: {
  31. visible: false,
  32. groups: [
  33. {
  34. id: "lu08gw56571r4497wrk9",
  35. name: "Official Rooms",
  36. rooms: [
  37. { id: "73qvw65746acvo8yqfr", thumbnail: "https://lh6.googleusercontent.com/-ghASz3s6yL4/AAAAAAAAAAI/AAAAAAAAALc/tFblPp2myu0/s0-c-k-no-ns/photo.jpg", name: "Country", description: "Johnny Cash - I Walk The Line", users: 10 },
  38. { id: "enxcysmhn1k7ld56ogvi", thumbnail: "http://66.media.tumblr.com/1734069af425e491fae7deae0a19869f/tumblr_o0i0xmIYrF1v421f2o1_1280.jpg", name: "Pop", description: "Sia - Cheap Thrills", users: 14 },
  39. { id: "kqa99gbva7lij05dn29", thumbnail: "http://www.youredm.com/wp-content/uploads/2014/09/taking-you-higher.jpg", name: "Chill", description: "MrSuicideSheep - Taking you higher", users: 13 },
  40. { id: "w19hu791iiub6wmjf9a4i", thumbnail: "http://edmsauce.wpengine.netdna-cdn.com/wp-content/uploads/2012/12/Deadmau5-album-title-goes-here.jpg", name: "EDM", description: "Deadmau5 - There Might Be Coffee", users: 13 }
  41. ]
  42. },
  43. {
  44. id: "g2b8v03xaedj8ht1emi",
  45. name: "Trending Rooms",
  46. rooms: [
  47. { id: "73qvw65746acvo8yqfr", thumbnail: "https://lh6.googleusercontent.com/-ghASz3s6yL4/AAAAAAAAAAI/AAAAAAAAALc/tFblPp2myu0/s0-c-k-no-ns/photo.jpg", name: "Country", description: "Johnny Cash - I Walk The Line", users: 10 },
  48. { id: "enxcysmhn1k7ld56ogvi", thumbnail: "http://66.media.tumblr.com/1734069af425e491fae7deae0a19869f/tumblr_o0i0xmIYrF1v421f2o1_1280.jpg", name: "Pop", description: "Sia - Cheap Thrills", users: 14 },
  49. { id: "kqa99gbva7lij05dn29", thumbnail: "http://www.youredm.com/wp-content/uploads/2014/09/taking-you-higher.jpg", name: "Chill", description: "MrSuicideSheep - Taking you higher", users: 13 },
  50. { id: "w19hu791iiub6wmjf9a4i", thumbnail: "http://edmsauce.wpengine.netdna-cdn.com/wp-content/uploads/2012/12/Deadmau5-album-title-goes-here.jpg", name: "EDM", description: "Deadmau5 - There Might Be Coffee", users: 13 }
  51. ]
  52. }
  53. ]
  54. },
  55. room: {
  56. visible: false,
  57. id: "",
  58. name: "",
  59. description: "",
  60. player: {
  61. },
  62. chat: {
  63. visible: false,
  64. messages: []
  65. },
  66. users: {
  67. list: {}
  68. },
  69. playlist: {
  70. visible: false,
  71. messages: []
  72. }
  73. }
  74. };
  75. var methods = {
  76. leaveRoom: function () {
  77. data.room.visible = false;
  78. window.setTimeout(function () { data.home.visible = true; }, 500);
  79. },
  80. enterRoom: function (room) {
  81. data.home.visible = false;
  82. window.setTimeout(function () { data.room.visible = true; }, 500);
  83. data.room.id = room.id;
  84. data.room.displayName = room.displayName;
  85. data.room.description = room.description;
  86. },
  87. modalVisibilityChange: function (name) {
  88. var modal = data.modals[name];
  89. if (modal) {
  90. switch (name) {
  91. case 'register': {
  92. data.modals.register.email = "";
  93. data.modals.register.username = "";
  94. data.modals.register.password = "";
  95. grecaptcha.reset();
  96. } break;
  97. }
  98. }
  99. },
  100. showModal: function (name) {
  101. Object.keys(data.modals).forEach(function (key) {
  102. var visibility = data.modals[key].visible;
  103. data.modals[key].visible = (key == name);
  104. if (visibility != data.modals[key].visible) {
  105. methods.modalVisibilityChange(key);
  106. }
  107. });
  108. },
  109. modalVisible: function (name) {
  110. var visible = false;
  111. // check if the specific modal is visible
  112. if (name) {
  113. Object.keys(data.modals).forEach(function (key) { if (key == name) visible = data.modals[key].visible; });
  114. }
  115. // check if any of them are visible
  116. else {
  117. Object.keys(data.modals).forEach(function (key) { if (visible == false) visible = data.modals[key].visible; });
  118. }
  119. return visible;
  120. },
  121. modalPositionStyle: function (name, width, height) {
  122. return {
  123. width: width + 'px',
  124. height: height + 'px',
  125. left: 'calc(50% - ' + (width / 2) + 'px)',
  126. top: (data.modals[name].visible ? 'calc(50% - ' + (height / 2) + 'px)' : '-' + (height + 32) + 'px')
  127. }
  128. },
  129. register: function () {
  130. socket.emit('/users/register', {
  131. email: data.modals.register.email,
  132. username: data.modals.register.username,
  133. password: data.modals.register.password,
  134. recaptcha: grecaptcha.getResponse()
  135. });
  136. }
  137. };
  138. var app = new Vue({ el: '#app', data: data, methods: methods, ready: function () { window.setTimeout(function () { data.home.visible = true; }, 250); } });
  139. window.socket = socket;
  140. window.data = data;
  141. };