Sha256: 776a75cbebe2a45a31e6353ba26b7969ff421c5e3aa9b28563abfbf648fbaff0

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

#= require lib/jquery.prevent_double_submit
#= require formol/subscriptions
#= require markitup/jquery.markitup.js
#= require markitup/sets/markdown/set.js

(($) ->
  $ ->
    $('form').preventDoubleSubmit()
    $('textarea').markItUp(mySettings)
    
    togglePollCheckbox = $('#topic_attach_poll')
    pollContainer = $('fieldset.poll ol')
    
    togglePoll = () ->
      pollContainer.toggle togglePollCheckbox.is(':checked')
      
    togglePoll()
    
    $(togglePollCheckbox).click () ->
      togglePoll()
    
    poll_options = $('.answers li.input')
    index = poll_options.length
    
    if index > 0
      $('a.add_poll_option').click ->
        id_replacement = [/_(\d)_/, '_' + index + '_']
        name_replacement = [/\[(\d)\]/, '[' + index + ']']
        replacement_meth  = String.prototype.replace
      
        new_line  = poll_options.eq(0).clone()
        new_id    = replacement_meth.apply(new_line.attr('id'), id_replacement)
        
        new_line.attr('id', new_id)
        
        new_line.appendTo(poll_options.parent())
        
        new_input = new_line.find('input')
        
        new_id = replacement_meth.apply(new_input.attr('id'), id_replacement)
        new_name  = replacement_meth.apply(new_input.attr('name'), name_replacement)
        
        new_input.attr('id', new_id)
        new_input.attr('name', new_name)
        new_input.val('')
        
        new_label = new_line.find('label')
        
        new_label.attr('for', new_id)
        
        index += 1
        
        false
)(jQuery)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
formol-0.0.5 app/assets/javascripts/formol/topics.js.coffee
formol-0.0.4 app/assets/javascripts/formol/topics.js.coffee