materio-base-legacy/feedback.js
bachy f3be35fe5e first import 7.x-2.x-dev
Signed-off-by: bachy <git@g-u-i.net>
2012-11-20 16:21:31 +01:00

73 lines
1.8 KiB
JavaScript

(function ($) {
/**
* Attach auto-submit to admin view form.
*/
Drupal.behaviors.feedbackAdminForm = {
attach: function (context) {
$('#feedback-admin-view-form', context).once('feedback', function () {
$(this).find('fieldset.feedback-messages :input[type="checkbox"]').click(function () {
this.form.submit();
});
});
}
};
/**
* Attach collapse behavior to the feedback form block.
*/
Drupal.behaviors.feedbackForm = {
attach: function (context) {
$('#block-feedback-form', context).once('feedback', function () {
var $block = $(this);
$block.find('span.feedback-link')
.prepend('<span id="feedback-form-toggle">[ + ]</span> ')
.css('cursor', 'pointer')
.toggle(function () {
Drupal.feedbackFormToggle($block, false);
},
function() {
Drupal.feedbackFormToggle($block, true);
}
);
$block.find('form').hide();
$block.show();
});
}
};
/**
* Re-collapse the feedback form after every successful form submission.
*/
Drupal.behaviors.feedbackFormSubmit = {
attach: function (context) {
var $context = $(context);
if (!$context.is('#feedback-status-message')) {
return;
}
// Collapse the form.
$('#block-feedback-form .feedback-link').click();
// Blend out and remove status message.
window.setTimeout(function () {
$context.fadeOut('slow', function () {
$context.remove();
});
}, 3000);
}
};
/**
* Collapse or uncollapse the feedback form block.
*/
Drupal.feedbackFormToggle = function ($block, enable) {
$block.find('form').slideToggle('medium');
if (enable) {
$('#feedback-form-toggle', $block).html('[ + ]');
}
else {
$('#feedback-form-toggle', $block).html('[ &minus; ]');
}
};
})(jQuery);