| 1 |
// $Id$
|
| 2 |
|
| 3 |
function uc_aac_calculate(element) {
|
| 4 |
var form = $(element).parents('form');
|
| 5 |
form.ajaxSubmit({
|
| 6 |
url: Drupal.settings.base_path + "?q=uc_aac",
|
| 7 |
dataType: 'json',
|
| 8 |
success: function(data) {
|
| 9 |
// Replace HTML elements with new values.
|
| 10 |
var node = $('#node-' + data.nid);
|
| 11 |
for (var i in data.replacements) {
|
| 12 |
var replacement = $(data.replacements[i]);
|
| 13 |
$(node).find('.' + i).after(replacement).remove();
|
| 14 |
}
|
| 15 |
|
| 16 |
// Update the add to cart form.
|
| 17 |
if (data.form) {
|
| 18 |
var action = form.attr('action');
|
| 19 |
$(form).after(data.form).next().attr('action', action).uc_aac_attach();
|
| 20 |
form.remove();
|
| 21 |
}
|
| 22 |
}
|
| 23 |
});
|
| 24 |
}
|
| 25 |
|
| 26 |
jQuery.fn.uc_aac_attach = function() {
|
| 27 |
$(this).find('select[@name^=attributes]').change(function() {
|
| 28 |
uc_aac_calculate(this);
|
| 29 |
});
|
| 30 |
$(this).find('input:radio[@name^=attributes]').click(function() {
|
| 31 |
uc_aac_calculate(this);
|
| 32 |
});
|
| 33 |
}
|
| 34 |
|
| 35 |
$(function() {
|
| 36 |
$('.add-to-cart').uc_aac_attach();
|
| 37 |
});
|