Created
          November 19, 2015 23:12 
        
      - 
      
- 
        Save spra85/c9b179c5b202f08e0083 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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