feedback.js 1.5 KB

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