Skip to content

Instantly share code, notes, and snippets.

@spra85
Created November 19, 2015 23:12
Show Gist options
  • Save spra85/c9b179c5b202f08e0083 to your computer and use it in GitHub Desktop.
Save spra85/c9b179c5b202f08e0083 to your computer and use it in GitHub Desktop.
var BarChart = {
render: function(responseData) {
}
};
module.exports = BarChart.render;
var barChart = require('./bar-chart');
var supportedTypes = {
'bar-chart': barChart
};
var Polls = {
defaults: {
pollSelector: '.poll',
types: 'bar-chart',
},
init: function(options) {
this.options = _.extend(this.defaults, options);
this.poll = $(this.options.pollSelector);
if (this.poll.length === 0) {
console.error('Poll could not be found for selector: ' + pollSelector);
return;
}
var selectedType = supportedTypes[this.options.type];
if (!selectedType) {
console.error('Unsupported type of vote response handler');
return;
}
this.voteResponseHandler = selectedType;
this.poll.find('.poll-answer').on('click', this.vote);
},
clearVotes: function() {
this.poll.find('.poll-answer').removeClass('selected-vote');
},
vote: function(event) {
$(event.target).addClass('selected-vote');
},
submitVote: function() {
var $selectedVote = this.poll.find('.poll-answer.selected-vote');
// POST to Sodahead vote api
$.post('api/v1/votes').success(this.successfulVote);
},
successfulVote: function(response) {
var response = this.voteResponseHandler(response);
// insert into DOM
}
};
module.exports = Polls;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment