Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (39 sloc) 1.3 KB
makesserves_swap = (val) ->
if val == "Serves"
$('#makes_what').hide()
$('#makes_num').attr('placeholder', 5)
else
$('#makes_what').show()
$('#makes_num').attr('placeholder', 20);
ingredient_number = 0
add = ->
ingredient_number++
amount = $('#amount').val()
unit = $('#unit').val()
item = $('#item').val()
[amount, unit, item] = [$('#amount').val(), $('#unit').val(), $('#item').val()]
hidden_amounts = $('<input>')
hidden_amounts.attr {type: 'hidden', name: 'amounts', value: amount}
hidden_units = $('<input>')
hidden_units.attr {type: 'hidden', name: 'units', value: unit}
hidden_items = $('<input>')
hidden_items.attr {type: 'hidden', name: 'items', value: item}
display_div = $('<div>')
display_div.attr 'id', 'ing' + ingredient_number
display_div.append(hidden_amounts, hidden_units, hidden_items)
display_div.append("#{amount} #{unit} of #{item}");
display_div.append $('<a>x</a>').attr('href',
"javascript:remove(#{ingredient_number});")
$('#ingredients').append display_div
addIfNeeded = ->
if $('#item').val
add();
$('#amount').focus()
return document.activeElement.id != 'item'
remove = (num) ->
$('#ing' + num).remove()
# Exports
window.addIfNeeded = addIfNeeded
window.makesserves_swap = makesserves_swap
window.remove = remove
window.add = add