BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_notifications.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. $(document).ready(function () {
  2. 'use strict';
  3. var skip = getSkippedPage();
  4. $('.noty-notification').each(function () {
  5. var $this = $(this);
  6. var type = $this.data('noty-type'),
  7. importance = $this.data('noty-importance'),
  8. id = $this.data('noty-id'),
  9. url = $this.data('noty-url');
  10. if (type != skip) {
  11. createNoty(type, id, $this.text(), url, importance);
  12. }
  13. $this.remove();
  14. });
  15. });
  16. /**
  17. * getSkippedPage
  18. */
  19. function getSkippedPage() {
  20. var skip
  21. var url = {
  22. path: window.location.pathname.split('/').reverse()[0].split('.')[0],
  23. query: window.location.search.slice(1).split('&').reduce((a, b) => Object.assign(a, { [b.split('=')[0]]: b.split('=')[1] }), {})
  24. };
  25. switch (url.path) {
  26. case 'inbox':
  27. if (url.query.length == 0 || (url.query.length == 1 && url.query.hasOwnProperty('sort'))) {
  28. skip = 'Inbox';
  29. }
  30. break;
  31. case 'userhistory':
  32. if (url.query['action'] == 'subscriptions') {
  33. skip = 'Subscriptions';
  34. }
  35. if (url.query['action'] == 'quote_notifications') {
  36. skip = 'Quotes';
  37. }
  38. if (url.query['action'] == 'subscribed_collages') {
  39. skip = 'Collages';
  40. }
  41. break;
  42. case 'user':
  43. if (url.query['action'] == 'notify') {
  44. skip = 'Torrents';
  45. }
  46. break;
  47. case 'blog':
  48. if (url.query.length == 0) {
  49. skip = 'Blog';
  50. }
  51. break;
  52. case 'index':
  53. if (url.query.length == 0) {
  54. skip = 'News';
  55. }
  56. break;
  57. case 'staffpm':
  58. if (url.query.length == 0) {
  59. skip = 'StaffPM';
  60. }
  61. break;
  62. default:
  63. break;
  64. }
  65. return skip;
  66. }
  67. /**
  68. * createNoty
  69. */
  70. function createNoty(type, id, message, url, importance) {
  71. var hideButtons = !url;
  72. noty({
  73. text: message,
  74. type: importance,
  75. layout: 'bottomRight',
  76. closeWith: ['click'],
  77. animation: {
  78. open: { height: 'toggle' },
  79. close: { height: 'toggle' },
  80. easing: 'swing',
  81. speed: 200
  82. },
  83. buttons: [
  84. {
  85. addClass: 'brackets noty_button_view' + (hideButtons ? ' hidden' : ''),
  86. text: 'View',
  87. onClick: function ($noty) {
  88. window.location.href = url;
  89. }
  90. },
  91. {
  92. addClass: 'brackets noty_button_clear',
  93. text: 'Clear',
  94. onClick: function ($noty) {
  95. $noty.close();
  96. clear(type, id);
  97. }
  98. },
  99. {
  100. addClass: 'brackets noty_button_close ',
  101. text: 'Hide',
  102. onClick: function ($noty) {
  103. $noty.close();
  104. }
  105. },
  106. ]
  107. });
  108. }
  109. /**
  110. * clear
  111. */
  112. function clear(type, id) {
  113. $.ajax({
  114. type: 'POST',
  115. url: 'api.php?action=clear_user_notification',
  116. dataType: 'json',
  117. data: {
  118. 'type': type,
  119. 'id': id
  120. }
  121. });
  122. }