diff --git advpoll-display-binary-form.tpl.php advpoll-display-binary-form.tpl.php
new file mode 100644
index 0000000..b9b98ea
--- /dev/null
+++ advpoll-display-binary-form.tpl.php
@@ -0,0 +1,27 @@
+
+
diff --git advpoll-display-ranking-form.tpl.php advpoll-display-ranking-form.tpl.php
index b096eb7..a455848 100644
--- advpoll-display-ranking-form.tpl.php
+++ advpoll-display-ranking-form.tpl.php
@@ -12,29 +12,24 @@
* $tabledrag_group_class
*/
?>
-
diff --git advpoll-vote.js advpoll-vote.js
index e63a585..b81c647 100644
--- advpoll-vote.js
+++ advpoll-vote.js
@@ -44,7 +44,6 @@ Drupal.behaviors.handleWriteins = function(context) {
// No write-ins in this poll.
return;
}
- var ranOnce = false;
// Toggle display of the write-in text box for radios/checkboxes.
$(".vote-choices input[type=radio], .vote-choices input[type=checkbox]", poll).click(function() {
var isLast = $(this).val() == $(".vote-choices input[type=radio]:last, .vote-choices input[type=checkbox]:last", poll).val();
@@ -52,12 +51,6 @@ Drupal.behaviors.handleWriteins = function(context) {
// The logic here is tricky but intentional.
if (isLast || type == "radio") {
var showChoice = isLast && (type == "radio" || $(this).attr("checked"));
- if (!ranOnce && showChoice) {
- // If this is our first time, clone the Drupal-added write-in element
- // and add a new one next to the checkbox, then delete the old one.
- $(".writein-choice input", poll).clone().addClass("writein-choice").insertAfter($(this).parent()).end().parent().parent().remove();
- ranOnce = true;
- }
$(".writein-choice", poll).css("display", showChoice ? "inline" : "none");
if (showChoice) {
$(".writein-choice", poll)[0].focus();
@@ -71,12 +64,6 @@ Drupal.behaviors.handleWriteins = function(context) {
// Toggle display of the write-in text box for select boxes.
// Fire on change() rather than click(), for Safari compatibility.
$(".vote-choices select:last", poll).change(function() {
- if (!ranOnce) {
- // If this is our first time, clone the Drupal-added write-in element
- // and add a new one next to the checkbox, then delete the old one.
- $(".writein-choice input", poll).clone().addClass("writein-choice").insertAfter($(this)).end().parent().parent().remove();
- ranOnce = true;
- }
var showChoice = $(this).val() > 0;
var alreadyVisible = $(".writein-choice", poll).css("display") == "inline";
$(".writein-choice", poll).css("display", showChoice ? "inline" : "none");
@@ -165,7 +152,7 @@ Drupal.behaviors.rankingDragAndDrop = function(context) {
else {
// Hack to have tabledrag.js parse the new table rows.
$existingChoicesTable.removeClass('dragtable-processed');
- Drupal.attachBehaviors();
+ Drupal.attachBehaviors($existingChoicesTable);
}
$(".vote-status", mainForm).show().html(Drupal.t("Choices remaining: %choices", {"%choices" : maxChoices - currentChoices}));
if (currentChoices > maxChoices) {
diff --git advpoll.module advpoll.module
index f0fc6fa..d6071b3 100644
--- advpoll.module
+++ advpoll.module
@@ -199,9 +199,6 @@ function advpoll_init() {
// Load the mode include files.
_advpoll_list_modes();
- if (module_exists('jquery_ui')) {
- jquery_ui_add(array('ui.draggable', 'ui.droppable', 'ui.sortable'));
- }
}
/**
@@ -1661,6 +1658,13 @@ function advpoll_theme() {
'form' => NULL,
)
),
+ 'advpoll_voting_binary_form' => array(
+ 'template' => 'advpoll-display-binary-form',
+ 'file' => 'modes/binary.inc',
+ 'arguments' => array(
+ 'form' => NULL,
+ )
+ ),
);
}
diff --git modes/binary.inc modes/binary.inc
index 054d4d5..1edfc76 100644
--- modes/binary.inc
+++ modes/binary.inc
@@ -56,8 +56,6 @@ function advpoll_voting_binary_form(&$form_state, $node, $teaser, $page, $status
$form['choice'] = array(
'#options' => $list,
- '#prefix' => '',
- '#suffix' => '
',
'#tree' => TRUE,
);
@@ -77,8 +75,6 @@ function advpoll_voting_binary_form(&$form_state, $node, $teaser, $page, $status
// Add write-in text field if write-ins are enabled and user has permission.
if ($node->writeins && user_access('add write-ins')) {
$form['writein_choice'] = array(
- '#prefix' => '',
- '#suffix' => '
',
'#type' => 'textfield',
'#title' => t('Write-in vote'),
'#size' => 25,
@@ -303,18 +299,30 @@ function advpoll_voting_binary_form_validate($form, &$form_state) {
}
/**
- * Render the voting form.
+ * Process variables for advpoll-display-binary-form.tpl.php.
+ *
+ * The variables array contains the following arguments:
+ * - $form
+ *
+ * @see advpoll-display-binary-form.tpl.php
*/
-function theme_advpoll_voting_binary_form($form) {
- $message = drupal_render($form['message']);
+function advpoll_preprocess_advpoll_voting_binary_form(&$variables) {
+ $form = &$variables['form'];
+ $variables['message'] = drupal_render($form['message']);
- $output = "\n";
- $output .= drupal_render($form);
- if ($message) {
- $output .= "
$message
\n";
+ // If write-ins are used on this form.
+ if (isset($form['writein_choice'])) {
+ $variables['writein_choice'] = drupal_render($form['writein_choice']);
}
- $output .= "
\n";
- return $output;
+ $variables['form_id'] = $form['#id'];
+
+ // List of available choices in the poll.
+ $variables['choice_list'] = drupal_render($form['choice']);
+ // Take off the annoying colon & endlines that Drupal adds to each title.
+ $variables['choice_list'] = preg_replace('/[\n\r]*: <\/label>[\n\r]*/i', '', $variables['choice_list']);
+ // All remaining form elements.
+ $variables['form_submit'] = drupal_render($form);
+
}
/**
diff --git modes/ranking.inc modes/ranking.inc
index 0be7883..a890480 100644
--- modes/ranking.inc
+++ modes/ranking.inc
@@ -171,28 +171,27 @@ function advpoll_voting_ranking_form(&$form_state, &$node, $teaser, $page, $stat
*
* @see advpoll-display-ranking-form.tpl.php
*/
-function template_preprocess_advpoll_voting_ranking_form(&$variables) {
+function advpoll_preprocess_advpoll_voting_ranking_form(&$variables) {
$form = &$variables['form'];
$variables['message'] = drupal_render($form['message']);
- // If write-ins are used on this form.
+
+ // If write-ins are used on this form.
if (isset($form['writein_choice'])) {
$variables['writein_choice'] = drupal_render($form['writein_choice']);
}
+
$variables['form_id'] = $form['#id'];
- // Every form element that should be carried in drag needs this class.
- $variables['tabledrag_group_class'] = $form['#id'] . '-tabledrag-group';
- foreach (element_children($form['choice']) as $i) {
- $choice = &$variables['form']['choice'][$i];
- // Add draggable class - TODO: fix this.
- $choice['#attributes']['class'] = $variables['tabledrag_group_class'];
- //$form['choice'][$i]['#attributes']['class'] = $variables['tabledrag_group_class'];
- }
+
// List of available choices in the poll.
$variables['choice_list'] = drupal_render($form['choice']);
// Take off the annoying colon & endlines that Drupal adds to each title.
$variables['choice_list'] = preg_replace('/[\n\r]*: <\/label>[\n\r]*/i', '', $variables['choice_list']);
// All remaining form elements.
$variables['form_submit'] = drupal_render($form);
+
+ // Add tabledrag JavaScript.
+ drupal_add_tabledrag($form['#id'] . '-table', 'order', 'self', 'advpoll-choice-order', NULL, NULL, FALSE);
+
}
function advpoll_view_results_ranking($node, $teaser, $page) {