Use radix for javascript parseInt
This commit is contained in:
parent
19dec68c59
commit
1848edea8b
|
@ -15,3 +15,12 @@
|
||||||
//= require bootstrap
|
//= require bootstrap
|
||||||
//= require turbolinks
|
//= require turbolinks
|
||||||
//= require_tree .
|
//= require_tree .
|
||||||
|
|
||||||
|
parseIntNaN = function(value) {
|
||||||
|
parsed_value = parseInt(value, 10);
|
||||||
|
if (isNaN(parsed_value)) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return parsed_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,4 @@
|
||||||
ready = function() {
|
ready = function() {
|
||||||
parseIntNaN = function(value) {
|
|
||||||
parsed_value = parseInt(value);
|
|
||||||
if (isNaN(parsed_value)) {
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
return parsed_value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
increment_function = function() {
|
increment_function = function() {
|
||||||
target = $(this).data("target");
|
target = $(this).data("target");
|
||||||
$(target).val(parseIntNaN($(target).data("default")) + parseIntNaN($(this).val()));
|
$(target).val(parseIntNaN($(target).data("default")) + parseIntNaN($(this).val()));
|
||||||
|
|
|
@ -16,7 +16,7 @@ ready = function() {
|
||||||
|
|
||||||
increment_product = function(product_id) {
|
increment_product = function(product_id) {
|
||||||
input = $("#current_order").find(".order_item_wrapper[data-product=" + product_id + "]").find("input[type=number]");
|
input = $("#current_order").find(".order_item_wrapper[data-product=" + product_id + "]").find("input[type=number]");
|
||||||
$(input).val(parseInt($(input).val()) + 1).change();
|
$(input).val(parseIntNaN($(input).val()) + 1).change();
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#products_modal button").click(function() {
|
$("#products_modal button").click(function() {
|
||||||
|
@ -38,20 +38,20 @@ ready = function() {
|
||||||
|
|
||||||
$('tr.order_item_wrapper').hide();
|
$('tr.order_item_wrapper').hide();
|
||||||
$('tr.order_item_wrapper').filter(function() {
|
$('tr.order_item_wrapper').filter(function() {
|
||||||
return parseInt($(this).find('[type=number]').val()) > 0;
|
return parseIntNaN($(this).find('[type=number]').val()) > 0;
|
||||||
}).show();
|
}).show();
|
||||||
|
|
||||||
$('tr.order_item_wrapper input[type=number]').change(function() {
|
$('tr.order_item_wrapper input[type=number]').change(function() {
|
||||||
tr = $(this).closest('tr.order_item_wrapper')
|
tr = $(this).closest('tr.order_item_wrapper')
|
||||||
$(tr).toggle(parseInt($(this).val()) > 0);
|
$(tr).toggle(parseIntNaN($(this).val()) > 0);
|
||||||
$(tr).find("td").last().html(((parseInt($(tr).data("price")) * parseInt($(this).val())) / 100.0).toFixed(2))
|
$(tr).find("td").last().html(((parseIntNaN($(tr).data("price")) * parseIntNaN($(this).val())) / 100.0).toFixed(2))
|
||||||
recalculate();
|
recalculate();
|
||||||
})
|
})
|
||||||
|
|
||||||
recalculate = function() {
|
recalculate = function() {
|
||||||
/* Total Price */
|
/* Total Price */
|
||||||
array = $('tr.order_item_wrapper').map(function() {
|
array = $('tr.order_item_wrapper').map(function() {
|
||||||
return parseInt($(this).data("price")) * parseInt($(this).find("input[type=number]").val());
|
return parseIntNaN($(this).data("price")) * parseIntNaN($(this).find("input[type=number]").val());
|
||||||
})
|
})
|
||||||
sum = 0;
|
sum = 0;
|
||||||
array.each(function(i, el) { sum += el; });
|
array.each(function(i, el) { sum += el; });
|
||||||
|
@ -59,7 +59,7 @@ ready = function() {
|
||||||
|
|
||||||
/* Message when no product has been choosen */
|
/* Message when no product has been choosen */
|
||||||
$("#current_order #empty").toggle(!($('tr.order_item_wrapper input[type=number]').filter(function() {
|
$("#current_order #empty").toggle(!($('tr.order_item_wrapper input[type=number]').filter(function() {
|
||||||
return parseInt($(this).val()) > 0;
|
return parseIntNaN($(this).val()) > 0;
|
||||||
}).length));
|
}).length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue