onCreated.js 31 KB

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