Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shop2.queue.amount = function() {
- var $document = $(document);
- function validate(input) {
- var kind = input.data('kind'),
- max = input.data('max'),
- val = Number(input.val()),
- amount = 0,
- available,
- amount_min = parseFloat(input.data('min')),
- multiplicity = parseFloat(input.data('multiplicity'));
- if (kind && max > 0) {
- amount = Number(input.val());
- if (amount > max) {
- available = max - amount + val;
- input.val(available);
- available = available.toFixed(4) - 0;
- shop2.msg(_s3Lang.JS_AVAILABLE_ONLY + ' ' + available, input);
- }
- }
- if (amount_min || multiplicity) {
- if (multiplicity) {
- var x = (val - amount_min) % multiplicity;
- if (x < (multiplicity / 2)) {
- val -= x;
- } else {
- val += multiplicity - x;
- }
- if (amount_min === 1 && multiplicity > 1) {
- val--;
- }
- val = val.toFixed(4) - 0;
- input.val(val);
- }
- if (amount_min > 0) {
- if (amount_min && val <= amount_min) {
- input.val(amount_min);
- }
- } else {
- if (val <= shop2.options.amountDefaultValue) {
- input.val(amountDefaultValue);
- }
- }
- }
- }
- $document.on('click', '.amount-minus', function() {
- var $this = $(this),
- text = $this.siblings('input:text'),
- value = text.getVal(),
- amount_min = parseFloat(text.data('min')),
- multiplicity = parseFloat(text.data('multiplicity'));
- if (value) {
- value = value[0];
- }
- if (amount_min && value <= amount_min) {
- return;
- }
- value = checkAmount(value, amount_min, multiplicity, -1);
- if (amount_min > 0) {
- if (value <= amount_min) {
- value = amount_min;
- }
- } else {
- if (value <= shop2.options.amountDefaultValue) {
- value = shop2.options.amountDefaultValue;
- }
- }
- text.val(value);
- text.trigger('change');
- });
- $document.on('click', '.amount-plus', function() {
- var $this = $(this),
- text = $this.siblings('input:text'),
- value = text.getVal(),
- amount_min = parseFloat(text.data('min')),
- multiplicity = parseFloat(text.data('multiplicity'));
- if (value) {
- value = value[0];
- }
- value = checkAmount(value, amount_min, multiplicity, 1);
- text.val(value);
- text.trigger('change');
- });
- function checkAmount(amount, amount_min, multiplicity, sign) {
- if (multiplicity > 0) {
- amount += multiplicity * sign;
- } else {
- amount += shop2.options.amountDefaultInc * sign;
- }
- amount = amount.toFixed(4) - 0;
- return amount
- }
- $document.on('change', '.shop2-product-amount input:text', function() {
- var $this = $(this);
- validate($this);
- });
- $document.keyFilter('.shop2-product-amount input:text', {
- type: shop2.options.amountType
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement