/site/sites/all/modules/contrib/mollom/mollom.flag.js

https://bitbucket.org/siftdigital/sift-digital-make-file · JavaScript · 118 lines · 84 code · 15 blank · 19 comment · 19 complexity · 95e217afd8cd48b06ecc606017e983d1 MD5 · raw file

  1. (function ($) {
  2. /**
  3. * Only show links to report comments after the comment has been moused over.
  4. */
  5. Drupal.behaviors.mollomReportComment = {
  6. showReportLink: function(e) {
  7. $(this).find('.mollom-flag').show();
  8. },
  9. hideReportLink: function(e) {
  10. if ($(this).find('.mollom-flag-reasons').length === 0) {
  11. // Only hide the link if the comment is not currently being reported.
  12. $(this).find('.mollom-flag').hide();
  13. }
  14. },
  15. attach: function (context) {
  16. // Leave the report links visible for touch devices.
  17. if (!!('ontouchstart' in window) || !!('msmaxtouchpoints' in window.navigator)) {
  18. return;
  19. }
  20. // Don't show/hide the report link if the text is aligned right or its
  21. // appearance will cause all other inline links to jump to the left.
  22. var ul = $(context).find('.comment ul.links:has(.mollom-flag)');
  23. if ((ul.css('display') == 'block' && ul.css('textAlign') == 'right')
  24. || ul.css('float') == 'right'
  25. || ul.find('li').css('float') == 'right') {
  26. } else {
  27. $(context).find('.comment:has(.mollom-flag)').bind('mouseover',this.showReportLink);
  28. $(context).find('.comment:has(.mollom-flag)').bind('mouseout',this.hideReportLink);
  29. $(context).find('.comment .mollom-flag').hide();
  30. }
  31. },
  32. detach: function(context) {
  33. $(context).find('.comment:has(.mollom-flag)').unbind('mouseover',this.showReportLink);
  34. $(context).find('.comment:has(.mollom-flag)').unbind('mouseout',this.hideReportLink);
  35. }
  36. };
  37. /**
  38. * Close a form to report comments as inappropriate if user clicks outside.
  39. */
  40. Drupal.behaviors.mollomReportCancel = {
  41. lastFocus: null,
  42. context: null,
  43. // Helper functions have "this" set to Drupal.behaviors.mollomReportCancel.
  44. closeReportDialog: function(e) {
  45. if ($('.mollom-flag-container').length > 0) {
  46. e.stopPropagation();
  47. $('.mollom-flag-container').remove();
  48. this.lastFocus.focus();
  49. }
  50. },
  51. checkEscapeDialog: function(e) {
  52. if (e.keyCode === 27) {
  53. this.closeReportDialog(e);
  54. }
  55. },
  56. checkClickOutside: function(e) {
  57. if (!$.contains(this.context[0],e.target)) {
  58. this.closeReportDialog(e);
  59. }
  60. },
  61. attach: function (context) {
  62. if ($(context).hasClass('mollom-flag-container')) {
  63. // Enable and set focus on the new dialog.
  64. this.context = context;
  65. this.lastFocus = document.activeElement;
  66. context.tabIndex = -1;
  67. context.focus();
  68. $(document).bind('keydown',$.proxy(this.checkEscapeDialog,this));
  69. $(document).bind('click',$.proxy(this.checkClickOutside,this));
  70. }
  71. },
  72. detach: function(context) {
  73. if ($(context).hasClass('mollom-flag-container')) {
  74. $(document).unbind('keydown',this.checkCloseDialog);
  75. $(document).unbind('click',this.checkClickOutside);
  76. }
  77. }
  78. };
  79. /**
  80. * Add a class to reported content to allow overriding the display with CSS.
  81. */
  82. Drupal.behaviors.mollomReportedMarkAsFlagged = {
  83. attach: function (context) {
  84. if ($(context).hasClass('mollom-flag-confirm')) {
  85. $(context).parents('.mollom-flag-content').addClass('mollom-flagged');
  86. }
  87. }
  88. }
  89. /**
  90. * Close reporting confirmation and remove a comment that has been reported.
  91. */
  92. Drupal.behaviors.mollomReportedCommentHide = {
  93. attach: function (context) {
  94. if ($(context).hasClass('mollom-flag-confirm')) {
  95. // Removes the comment from view.
  96. $(context).parent().delay(1000).fadeOut(400,function() {
  97. $(context).parents('.mollom-flag-content-comment').prev().remove();
  98. $(context).parents('.mollom-flag-content-comment').slideUp(200, this.remove);
  99. });
  100. }
  101. }
  102. };
  103. })(jQuery);