onCreated.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. var StationSubscription = undefined;
  2. var resizeSeekerbarInterval;
  3. Template.banned.onCreated(function() {
  4. if (Session.get("rTimeInterval") !== undefined) {
  5. Meteor.clearInterval(Session.get("rTimeInterval"))
  6. }
  7. Session.set("rTimeInterval", Meteor.setInterval(function() {
  8. Session.set("time", new Date().getTime());
  9. }, 10000));
  10. Session.set("ban", Meteor.user().punishments.ban);
  11. });
  12. Template.home.onCreated(function() {
  13. if (Session.get("minterval") !== undefined) {
  14. Meteor.clearInterval(Session.get("minterval"));
  15. }
  16. if (resizeSeekerbarInterval !== undefined) {
  17. Meteor.clearInterval(resizeSeekerbarInterval);
  18. resizeSeekerbarInterval = undefined;
  19. }
  20. if (StationSubscription !== undefined) {
  21. StationSubscription.stop();
  22. }
  23. Session.set("type", undefined);
  24. });
  25. Template.login.onCreated(function() {
  26. Session.set("github", true);
  27. Accounts.onLoginFailure(function() {
  28. if (Session.get("github") === true) {
  29. var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> Something went wrong when trying to log in with GitHub.</div>');
  30. $(".landing").before(errAlert);
  31. Meteor.setTimeout(function() {
  32. errAlert.fadeOut(5000, function() {
  33. errAlert.remove();
  34. });
  35. }, 10000);
  36. }
  37. });
  38. });
  39. Template.admin.onCreated(function() {
  40. Meteor.subscribe("allAlerts");
  41. });
  42. Template.feedback.onCreated(function(){
  43. Meteor.subscribe("feedback");
  44. })
  45. Template.profile.onCreated(function() {
  46. var parts = Router.current().url.split('/');
  47. var username = parts.pop();
  48. Session.set("loaded", false);
  49. Meteor.subscribe("userProfiles", username.toLowerCase(), function() {
  50. if (Meteor.users.find({"profile.usernameL": username.toLowerCase()}).count() === 0) {
  51. window.location = "/";
  52. } else {
  53. var data = Meteor.users.findOne({"profile.usernameL": username.toLowerCase()});
  54. Session.set("real_name", data.profile.realname);
  55. Session.set("username", data.profile.username);
  56. Session.set("first_joined", data.createdAt);
  57. Session.set("rank", data.profile.rank);
  58. Session.set("songs_requested", data.profile.statistics.songsRequested);
  59. Session.set("liked", data.profile.liked);
  60. Session.set("disliked", data.profile.disliked);
  61. Session.set("loaded", true);
  62. }
  63. });
  64. });
  65. Template.queues.onCreated(function() {
  66. var tag = document.createElement("script");
  67. tag.src = "https://www.youtube.com/iframe_api";
  68. var firstScriptTag = document.getElementsByTagName('script')[0];
  69. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  70. YTPlayer = undefined;
  71. $(document).keydown(function(evt){
  72. if (evt.keyCode==83 && (evt.ctrlKey)){
  73. evt.preventDefault();
  74. if (Session.get("editing") === true) {
  75. $("#save-song-button").click();
  76. }
  77. }
  78. });
  79. });
  80. Template.manageStation.onCreated(function() {
  81. var tag = document.createElement("script");
  82. tag.src = "https://www.youtube.com/iframe_api";
  83. var firstScriptTag = document.getElementsByTagName('script')[0];
  84. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  85. YTPlayer = undefined;
  86. $(document).keydown(function(evt){
  87. if (evt.keyCode==83 && (evt.ctrlKey)){
  88. evt.preventDefault();
  89. if (Session.get("editing") === true) {
  90. $("#save-song-button").click();
  91. }
  92. }
  93. });
  94. });
  95. Template.manageSongs.onCreated(function() {
  96. Session.set("showNoGenres", false);
  97. Session.set("showGenres", true);
  98. var tag = document.createElement("script");
  99. tag.src = "https://www.youtube.com/iframe_api";
  100. var firstScriptTag = document.getElementsByTagName('script')[0];
  101. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  102. YTPlayer = undefined;
  103. $(document).keydown(function(evt){
  104. if (evt.keyCode==83 && (evt.ctrlKey)){
  105. evt.preventDefault();
  106. if (Session.get("editing") === true) {
  107. $("#save-song-button").click();
  108. }
  109. }
  110. });
  111. });
  112. Template.register.onCreated(function() {
  113. Accounts.onLoginFailure(function() {
  114. var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> Something went wrong when trying to register with GitHub. Maybe an account with that username already exists?</div>');
  115. $(".landing").before(errAlert);
  116. Meteor.setTimeout(function() {
  117. errAlert.fadeOut(5000, function() {
  118. errAlert.remove();
  119. });
  120. }, 10000);
  121. });
  122. });
  123. Template.room.onCreated(function () {
  124. Chat.after.find(function(userId, selector) {
  125. if (selector.type === "global") {
  126. if (!$("#global-chat-tab").hasClass("active")) {
  127. $("#global-chat-tab").addClass("unread-messages");
  128. }
  129. } else if(selector.type === Session.get("type")) {
  130. if (!$("#chat-tab").hasClass("active")) {
  131. $("#chat-tab").addClass("unread-messages");
  132. }
  133. }
  134. });
  135. Session.set("reportSong", false);
  136. Session.set("reportTitle", false);
  137. Session.set("reportAuthor", false);
  138. Session.set("reportDuration", false);
  139. Session.set("reportAudio", false);
  140. Session.set("reportAlbumart", false);
  141. Session.set("reportOther", false);
  142. Session.set("si_or_pl", "singleVideo");
  143. Session.set("editingSong", false);
  144. var parts = location.href.split('/');
  145. var id = parts.pop();
  146. var type = id.toLowerCase();
  147. if (resizeSeekerbarInterval !== undefined) {
  148. Meteor.clearInterval(resizeSeekerbarInterval);
  149. resizeSeekerbarInterval = undefined;
  150. }
  151. YTPlayer = undefined;
  152. Session.set("videoHidden", false);
  153. var tag = document.createElement("script");
  154. tag.src = "https://www.youtube.com/iframe_api";
  155. var firstScriptTag = document.getElementsByTagName('script')[0];
  156. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  157. Session.set("singleVideo", true);
  158. var currentSong = undefined;
  159. var currentSongR = undefined;
  160. function getTimeElapsed() {
  161. var type = Session.get("type");
  162. if (currentSong !== undefined) {
  163. var room = Rooms.findOne({type: type});
  164. if (room !== undefined) {
  165. return Date.now() - currentSong.started - room.timePaused;
  166. }
  167. }
  168. return 0;
  169. }
  170. function getSongInfo(songData){
  171. Session.set("title", songData.title);
  172. Session.set("artist", songData.artist);
  173. Session.set("id", songData.id);
  174. $("#song-img").attr("src", songData.img);
  175. Session.set("duration", parseInt(songData.duration));
  176. var d = moment.duration(parseInt(songData.duration), 'seconds');
  177. $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  178. Session.set("timeFormat", d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  179. document.title = Session.get("title") + " - " + Session.get("artist") + " - Musare";
  180. }
  181. function resizeSeekerbar() {
  182. if (Session.get("state") === "playing") {
  183. $(".seeker-bar").width(((getTimeElapsed() / 1000) / Session.get("duration") * 100) + "%");
  184. }
  185. }
  186. function startSong() {
  187. $("#time-elapsed").text("0:00");
  188. $("#vote-skip").attr("disabled", false);
  189. if (currentSong !== undefined) {
  190. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) YTPlayer.stopVideo();
  191. var volume = localStorage.getItem("volume") || 20;
  192. $("#volume_slider").val(volume);
  193. $("#player").show();
  194. function loadVideo() {
  195. if (!Session.get("YTLoaded")) {
  196. Session.set("loadVideoTimeout", Meteor.setTimeout(function () {
  197. loadVideo();
  198. }, 500));
  199. } else {
  200. if (YTPlayer === undefined) {
  201. if (YT !== undefined && YT.Player !== undefined) {
  202. YTPlayer = new YT.Player("player", {
  203. height: 270,
  204. width: 480,
  205. videoId: currentSong.id,
  206. playerVars: {controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0},
  207. events: {
  208. 'onReady': function (event) {
  209. if (currentSong.skipDuration === undefined) {
  210. currentSong.skipDuration = 0;
  211. }
  212. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  213. event.target.playVideo();
  214. event.target.setVolume(volume);
  215. resizeSeekerbar();
  216. },
  217. 'onStateChange': function (event) {
  218. if (Session.get("YTLoaded")) {
  219. if (event.data == YT.PlayerState.PAUSED && Session.get("state") === "playing") {
  220. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  221. event.target.playVideo();
  222. }
  223. if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
  224. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  225. event.target.pauseVideo();
  226. }
  227. }
  228. }
  229. }
  230. });
  231. } else {
  232. setTimeout(function() {
  233. startSong();
  234. }, 500);
  235. }
  236. } else {
  237. YTPlayer.loadVideoById(currentSong.id);
  238. if (currentSong.skipDuration === undefined) {
  239. currentSong.skipDuration = 0;
  240. }
  241. YTPlayer.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  242. $("#vote-skip").removeClass("disabled");
  243. }
  244. Session.set("pauseVideo", false);
  245. getSongInfo(currentSong);
  246. }
  247. }
  248. loadVideo();
  249. }
  250. }
  251. Session.set("loaded", false);
  252. Meteor.subscribe("rooms", function() {
  253. var parts = location.href.split('/');
  254. var id = parts.pop();
  255. var type = id.toLowerCase();
  256. Session.set("type", type);
  257. if (Rooms.find({type: type}).count() !== 1) {
  258. window.location = "/";
  259. } else {
  260. StationSubscription = Meteor.subscribe(type);
  261. Session.set("loaded", true);
  262. Session.set("minterval", Meteor.setInterval(function () {
  263. var room = Rooms.findOne({type: type});
  264. if (room !== undefined) {
  265. if (room.state === "paused" || Session.get("pauseVideo")) {
  266. Session.set("state", "paused");
  267. // TODO Fix issue where sometimes nothing loads with the YT is not defined error. The error points to around this.
  268. if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() === 1) {
  269. YTPlayer.pauseVideo();
  270. }
  271. } else {
  272. Session.set("state", "playing");
  273. if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() !== 1) {
  274. YTPlayer.playVideo();
  275. }
  276. }
  277. }
  278. if (currentSongR === undefined || room.currentSong.started !== currentSongR.started) {
  279. Session.set("previousSong", currentSong);
  280. currentSongR = room.currentSong;
  281. currentSong = room.currentSong.song;
  282. currentSong.started = room.currentSong.started;
  283. Session.set("currentSong", currentSong);
  284. Meteor.clearTimeout(Session.get("loadVideoTimeout"));
  285. startSong();
  286. }
  287. if (currentSong !== undefined) {
  288. if (room !== undefined) {
  289. var duration = (Date.now() - currentSong.started - room.timePaused) / 1000;
  290. var song_duration = currentSong.duration;
  291. if (song_duration <= duration) {
  292. Session.set("pauseVideo", true);
  293. }
  294. var d = moment.duration(duration, 'seconds');
  295. if (Session.get("state") === "playing") {
  296. $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  297. }
  298. }
  299. }
  300. }, 100));
  301. resizeSeekerbarInterval = Meteor.setInterval(function () {
  302. resizeSeekerbar();
  303. }, 500)
  304. }
  305. });
  306. Meteor.setTimeout(function(){
  307. $("#playlist-slideout").on("click", function(){
  308. if($("#chat-slide-out").css("right") === "0px"){
  309. $("#chat-slideout").sideNav("hide");
  310. }
  311. else if($("#users-slide-out").css("right") === "0px"){
  312. $("#users-slideout").sideNav("hide");
  313. }
  314. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  315. $(".room-container").css("margin-right", "370px")
  316. if($("#playlist-slide-out").css("right") === "0px"){
  317. $(".room-container").css("margin-right", marginRightWidth);
  318. }
  319. });
  320. $("#chat-slideout").on("click", function(){
  321. if($("#playlist-slide-out").css("right") === "0px"){
  322. $("#playlist-slideout").sideNav("hide");
  323. }
  324. else if($("#users-slide-out").css("right") === "0px"){
  325. $("#users-slideout").sideNav("hide");
  326. }
  327. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  328. $(".chat-ul").scrollTop(1000000);
  329. $(".room-container").css("margin-right", "370px")
  330. if($("#chat-slide-out").css("right") === "0px"){
  331. $(".room-container").css("margin-right", marginRightWidth);
  332. }
  333. });
  334. $("#users-slideout").on("click", function(){
  335. if($("#playlist-slide-out").css("right") === "0px"){
  336. $("#playlist-slideout").sideNav("hide");
  337. }
  338. else if($("#chat-slide-out").css("right") === "0px"){
  339. $("#chat-slideout").sideNav("hide");
  340. }
  341. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  342. $(".room-container").css("margin-right", "370px")
  343. if($("#users-slide-out").css("right") === "0px"){
  344. $(".room-container").css("margin-right", marginRightWidth);
  345. }
  346. });
  347. $("body").on("click", function(e){
  348. });
  349. $(window).on("resize", function(){
  350. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  351. $(".container").css("margin-right", marginRightWidth);
  352. })
  353. }, 1000);
  354. });
  355. Template.privateRoom.onCreated(function () {
  356. Chat.after.find(function(userId, selector) {
  357. if (selector.type === "global") {
  358. if (!$("#global-chat-tab").hasClass("active")) {
  359. $("#global-chat-tab").addClass("unread-messages");
  360. }
  361. }
  362. });
  363. var parts = location.href.split('/');
  364. var id = parts.pop();
  365. var name = id.toLowerCase();
  366. if (resizeSeekerbarInterval !== undefined) {
  367. Meteor.clearInterval(resizeSeekerbarInterval);
  368. resizeSeekerbarInterval = undefined;
  369. }
  370. YTPlayer = undefined;
  371. Session.set("videoHidden", false);
  372. var tag = document.createElement("script");
  373. tag.src = "https://www.youtube.com/iframe_api";
  374. var firstScriptTag = document.getElementsByTagName('script')[0];
  375. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  376. Session.set("singleVideo", true);
  377. var currentSong = undefined;
  378. var currentSongR = undefined;
  379. function getTimeElapsed() {
  380. var name = Session.get("privateRoomName");
  381. if (currentSong !== undefined) {
  382. var room = PrivateRooms.findOne({name: name});
  383. if (room !== undefined) {
  384. return Date.now() - currentSong.started - room.timePaused;
  385. }
  386. }
  387. return 0;
  388. }
  389. function getSongInfo(songData){
  390. Session.set("title", songData.title);
  391. Session.set("id", songData.id);
  392. Session.set("duration", parseInt(songData.duration));
  393. var d = moment.duration(parseInt(songData.duration), 'seconds');
  394. $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  395. Session.set("timeFormat", d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  396. document.title = Session.get("title") + " - Musare";
  397. }
  398. function resizeSeekerbar() {
  399. if (Session.get("state") === "playing") {
  400. $(".seeker-bar").width(((getTimeElapsed() / 1000) / Session.get("duration") * 100) + "%");
  401. }
  402. }
  403. function startSong() {
  404. $("#time-elapsed").text("0:00");
  405. $("#vote-skip").attr("disabled", false);
  406. if (currentSong !== undefined) {
  407. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) YTPlayer.stopVideo();
  408. var volume = localStorage.getItem("volume") || 20;
  409. $("#volume_slider").val(volume);
  410. $("#player").show();
  411. function loadVideo() {
  412. if (!Session.get("YTLoaded")) {
  413. Session.set("loadVideoTimeout", Meteor.setTimeout(function () {
  414. loadVideo();
  415. }, 500));
  416. } else {
  417. if (YTPlayer === undefined) {
  418. if (YT !== undefined && YT.Player !== undefined) {
  419. YTPlayer = new YT.Player("player", {
  420. height: 270,
  421. width: 480,
  422. videoId: currentSong.id,
  423. playerVars: {controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0},
  424. events: {
  425. 'onReady': function (event) {
  426. event.target.seekTo(getTimeElapsed() / 1000);
  427. event.target.playVideo();
  428. event.target.setVolume(volume);
  429. resizeSeekerbar();
  430. },
  431. 'onStateChange': function (event) {
  432. if (Session.get("YTLoaded")) {
  433. if (event.data == YT.PlayerState.PAUSED && Session.get("state") === "playing") {
  434. event.target.seekTo(getTimeElapsed() / 1000);
  435. event.target.playVideo();
  436. }
  437. if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
  438. event.target.seekTo(getTimeElapsed() / 1000);
  439. event.target.pauseVideo();
  440. }
  441. }
  442. }
  443. }
  444. });
  445. } else {
  446. setTimeout(function() {
  447. startSong();
  448. }, 500);
  449. }
  450. } else {
  451. YTPlayer.loadVideoById(currentSong.id);
  452. YTPlayer.seekTo(getTimeElapsed() / 1000);
  453. $("#vote-skip").removeClass("disabled");
  454. }
  455. Session.set("pauseVideo", false);
  456. getSongInfo(currentSong);
  457. }
  458. }
  459. loadVideo();
  460. }
  461. }
  462. Session.set("loaded", false);
  463. Meteor.subscribe("private_rooms", function() {
  464. var parts = location.href.split('/');
  465. var id = parts.pop();
  466. var name = id.toLowerCase();
  467. Session.set("privateRoomName", name);
  468. if (PrivateRooms.find({name: name}).count() !== 1) {
  469. window.location = "/";
  470. } else {
  471. StationSubscription = Meteor.subscribe("pr_" + name);
  472. Session.set("loaded", true);
  473. Session.set("minterval", Meteor.setInterval(function () {
  474. var room = PrivateRooms.findOne({name: name});
  475. if (room !== undefined) {
  476. if (room.state === "paused" || Session.get("pauseVideo")) {
  477. Session.set("state", "paused");
  478. // TODO Fix issue where sometimes nothing loads with the YT is not defined error. The error points to around this.
  479. if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() === 1) {
  480. YTPlayer.pauseVideo();
  481. }
  482. } else {
  483. Session.set("state", "playing");
  484. if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() !== 1) {
  485. YTPlayer.playVideo();
  486. }
  487. }
  488. }
  489. if (currentSongR === undefined || room.currentSong.started !== currentSongR.started) {
  490. Session.set("previousSong", currentSong);
  491. currentSongR = room.currentSong;
  492. currentSong = room.currentSong.song;
  493. currentSong.started = room.currentSong.started;
  494. Session.set("currentSong", currentSong);
  495. Meteor.clearTimeout(Session.get("loadVideoTimeout"));
  496. startSong();
  497. }
  498. if (currentSong !== undefined) {
  499. if (room !== undefined) {
  500. var duration = (Date.now() - currentSong.started - room.timePaused) / 1000;
  501. var song_duration = currentSong.duration;
  502. if (song_duration <= duration) {
  503. Session.set("pauseVideo", true);
  504. }
  505. var d = moment.duration(duration, 'seconds');
  506. if (Session.get("state") === "playing") {
  507. $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  508. }
  509. }
  510. }
  511. }, 100));
  512. resizeSeekerbarInterval = Meteor.setInterval(function () {
  513. resizeSeekerbar();
  514. }, 500)
  515. }
  516. });
  517. Meteor.setTimeout(function(){
  518. $("#playlist-slideout").on("click", function(){
  519. if($("#chat-slide-out").css("right") === "0px"){
  520. $("#chat-slideout").sideNav("hide");
  521. }
  522. else if($("#users-slide-out").css("right") === "0px"){
  523. $("#users-slideout").sideNav("hide");
  524. }
  525. else if($("#allowed-slide-out").css("right") === "0px"){
  526. $("#allowed-slideout").sideNav("hide");
  527. }
  528. else if($("#playlists-slide-out").css("right") === "0px"){
  529. $("#playlists-slideout").sideNav("hide");
  530. }
  531. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  532. $(".room-container").css("margin-right", "370px")
  533. if($("#playlist-slide-out").css("right") === "0px"){
  534. $(".room-container").css("margin-right", marginRightWidth);
  535. }
  536. });
  537. $("#chat-slideout").on("click", function(){
  538. if($("#playlist-slide-out").css("right") === "0px"){
  539. $("#playlist-slideout").sideNav("hide");
  540. }
  541. else if($("#users-slide-out").css("right") === "0px"){
  542. $("#users-slideout").sideNav("hide");
  543. }
  544. else if($("#allowed-slide-out").css("right") === "0px"){
  545. $("#allowed-slideout").sideNav("hide");
  546. }
  547. else if($("#playlists-slide-out").css("right") === "0px"){
  548. $("#playlists-slideout").sideNav("hide");
  549. }
  550. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  551. $(".chat-ul").scrollTop(1000000);
  552. $(".room-container").css("margin-right", "370px")
  553. if($("#chat-slide-out").css("right") === "0px"){
  554. $(".room-container").css("margin-right", marginRightWidth);
  555. }
  556. });
  557. $("#users-slideout").on("click", function(){
  558. if($("#playlist-slide-out").css("right") === "0px"){
  559. $("#playlist-slideout").sideNav("hide");
  560. }
  561. else if($("#chat-slide-out").css("right") === "0px"){
  562. $("#chat-slideout").sideNav("hide");
  563. }
  564. else if($("#allowed-slide-out").css("right") === "0px"){
  565. $("#allowed-slideout").sideNav("hide");
  566. }
  567. else if($("#playlists-slide-out").css("right") === "0px"){
  568. $("#playlists-slideout").sideNav("hide");
  569. }
  570. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  571. $(".room-container").css("margin-right", "370px")
  572. if($("#users-slide-out").css("right") === "0px"){
  573. $(".room-container").css("margin-right", marginRightWidth);
  574. }
  575. });
  576. $("#allowed-slideout").on("click", function(){
  577. if($("#playlist-slide-out").css("right") === "0px"){
  578. $("#playlist-slideout").sideNav("hide");
  579. }
  580. else if($("#chat-slide-out").css("right") === "0px"){
  581. $("#chat-slideout").sideNav("hide");
  582. }
  583. else if($("#users-slide-out").css("right") === "0px"){
  584. $("#users-slideout").sideNav("hide");
  585. }
  586. else if($("#playlists-slide-out").css("right") === "0px"){
  587. $("#playlists-slideout").sideNav("hide");
  588. }
  589. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  590. $(".room-container").css("margin-right", "370px")
  591. if($("#allowed-slide-out").css("right") === "0px"){
  592. $(".room-container").css("margin-right", marginRightWidth);
  593. }
  594. });
  595. $("#playlists-slideout").on("click", function(){
  596. if($("#playlist-slide-out").css("right") === "0px"){
  597. $("#playlist-slideout").sideNav("hide");
  598. }
  599. else if($("#chat-slide-out").css("right") === "0px"){
  600. $("#chat-slideout").sideNav("hide");
  601. }
  602. else if($("#users-slide-out").css("right") === "0px"){
  603. $("#users-slideout").sideNav("hide");
  604. }
  605. else if($("#allowed-slide-out").css("right") === "0px"){
  606. $("#allowed-slideout").sideNav("hide");
  607. }
  608. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  609. $(".room-container").css("margin-right", "370px")
  610. if($("#playlists-slide-out").css("right") === "0px"){
  611. $(".room-container").css("margin-right", marginRightWidth);
  612. }
  613. });
  614. $("body").on("click", function(e){
  615. });
  616. $(window).on("resize", function(){
  617. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  618. $(".container").css("margin-right", marginRightWidth);
  619. })
  620. }, 1000);
  621. });
  622. Template.settings.onCreated(function() {
  623. $(document).ready(function() {
  624. var user = Meteor.user();
  625. function initSettings() {
  626. if (user !== undefined) {
  627. if (user.profile.settings && user.profile.settings.showRating === true) {
  628. function setChecked() {
  629. $("#showRating").prop("checked", true);
  630. if (!$("#showRating").prop("checked")) {
  631. Meteor.setTimeout(function() {
  632. setChecked();
  633. }, 100);
  634. }
  635. }
  636. setChecked();
  637. }
  638. } else {
  639. Meteor.setTimeout(function() {
  640. initSettings();
  641. }, 500);
  642. }
  643. }
  644. initSettings();
  645. });
  646. });