site_notifications.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * site notifications JavaScript
  4. */
  5. ?>
  6. elgg.provide('elgg.site_notifications');
  7. elgg.site_notifications.init = function() {
  8. $('.site-notifications-delete').live('click', elgg.site_notifications.delete);
  9. $('.site-notifications-link').live('click', elgg.site_notifications.auto_delete);
  10. $('#site-notifications-toggle').live('click', elgg.site_notifications.toggle_all);
  11. };
  12. /**
  13. * Delete notification asynchronously when delete button clicked
  14. *
  15. * @param {Object} event
  16. *
  17. * @return void
  18. */
  19. elgg.site_notifications.delete = function(event) {
  20. var $item = $(this).closest('.elgg-item');
  21. $item.slideToggle('medium');
  22. elgg.action($(this).attr('href'), {
  23. success: function(json) {
  24. if (json.system_messages.error.length) {
  25. // Something went wrong, so undo the optimistic changes
  26. $item.slideToggle('medium');
  27. }
  28. },
  29. error: function() {
  30. // Something went wrong, so undo the optimistic changes
  31. $item.slideToggle('medium');
  32. }
  33. });
  34. event.preventDefault();
  35. }
  36. /**
  37. * Delete notification for this link
  38. *
  39. * @param {Object} event
  40. *
  41. * @return void
  42. */
  43. elgg.site_notifications.auto_delete = function(event) {
  44. var id = $(this).attr('id');
  45. id = id.replace("link", "delete");
  46. elgg.action($('#' + id).attr('href'), {});
  47. }
  48. /**
  49. * Toggle the checkboxes in the site notification listing
  50. *
  51. * @return void
  52. */
  53. elgg.site_notifications.toggle_all = function() {
  54. $('.site-notifications-container input[type=checkbox]').click();
  55. };
  56. elgg.register_hook_handler('init', 'system', elgg.site_notifications.init);