| 1 |
// $Id$
|
| 2 |
|
| 3 |
if (!Drupal.advpoll) {
|
| 4 |
Drupal.advpoll = {};
|
| 5 |
}
|
| 6 |
|
| 7 |
/*
|
| 8 |
* Submit advpoll forms with ajax
|
| 9 |
*/
|
| 10 |
Drupal.advpoll.attachVoteAjax = function() {
|
| 11 |
$("form.advpoll-vote").each(function() {
|
| 12 |
var thisForm = this;
|
| 13 |
var options = {
|
| 14 |
dataType: 'json',
|
| 15 |
after: function(data) {
|
| 16 |
// Remove previous messages
|
| 17 |
$("div.messages").remove();
|
| 18 |
// Remove the voting form if validating passes
|
| 19 |
if (!data.error) {
|
| 20 |
$(thisForm).hide();
|
| 21 |
}
|
| 22 |
// Insert the response (voting result or error message)
|
| 23 |
$(data.response).insertBefore(thisForm);
|
| 24 |
}
|
| 25 |
};
|
| 26 |
// Tell the server we are passing the form values with ajax and attach the function
|
| 27 |
$(this).prepend('<input type="hidden" name="ajax" value="true" />').ajaxForm(options);
|
| 28 |
});
|
| 29 |
}
|
| 30 |
|
| 31 |
Drupal.advpoll.nodeVoteAutoAttach = function() {
|
| 32 |
Drupal.advpoll.attachVoteAjax();
|
| 33 |
}
|
| 34 |
|
| 35 |
if (Drupal.jsEnabled) {
|
| 36 |
$(document).ready(function(){
|
| 37 |
Drupal.advpoll.nodeVoteAutoAttach();
|
| 38 |
});
|
| 39 |
};
|