Вход Регистрация
Файл: Luxe-Shop v6.0/templates/pay/shop.new.js
Строк: 247
<?php
$(function(){

    var 
isiShop = {
        
variables: {
            
currency'wmr',
            
currency_str'СЂСѓР±.',
            
discountPercent0
        
},
        
generateSum: function(count) {
            if (
count this.variables.good_count)
            {
                $(
'.choose_popup #currency').hide();
                return 
'Такого РєРѕР»-РІР° С‚овара РЅРµС‚';
            }
            else
            {
                var 
sum;
                
sum count this.getCurrency();
                
sum this.generateSumDiscount(sum);
                var 
ret;

                if (
this.variables.currency == 'qiwi')
                    return 
sum.toFixed(2);
                else
                    return 
parseFloat(sum.toFixed(3)); // 1.1, but 1.001
            
}
        },
        
getCurrency: function(){
            var 
price;
            if (
this.variables.currency == 'wmz')
            {
                
price this.variables.good_priceusd;
                
this.variables.currency_str '$';
            }
            else
            {
                
price this.variables.good_pricerub;
                
this.variables.currency_str 'СЂСѓР±.';
            }
    
            $(
'.choose_popup #currency').show().text(this.variables.currency_str);
    
            return 
price;
        },
        
generateSumDiscount: function(sum) {
            if (
this.variables.discountPercent 0)
            {
                
sum sum - (sum 100 this.variables.discountPercent);
            }
    
            return 
sum;
        }
    };
    
    $(
document).on('click''.choose_popup .fa-times, .success_popup .fa-times', function(e){
        $(
"#overlay, .choose_popup, .success_popup").fadeOut("slow");
        $(
'body').removeClass('popup-open');
    });
    
    $(
document).keyup(function(e) {
        if (
e.keyCode == 27) {
            $(
"#overlay, .choose_popup, .success_popup").fadeOut("slow");
            $(
'body').removeClass('popup-open');
        }
    });
    
    
/**
     * РћС‚крываем РїРѕРїР°Рї
     */
    
$(document).on('click''a.buy, .good-container', function(e){
        var 
$popup = $('.choose_popup');

        var 
tr = $(this).parents('tr'),
            
dData = $(this);

        if (
tr.length 0)
        {
            
data tr.data();
        }
        else
        {
            
data dData.data();
        }
    
        $(
'.order_popup').remove(); // if last form already exists
        
$('#order').show();
        $(
'body').addClass('popup-open');
    
        $.
each(data, function(ielem){
            
isiShop.variables['good_' i] = elem;
        });
    
        
isiShop.variables.discountPercent 0;
    
        
$popup.find('#good_title').text(data.title);
        
$popup.find('#good_count').val(data.mincount);
        
$popup.find('#discount_code').val('');

        $(
'.choose_popup #sum').text(isiShop.generateSum(data.mincount)); // РґРµС„олтная СЃСѓРјРјР° РїРѕ РјРёРЅ РєРѕР»-РІСѓ Р°РєРєРѕРІ
    
    
        
$("#overlay, .choose_popup").fadeIn("slow");

        return 
false;
    });
    
    
/**
     * РљРѕР»-РІРѕ Р°РєРєР°СѓРЅС‚РѕРІ РјРѕР¶РµС‚ Р±С‹С‚СЊ С‚олько С†РµР»С‹Рј С‡РёСЃР»РѕРј
     * Р Р°СЃС‡РёС‚ываем СЃСѓРјРјСѓ Р·Р°РєР°Р·Р°
     */
    
$("#good_count").on('keydown keyup', function (e) {
        
// Allow: backspace, delete, tab, escape, enter
        
if ($.inArray(e.keyCode, [4692713110]) !== -||
                
// Allow: Ctrl+A
            
(e.keyCode == 65 && e.ctrlKey === true) ||
                
// Allow: home, end, left, right, down, up
            
(e.keyCode >= 35 && e.keyCode <= 40)) {
            
// let it happen, don't do anything
            
return;
        }
    
        
// Ensure that it is a number and stop the keypress, 8 == backspace
        
if ((e.shiftKey || (e.keyCode 48 || e.keyCode 57)) && (e.keyCode 96 || e.keyCode 105) && e.keyCode != 8) {
            
e.preventDefault();
        }
    
        if (
e.type == 'keyup')
        {
            var 
count this.value || 0;
            $(
'.choose_popup #sum').text(isiShop.generateSum(count));
        }
    });
    
    
/**
     * РџРѕР»СѓС‡Р°РµРј СЃСѓРјРјСѓ СЃРєРёРґРєРё
     */
    
$('#discount_code').on('keydown keyup paste', function (e) {
        var 
dv this.value,
            
action = $(this).attr('data-action'),
            
count = $("#good_count").val() || 0;
    
        if (
e.type == 'keyup')
        {
            if (
dv.length == 11)
            {
                $.
post(action, { codedvgidisiShop.variables.good_idshopisiShop.variables.good_shopid }, function(json){
                    if (
json.ok)
                    {
                        
isiShop.variables.discountPercent parseInt(json.percent);
                        $(
'.choose_popup #sum').text(isiShop.generateSum(count))
                    }
                    else
                    {
                        
isiShop.variables.discountPercent 0;
                        $(
'.choose_popup #sum').text(isiShop.generateSum(count))
                    }
                }, 
'json');
            }
            else
            {
                
isiShop.variables.discountPercent 0;
                $(
'.choose_popup #sum').text(isiShop.generateSum(count))
            }
        }
    });

    
/**
     * Р’ыбираем РјРµС‚РѕРґ РѕРїР»Р°С‚С‹
     */
    
$(document).on('change''select[name=paymethod]', function(){
        
isiShop.variables.currency = $(this).val();
        var 
count = $("#good_count").val() || 0;
        $(
'.choose_popup #sum').text(isiShop.generateSum(count));
    });

    $(
document).on('click''input.clipboard', function(){
        
this.select();
    });

    $(
document).on('click''.order_popup h4 .close', function(){
        $(
'.order_popup').remove();
        $(
'#buy-btn').attr('disabled'false);
    });

    function 
validateEmail(email){
        var 
re = /^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/;
        return 
re.test(email);
    }

    
// РЎРѕР·РґР°РЅРёРµ Р·Р°РєР°Р·Р°
    
$(document).on('submit''#order', function(event){
        var 
dataS = $(this).serialize();

        if (
typeof isiShop != 'undefined')
        {
            var 
link = $(this).attr('action'),
                
email = $('input[name=email]'this).val(),
                
count = $('input[name=count]'this).val() || 0,
                
goodid isiShop.variables.good_id,
                
min_count isiShop.variables.good_mincount,
                
paymethod = $('select[name=paymethod]'this).val(),
                
count_accs isiShop.variables.good_count;

            
dataS dataS '&type=' goodid;
        }

        if (!
validateEmail(email))
        {
            
alert('Укажите Email Р°РґСЂРµСЃ');
            return 
false;
        }

        if (
parseInt(count) < parseInt(min_count))
        {
            
alert('РњРёРЅ. РєРѕР»-РІРѕ С‚овара ' min_count);
            return 
false;
        }

        if (
parseInt(count_accs) < parseInt(count))
        {
            
alert('Такого РєРѕР»РёС‡РµСЃС‚РІР° С‚овара РЅРµС‚');
            return 
false;
        }

        if (
paymethod == 0)
        {
            
alert('Выберите СЃРїРѕСЃРѕР± РѕРїР»Р°С‚С‹');
            return 
false;
        }

        $.
ajax({
            
type"POST",
            
urllink,
            
datadataS,
            
dataType"json",
            
success: function(json) {
                if (
json.order)
                {
                    $(
'#order').hide();
                    $(
'.choose_popup .popup-modal').append(json.order);
                }
                else
                if (
json.errors)
                {
                    if (
json.errors.global)
                        
alert(json.errors.global);
                    else
                    if (
json.errors.pay)
                        
alert(json.errors.pay);
                }
            },
            
error: function(data){
                
console.log(data);
                
alert('Временная РѕС€РёР±РєР° СЃРµСЂРІРµСЂР°. РџРѕРїСЂРѕР±СѓР№С‚Рµ РµС‰Рµ СЂР°Р·!');
            }
        });

        
event.preventDefault();
    });

    var 
hasLink '';
    
// РџСЂРѕРІРµСЂРєР° РѕРїР»Р°С‚С‹ С‚овара
    
$(document).on('submit''#pay', function(event){
        var 
chk = $('.check_pay .check'),
            
link = $(this).attr('action');

        
chk.addClass('loading').html('');
        $(
'.check_pay input[type="submit"]').prop('disabled'true);

        var 
dataS = $(this).serialize();

        $.
ajax({
            
type"POST",
            
urllink,
            
datadataS,
            
dataType"json",
            
success: function(json) {
                
chk.removeClass('loading');
                $(
'.check_pay input[type="submit"]').prop('disabled'false);

                if (
typeof json.redirect != 'undefined')
                {
                    
window.location.href json.redirect;
                }
                else
                if ((
json.ok && json.link) || hasLink != '')
                {
                    
hasLink json.link || hasLink;
                    $(
'.check_pay .check').html(hasLink);
                }
                else
                if (
json.errors)
                {
                    if (
json.errors.global)
                        $(
'.check_pay .check').html(json.errors.global);
                }
            },
            
error: function(data){
                
console.log(data);
                
chk.removeClass('loading');
                $(
'.check_pay input[type="submit"]').prop('disabled'false);
                $(
'.check_pay .check').html('Временная РѕС€РёР±РєР° СЃРµСЂРІРµСЂР°. РџРѕРїСЂРѕР±СѓР№С‚Рµ РµС‰Рµ СЂР°Р·!');
            }
        });

        
event.preventDefault();
    });
});
?>
Онлайн: 2
Реклама