functions.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. function help_notice_check()
  2. {
  3. $.getJSON(home+'help/section/notice/go',
  4. function(data)
  5. {
  6. $.each(data, function(i, val)
  7. {
  8. if(i == 'empty')
  9. {
  10. hnt = false; help_notice_title(true);
  11. $('.header-icon-1').css('animation', 'none');
  12. }
  13. if(i == 'reply')
  14. {
  15. if(val)
  16. {
  17. if(val > getCookie('help') || getCookie('help') == undefined)
  18. {
  19. setCookie('help', val, {expires: 86400});
  20. help_notice_sound();
  21. }
  22. }
  23. $('.header-icon-1').css('animation', 'fa-spin 2s infinite cubic-bezier(0, 0, 0.15, 0.96)');
  24. }
  25. if(i == 'notice')
  26. {
  27. help_notice_sound();
  28. $('.header-icon-1').css('animation', 'fa-spin 2s infinite cubic-bezier(0, 0, 0.15, 0.96)');
  29. }
  30. });
  31. });
  32. setTimeout(function() {help_notice_check()}, 10000);
  33. }
  34. function help_notice_sound()
  35. {
  36. hnt = true; help_notice_title();
  37. var audio = new Audio();
  38. audio.preload = 'auto';
  39. audio.src = '/notice.wav';
  40. audio.play();
  41. }
  42. function help_notice_title(stop)
  43. {
  44. if(document.title == title && !stop)
  45. document.title = 'Новое сообщение';
  46. else
  47. document.title = title;
  48. if(hnt)
  49. setTimeout(function() {help_notice_title()}, 1000);
  50. }
  51. function setCookie(name, value, options)
  52. {
  53. options = options || {};
  54. var expires = options.expires;
  55. if(typeof expires == 'number' && expires)
  56. {
  57. var d = new Date();
  58. d.setTime(d.getTime() + expires * 1000);
  59. expires = options.expires = d;
  60. }
  61. if(expires && expires.toUTCString)
  62. options.expires = expires.toUTCString();
  63. value = encodeURIComponent(value);
  64. var updatedCookie = name + '=' + value + '; path=/';
  65. for (var propName in options)
  66. {
  67. updatedCookie += '; ' + propName;
  68. var propValue = options[propName];
  69. if(propValue !== true)
  70. updatedCookie += '=' + propValue;
  71. }
  72. document.cookie = updatedCookie;
  73. }
  74. function getCookie(name)
  75. {
  76. var matches = document.cookie.match(new RegExp(
  77. "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  78. ));
  79. return matches ? decodeURIComponent(matches[1]) : undefined;
  80. }
  81. function deleteCookie(name)
  82. {
  83. setCookie(name, '', {expires: -1})
  84. }
  85. $(document).ready(function(){
  86. $('.spoiler').click(function(){
  87. $(this).parent().children('div.spoiler_main').toggle(0);
  88. });
  89. help_notice_check();
  90. });