| 1 |
// $Id: feedback.js,v 1.3 2008/10/19 19:10:23 sun Exp $
|
| 2 |
(function ($) {
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Attach collapse behavior to the feedback form block (once).
|
| 6 |
*/
|
| 7 |
Drupal.feedbackSetup = function() {
|
| 8 |
$block = $('#block-feedback-form');
|
| 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')
|
| 20 |
.find(':input[name="ajax"]').val(1).end()
|
| 21 |
.submit(function() {
|
| 22 |
$('#feedback-submit', this).fadeOut('fast', function() {
|
| 23 |
Drupal.feedbackFormSubmit($(this).parents('form').get(0));
|
| 24 |
});
|
| 25 |
return false;
|
| 26 |
});
|
| 27 |
// Attach auto-submit to admin view form.
|
| 28 |
$('fieldset.feedback-messages :input[type="checkbox"]').click(function() {
|
| 29 |
$(this).parents('form').submit();
|
| 30 |
});
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Collapse or uncollapse the feedback form block.
|
| 35 |
*/
|
| 36 |
Drupal.feedbackFormToggle = function($block, enable) {
|
| 37 |
$block.find('.content').slideToggle('medium');
|
| 38 |
if (enable) {
|
| 39 |
$('#feedback-form-toggle', $block).html('[ + ]');
|
| 40 |
}
|
| 41 |
else {
|
| 42 |
$('#feedback-form-toggle', $block).html('[ − ]');
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Collapse or uncollapse the feedback form block.
|
| 48 |
*/
|
| 49 |
Drupal.feedbackFormSubmit = function(form) {
|
| 50 |
var $form = $(form);
|
| 51 |
$.post(form.action, $form.serialize(), function(data) {
|
| 52 |
// Collapse the form.
|
| 53 |
$('#block-feedback-form').find('.feedback-link').click();
|
| 54 |
// Display status message.
|
| 55 |
$form.parent().parent().append('<div id="feedback-status-message">' + data.message + '</div>');
|
| 56 |
// Reset form values.
|
| 57 |
$(':input[name="message"]', $form).val('');
|
| 58 |
$('#feedback-submit', $form).show();
|
| 59 |
// Blend out status message.
|
| 60 |
window.setTimeout(function() {
|
| 61 |
$('#feedback-status-message').fadeOut('slow', function() {
|
| 62 |
$(this).remove();
|
| 63 |
});
|
| 64 |
}, 3000);
|
| 65 |
}, 'json');
|
| 66 |
return false;
|
| 67 |
}
|
| 68 |
|
| 69 |
$(document).ready(function() {
|
| 70 |
Drupal.feedbackSetup();
|
| 71 |
});
|
| 72 |
|
| 73 |
})(jQuery)
|