Created
July 9, 2010 13:24
-
-
Save philippamarkovics/469453 to your computer and use it in GitHub Desktop.
This file contains 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
document.observe('dom:loaded', function() { | |
var products = $$('.product'); | |
var updateTotal = function() { | |
var total = 0; | |
products.each(function(product) { | |
var amount = product.down('.amount'); | |
if (!amount.value.blank() && ~~(amount.value) > 0) { | |
total += parseFloat(amount.value) * parseFloat(product.down('.entry-price').value); | |
} | |
}); | |
$('eur').update('EUR ' + total.toFixed(2)); | |
}; | |
products.each(function(product) { | |
var input = product.down('.amount') | |
input.observe('keyup', function(event) { | |
if (!input.value.blank() && ~~(input.value) > 0) { | |
updateTotal(); | |
} | |
}); | |
}); | |
}); | |
$('shop_form').observe('submit', function(event) { | |
event.stop(); | |
return false; | |
}) | |
$('order_button').observe('click', function() { | |
if ($('order_button').hasClassName('disabled')) { | |
return; | |
} | |
var email = $('field_email'); | |
email.next('.error')[email.value.blank() || /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(email.value) === false ? 'show' : 'hide'](); | |
$w('name tel address plz town').each(function(identifier) { | |
var field = $('field_' + identifier); | |
field.next('.error')[field.value.blank() ? 'show' : 'hide'](); | |
}); | |
if ($$('.error').all(function(error) { return !error.visible(); }) === true) { | |
$('shop_form').submit(); | |
} | |
}); | |
var agbs = $('agbs_checkbox'); | |
agbs.observe('click', function() { | |
$('order_button')[agbs.checked ? 'removeClassName' : 'addClassName']('disabled'); | |
}); | |
$('agbs_link').observe('click', function(event) { | |
event.stop(); | |
window.open('/agbs.html', "AGBs", "width=500,height=500,scrollbars=yes,status=no,toolbar=no,menubar=no"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment