onCreated.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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. function recursion() {
  216. Meteor.setTimeout(function() {
  217. if (event.target.getPlayerState() === 1 && Session.get("state") === "playing") {
  218. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  219. } else {
  220. recursion();
  221. }
  222. }, 200);
  223. }
  224. recursion();
  225. resizeSeekerbar();
  226. },
  227. 'onStateChange': function (event) {
  228. if (Session.get("YTLoaded")) {
  229. if (event.data == YT.PlayerState.PAUSED && Session.get("state") === "playing") {
  230. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  231. event.target.playVideo();
  232. }
  233. if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
  234. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  235. event.target.pauseVideo();
  236. }
  237. }
  238. }
  239. }
  240. });
  241. } else {
  242. setTimeout(function() {
  243. startSong();
  244. }, 500);
  245. }
  246. } else {
  247. YTPlayer.loadVideoById(currentSong.id);
  248. if (currentSong.skipDuration === undefined) {
  249. currentSong.skipDuration = 0;
  250. }
  251. YTPlayer.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  252. $("#vote-skip").removeClass("disabled");
  253. }
  254. Session.set("pauseVideo", false);
  255. getSongInfo(currentSong);
  256. }
  257. }
  258. loadVideo();
  259. }
  260. }
  261. Session.set("loaded", false);
  262. Meteor.subscribe("rooms", function() {
  263. var parts = location.href.split('/');
  264. var id = parts.pop();
  265. var type = id.toLowerCase();
  266. Session.set("type", type);
  267. if (Rooms.find({type: type}).count() !== 1) {
  268. window.location = "/";
  269. } else {
  270. StationSubscription = Meteor.subscribe(type);
  271. Session.set("loaded", true);
  272. Session.set("minterval", Meteor.setInterval(function () {
  273. var room = Rooms.findOne({type: type});
  274. if (room !== undefined) {
  275. if (room.state === "paused" || Session.get("pauseVideo")) {
  276. Session.set("state", "paused");
  277. // TODO Fix issue where sometimes nothing loads with the YT is not defined error. The error points to around this.
  278. if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() === 1) {
  279. YTPlayer.pauseVideo();
  280. }
  281. } else {
  282. Session.set("state", "playing");
  283. if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() !== 1) {
  284. YTPlayer.playVideo();
  285. }
  286. }
  287. }
  288. if (currentSongR === undefined || room.currentSong.started !== currentSongR.started) {
  289. Session.set("previousSong", currentSong);
  290. currentSongR = room.currentSong;
  291. currentSong = room.currentSong.song;
  292. currentSong.started = room.currentSong.started;
  293. Session.set("currentSong", currentSong);
  294. Meteor.clearTimeout(Session.get("loadVideoTimeout"));
  295. startSong();
  296. }
  297. if (currentSong !== undefined) {
  298. if (room !== undefined) {
  299. var duration = (Date.now() - currentSong.started - room.timePaused) / 1000;
  300. var song_duration = currentSong.duration;
  301. if (song_duration <= duration) {
  302. Session.set("pauseVideo", true);
  303. }
  304. var d = moment.duration(duration, 'seconds');
  305. if (Session.get("state") === "playing") {
  306. $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  307. }
  308. }
  309. }
  310. }, 100));
  311. resizeSeekerbarInterval = Meteor.setInterval(function () {
  312. resizeSeekerbar();
  313. }, 500)
  314. }
  315. });
  316. Meteor.setTimeout(function(){
  317. $("#playlist-slideout").on("click", function(){
  318. if($("#chat-slide-out").css("right") === "0px"){
  319. $("#chat-slideout").sideNav("hide");
  320. }
  321. else if($("#users-slide-out").css("right") === "0px"){
  322. $("#users-slideout").sideNav("hide");
  323. }
  324. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  325. $(".room-container").css("margin-right", "370px")
  326. if($("#playlist-slide-out").css("right") === "0px"){
  327. $(".room-container").css("margin-right", marginRightWidth);
  328. }
  329. });
  330. $("#chat-slideout").on("click", function(){
  331. if($("#playlist-slide-out").css("right") === "0px"){
  332. $("#playlist-slideout").sideNav("hide");
  333. }
  334. else if($("#users-slide-out").css("right") === "0px"){
  335. $("#users-slideout").sideNav("hide");
  336. }
  337. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  338. $(".chat-ul").scrollTop(1000000);
  339. $(".room-container").css("margin-right", "370px")
  340. if($("#chat-slide-out").css("right") === "0px"){
  341. $(".room-container").css("margin-right", marginRightWidth);
  342. }
  343. });
  344. $("#users-slideout").on("click", function(){
  345. if($("#playlist-slide-out").css("right") === "0px"){
  346. $("#playlist-slideout").sideNav("hide");
  347. }
  348. else if($("#chat-slide-out").css("right") === "0px"){
  349. $("#chat-slideout").sideNav("hide");
  350. }
  351. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  352. $(".room-container").css("margin-right", "370px")
  353. if($("#users-slide-out").css("right") === "0px"){
  354. $(".room-container").css("margin-right", marginRightWidth);
  355. }
  356. });
  357. $("body").on("click", function(e){
  358. });
  359. $(window).on("resize", function(){
  360. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  361. $(".container").css("margin-right", marginRightWidth);
  362. })
  363. }, 1000);
  364. });
  365. Template.communityStation.onCreated(function () {
  366. Chat.after.find(function(userId, selector) {
  367. if (selector.type === "global") {
  368. if (!$("#global-chat-tab").hasClass("active")) {
  369. $("#global-chat-tab").addClass("unread-messages");
  370. }
  371. }
  372. });
  373. var parts = location.href.split('/');
  374. var id = parts.pop();
  375. var name = id.toLowerCase();
  376. if (resizeSeekerbarInterval !== undefined) {
  377. Meteor.clearInterval(resizeSeekerbarInterval);
  378. resizeSeekerbarInterval = undefined;
  379. }
  380. YTPlayer = undefined;
  381. Session.set("videoHidden", false);
  382. var tag = document.createElement("script");
  383. tag.src = "https://www.youtube.com/iframe_api";
  384. var firstScriptTag = document.getElementsByTagName('script')[0];
  385. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  386. Session.set("singleVideo", true);
  387. var currentSong = undefined;
  388. var currentSongR = undefined;
  389. function getTimeElapsed() {
  390. var name = Session.get("CommunityStationName");
  391. if (currentSong !== undefined) {
  392. var room = CommunityStations.findOne({name: name});
  393. if (room !== undefined) {
  394. return Date.now() - currentSong.started - room.timePaused;
  395. }
  396. }
  397. return 0;
  398. }
  399. function getSongInfo(songData){
  400. Session.set("title", songData.title);
  401. Session.set("id", songData.id);
  402. Session.set("duration", parseInt(songData.duration));
  403. var d = moment.duration(parseInt(songData.duration), 'seconds');
  404. $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  405. Session.set("timeFormat", d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  406. document.title = Session.get("title") + " - Musare";
  407. }
  408. function resizeSeekerbar() {
  409. if (Session.get("state") === "playing") {
  410. $(".seeker-bar").width(((getTimeElapsed() / 1000) / Session.get("duration") * 100) + "%");
  411. }
  412. }
  413. function startSong() {
  414. $("#time-elapsed").text("0:00");
  415. $("#vote-skip").attr("disabled", false);
  416. if (currentSong !== undefined) {
  417. if (YTPlayer !== undefined && YTPlayer.stopVideo !== undefined) YTPlayer.stopVideo();
  418. var volume = localStorage.getItem("volume") || 20;
  419. $("#volume_slider").val(volume);
  420. $("#player").show();
  421. function loadVideo() {
  422. if (!Session.get("YTLoaded")) {
  423. Session.set("loadVideoTimeout", Meteor.setTimeout(function () {
  424. loadVideo();
  425. }, 500));
  426. } else {
  427. if (YTPlayer === undefined) {
  428. if (YT !== undefined && YT.Player !== undefined) {
  429. YTPlayer = new YT.Player("player", {
  430. height: 270,
  431. width: 480,
  432. videoId: currentSong.id,
  433. playerVars: {controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0},
  434. events: {
  435. 'onReady': function (event) {
  436. event.target.seekTo(getTimeElapsed() / 1000);
  437. event.target.playVideo();
  438. event.target.setVolume(volume);
  439. function recursion() {
  440. Meteor.setTimeout(function() {
  441. if (event.target.getPlayerState() === 1 && Session.get("state") === "playing") {
  442. event.target.seekTo(getTimeElapsed() / 1000);
  443. } else {
  444. recursion();
  445. }
  446. }, 200);
  447. }
  448. recursion();
  449. resizeSeekerbar();
  450. },
  451. 'onStateChange': function (event) {
  452. if (Session.get("YTLoaded")) {
  453. if (event.data == YT.PlayerState.PAUSED && Session.get("state") === "playing") {
  454. event.target.seekTo(getTimeElapsed() / 1000);
  455. event.target.playVideo();
  456. }
  457. if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
  458. event.target.seekTo(getTimeElapsed() / 1000);
  459. event.target.pauseVideo();
  460. }
  461. }
  462. }
  463. }
  464. });
  465. } else {
  466. setTimeout(function() {
  467. startSong();
  468. }, 500);
  469. }
  470. } else {
  471. YTPlayer.loadVideoById(currentSong.id);
  472. YTPlayer.seekTo(getTimeElapsed() / 1000);
  473. $("#vote-skip").removeClass("disabled");
  474. }
  475. Session.set("pauseVideo", false);
  476. getSongInfo(currentSong);
  477. }
  478. }
  479. loadVideo();
  480. }
  481. }
  482. Session.set("loaded", false);
  483. Meteor.subscribe("community_stations", function() {
  484. var parts = location.href.split('/');
  485. var id = parts.pop();
  486. var name = id.toLowerCase();
  487. Session.set("CommunityStationName", name);
  488. if (CommunityStations.find({name: name}).count() !== 1) {
  489. window.location = "/";
  490. } else {
  491. StationSubscription = Meteor.subscribe("pr_" + name);
  492. Session.set("loaded", true);
  493. Session.set("minterval", Meteor.setInterval(function () {
  494. var room = CommunityStations.findOne({name: name});
  495. if (room !== undefined) {
  496. if (room.state === "paused" || Session.get("pauseVideo")) {
  497. Session.set("state", "paused");
  498. // TODO Fix issue where sometimes nothing loads with the YT is not defined error. The error points to around this.
  499. if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() === 1) {
  500. YTPlayer.pauseVideo();
  501. }
  502. } else {
  503. Session.set("state", "playing");
  504. if (YTPlayer !== undefined && YTPlayer.getPlayerState !== undefined && YTPlayer.getPlayerState() !== 1) {
  505. YTPlayer.playVideo();
  506. }
  507. }
  508. }
  509. if (currentSongR === undefined || room.currentSong.started !== currentSongR.started) {
  510. Session.set("previousSong", currentSong);
  511. currentSongR = room.currentSong;
  512. currentSong = room.currentSong.song;
  513. currentSong.started = room.currentSong.started;
  514. Session.set("currentSong", currentSong);
  515. Meteor.clearTimeout(Session.get("loadVideoTimeout"));
  516. startSong();
  517. }
  518. if (currentSong !== undefined) {
  519. if (room !== undefined) {
  520. var duration = (Date.now() - currentSong.started - room.timePaused) / 1000;
  521. var song_duration = currentSong.duration;
  522. if (song_duration <= duration) {
  523. Session.set("pauseVideo", true);
  524. }
  525. var d = moment.duration(duration, 'seconds');
  526. if (Session.get("state") === "playing") {
  527. $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  528. }
  529. }
  530. }
  531. }, 100));
  532. resizeSeekerbarInterval = Meteor.setInterval(function () {
  533. resizeSeekerbar();
  534. }, 500)
  535. }
  536. });
  537. Meteor.setTimeout(function(){
  538. $("#playlist-slideout").on("click", function(){
  539. if($("#chat-slide-out").css("right") === "0px"){
  540. $("#chat-slideout").sideNav("hide");
  541. }
  542. else if($("#users-slide-out").css("right") === "0px"){
  543. $("#users-slideout").sideNav("hide");
  544. }
  545. else if($("#allowed-slide-out").css("right") === "0px"){
  546. $("#allowed-slideout").sideNav("hide");
  547. }
  548. else if($("#playlists-slide-out").css("right") === "0px"){
  549. $("#playlists-slideout").sideNav("hide");
  550. }
  551. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  552. $(".room-container").css("margin-right", "370px")
  553. if($("#playlist-slide-out").css("right") === "0px"){
  554. $(".room-container").css("margin-right", marginRightWidth);
  555. }
  556. });
  557. $("#chat-slideout").on("click", function(){
  558. if($("#playlist-slide-out").css("right") === "0px"){
  559. $("#playlist-slideout").sideNav("hide");
  560. }
  561. else if($("#users-slide-out").css("right") === "0px"){
  562. $("#users-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. $(".chat-ul").scrollTop(1000000);
  572. $(".room-container").css("margin-right", "370px")
  573. if($("#chat-slide-out").css("right") === "0px"){
  574. $(".room-container").css("margin-right", marginRightWidth);
  575. }
  576. });
  577. $("#users-slideout").on("click", function(){
  578. if($("#playlist-slide-out").css("right") === "0px"){
  579. $("#playlist-slideout").sideNav("hide");
  580. }
  581. else if($("#chat-slide-out").css("right") === "0px"){
  582. $("#chat-slideout").sideNav("hide");
  583. }
  584. else if($("#allowed-slide-out").css("right") === "0px"){
  585. $("#allowed-slideout").sideNav("hide");
  586. }
  587. else if($("#playlists-slide-out").css("right") === "0px"){
  588. $("#playlists-slideout").sideNav("hide");
  589. }
  590. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  591. $(".room-container").css("margin-right", "370px")
  592. if($("#users-slide-out").css("right") === "0px"){
  593. $(".room-container").css("margin-right", marginRightWidth);
  594. }
  595. });
  596. $("#allowed-slideout").on("click", function(){
  597. if($("#playlist-slide-out").css("right") === "0px"){
  598. $("#playlist-slideout").sideNav("hide");
  599. }
  600. else if($("#chat-slide-out").css("right") === "0px"){
  601. $("#chat-slideout").sideNav("hide");
  602. }
  603. else if($("#users-slide-out").css("right") === "0px"){
  604. $("#users-slideout").sideNav("hide");
  605. }
  606. else if($("#playlists-slide-out").css("right") === "0px"){
  607. $("#playlists-slideout").sideNav("hide");
  608. }
  609. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  610. $(".room-container").css("margin-right", "370px")
  611. if($("#allowed-slide-out").css("right") === "0px"){
  612. $(".room-container").css("margin-right", marginRightWidth);
  613. }
  614. });
  615. $("#playlists-slideout").on("click", function(){
  616. if($("#playlist-slide-out").css("right") === "0px"){
  617. $("#playlist-slideout").sideNav("hide");
  618. }
  619. else if($("#chat-slide-out").css("right") === "0px"){
  620. $("#chat-slideout").sideNav("hide");
  621. }
  622. else if($("#users-slide-out").css("right") === "0px"){
  623. $("#users-slideout").sideNav("hide");
  624. }
  625. else if($("#allowed-slide-out").css("right") === "0px"){
  626. $("#allowed-slideout").sideNav("hide");
  627. }
  628. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  629. $(".room-container").css("margin-right", "370px")
  630. if($("#playlists-slide-out").css("right") === "0px"){
  631. $(".room-container").css("margin-right", marginRightWidth);
  632. }
  633. });
  634. $("body").on("click", function(e){
  635. });
  636. $(window).on("resize", function(){
  637. var marginRightWidth = ($(document).width() - $(".container").width()) / 2 + "px";
  638. $(".container").css("margin-right", marginRightWidth);
  639. })
  640. }, 1000);
  641. });
  642. Template.settings.onCreated(function() {
  643. $(document).ready(function() {
  644. var user = Meteor.user();
  645. function initSettings() {
  646. if (user !== undefined) {
  647. if (user.profile.settings && user.profile.settings.showRating === true) {
  648. function setChecked() {
  649. $("#showRating").prop("checked", true);
  650. if (!$("#showRating").prop("checked")) {
  651. Meteor.setTimeout(function() {
  652. setChecked();
  653. }, 100);
  654. }
  655. }
  656. setChecked();
  657. }
  658. } else {
  659. Meteor.setTimeout(function() {
  660. initSettings();
  661. }, 500);
  662. }
  663. }
  664. initSettings();
  665. });
  666. });