anonymous_comments.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. define(['require', 'jquery'], function(require, $) {
  2. $('.moderation-controls').insertBefore($('form.elgg-form-comment-save'));
  3. $(document).on('change', '.moderated-comment input[type="checkbox"]', function(e) {
  4. var val = $(this).val();
  5. var $hidden_inputs = $('.moderation-controls .hidden-inputs');
  6. if ($(this).is(':checked')) {
  7. // add hidden input to our form
  8. if (!$('input[value="'+val+'"]', $hidden_inputs).length) {
  9. var $html = '<input type="hidden" name="guid[]" value="'+val+'">';
  10. $($html).appendTo($hidden_inputs);
  11. }
  12. }
  13. else {
  14. // remove hidden input from our form
  15. if ($('input[value="'+val+'"]', $hidden_inputs).length) {
  16. $('input[value="'+val+'"]', $hidden_inputs).remove();
  17. }
  18. // uncheck the select-all checkbox
  19. $('.moderation-controls input[type="checkbox"]').removeAttr('checked');
  20. }
  21. });
  22. $(document).on('click', '.moderation-controls input[type="checkbox"]', function(e) {
  23. if ($(this).is(':checked')) {
  24. // check all others
  25. $('.moderated-comment input[type="checkbox"]').each(function(index, elem) {
  26. $(elem).attr("checked", "checked").trigger('change');
  27. });
  28. }
  29. else {
  30. $('.moderated-comment input[type="checkbox"]').each(function(index, elem) {
  31. $(elem).removeAttr('checked').trigger('change');
  32. });
  33. }
  34. });
  35. });