feedback.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. (function ($) {
  2. /**
  3. * Attach auto-submit to admin view form.
  4. */
  5. Drupal.behaviors.feedbackAdminForm = {
  6. attach: function (context) {
  7. $('#feedback-admin-view-form', context).once('feedback', function () {
  8. $(this).find('fieldset.feedback-messages :input[type="checkbox"]').click(function () {
  9. this.form.submit();
  10. });
  11. });
  12. }
  13. };
  14. /**
  15. * Attach collapse behavior to the feedback form block.
  16. */
  17. Drupal.behaviors.feedbackForm = {
  18. attach: function (context) {
  19. $('#block-feedback-form', context).once('feedback', function () {
  20. var $block = $(this);
  21. $block.find('span.feedback-link')
  22. .prepend('<span id="feedback-form-toggle">[ + ]</span> ')
  23. .css('cursor', 'pointer')
  24. .toggle(function () {
  25. Drupal.feedbackFormToggle($block, false);
  26. },
  27. function() {
  28. Drupal.feedbackFormToggle($block, true);
  29. }
  30. );
  31. $block.find('form').hide();
  32. $block.show();
  33. });
  34. }
  35. };
  36. /**
  37. * Re-collapse the feedback form after every successful form submission.
  38. */
  39. Drupal.behaviors.feedbackFormSubmit = {
  40. attach: function (context) {
  41. var $context = $(context);
  42. if (!$context.is('#feedback-status-message')) {
  43. return;
  44. }
  45. // Collapse the form.
  46. $('#block-feedback-form .feedback-link').click();
  47. // Blend out and remove status message.
  48. window.setTimeout(function () {
  49. $context.fadeOut('slow', function () {
  50. $context.remove();
  51. });
  52. }, 3000);
  53. }
  54. };
  55. /**
  56. * Collapse or uncollapse the feedback form block.
  57. */
  58. Drupal.feedbackFormToggle = function ($block, enable) {
  59. $block.find('form').slideToggle('medium');
  60. if (enable) {
  61. $('#feedback-form-toggle', $block).html('[ + ]');
  62. }
  63. else {
  64. $('#feedback-form-toggle', $block).html('[ &minus; ]');
  65. }
  66. };
  67. })(jQuery);