JSFiddle - React, Tailwind, and code Playground
by Chase Wilson
JavaScript
var polls = {};
(function () {
var currentOptionIndex = null;
polls = {
vote: function (questionsDiv) {
this.inputs(questionsDiv, function (input, pollQuestionId, checked) {
var openInputBox = '#poll_open_input_' + pollQuestionId.toString();
if (checked) {
try { jQuery(openInputBox).show(); } catch (e) {}
} else {
try { jQuery(openInputBox).hide(); } catch (ee) {}
}
});
},
inputs: function (questionsDiv, onInput) {
var inputs = jQuery('div#' + questionsDiv + ' .poll_questions');
jQuery(inputs).each(function (){
var input = this;
var pollQuestionId = jQuery(input).attr('id').match(/\d+/);
if(onFBJS()) {
var checked = jQuery(input).attr('checked');
} else {
var checked = jQuery(input).prop('checked');
}
onInput(input, pollQuestionId, checked);
});
},
submit: function (updateDiv, questionsDiv, submitButton, url, requireAuth, storeId) {
var votes = []; //json encode this since fb breaks with the objects
var voteString;
var foundVotes = false;
// ex: {"25":{},"26":{"open_input":"test"},"27":{}}
// to server: {"votes"=>"{\"25\":{},\"26\":{\"open_input\":\"test\"},\"27\":{}}"
this.inputs(questionsDiv, function (input, pollQuestionId, checked) {
if (checked) {
voteString = '';
foundVotes = true
var openInput = null;
try {
openInput = jQuery('#poll_open_input_field_' + pollQuestionId.toString()).val();
} catch (e) {}
voteString += "\"" + pollQuestionId.toString() + "\":{";
if (openInput) {
voteString += "\"open_input\":\"" + openInput + "\"";
}
voteString += '}';
votes.push(voteString);
}
});
votes = "{" +...