Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function() {
- var shopScript = '/ajax';
- var openingCase = false;
- var winnersInterval = 5*1000;
- var inventoryInterval = 60*1000;
- var paySum;
- /*var c_case = 'eSports 2014 Summer';
- $.ajax({
- url: '/index.php/main/update_weapon',
- type: 'POST',
- data: {
- data: JSON.stringify(cases['Winter Offensive']),
- case_n: c_case,
- },
- success: function(data) {
- alert('ok');
- },
- error: function() {
- alert('error')
- }
- })*/
- $('.thumbnail').hover(
- function(){
- $(this).find('.caption').fadeIn(250); //.fadeIn(250)
- },
- function(){
- $(this).find('.caption').fadeOut(250); //.fadeOut(205)
- }
- );
- $('.enter-circle').mouseenter(function(){
- $(".enter-text").show();
- });
- $(".enter-circle").mouseleave(function(){
- $(".enter-text").hide();
- });
- $('.no-auth').click(function() {
- $('#auth').arcticmodal({
- closeOnOverlayClick: false,
- openEffect: {type: 'fade', speed: 400},
- closeEffect: {type: 'fade', speed: 5},
- })
- })
- $('.item-wrapper:gt('+($('.item-wrapper').length - 6)+')').addClass('small')
- $('[data-modal]').click(function() {
- $($(this).data('modal')).arcticmodal();
- return false;
- })
- $('[data-bonus]').click(function() {
- paySum = $(this).data('sum');
- var bonus = $(this).data('bonus');
- $('#paySum').text(paySum + n2w(paySum, [' рубль', ' рубля', ' рублей']))
- $('#payBonus').text('+ '+bonus+' Р±РѕРЅСѓСЃ')
- return false;
- })
- $(document).on('click', '.btn-repeat', function(e) {
- var that = $(this);
- var prev = that.text()
- that.text('Подождите...').attr('disabled', 'disabled');
- $.ajax({
- url: shopScript,
- type: 'POST',
- dataType: 'json',
- data: { action: 'orderRepeat', order_id: that.data('order') },
- success: function(data) {
- if (data.status == 'success') {
- }
- else {
- }
- that.text('Готово').attr('disabled', 'disabled');
- },
- error: function() {
- alert('Произошла ошибка. Попробуйте еще раз')
- that.text(prev).attr('disabled', null)
- }
- })
- })
- $('form').submit(function() {
- return false;
- })
- $(document).on('keypress', '.balanceInput', function(e) {
- if (!(e.which >= 48 && e.which <=57)) {
- e.preventDefault();
- }
- if (e.which == 13) $(this).next().click()
- })
- var paySystems = $('#paySystems')
- $(document).on('click', '.addbal', function(e) {
- var userPanelError = $('.userPanelError')
- userPanelError.text('')
- paySum = parseInt($(this).prev().val());
- $('#paySum').text(paySum + n2w(paySum, [' рубль', ' рубля', ' рублей']))
- $('#payBonus').text('+ '+0+' Р±РѕРЅСѓСЃ')
- paySystems.arcticmodal()
- })
- $(document).on('click', '.paytype', function(e) {
- $.ajax({
- url: shopScript,
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'addbalance',
- data: paySum,
- system: $(this).data('system'),
- },
- success: function(data) {
- if (data.status == 'success') {
- if (data.form) {
- var form = $('<form action="'+data.form.action+'" method="post"></form>')
- $.each(data.form.data, function(key, value) {
- form.append('<input type="hidden" name="'+key+'" value="'+value+'" />')
- })
- $(document.body).append(form)
- form.submit()
- }
- else {
- document.location = data.url;
- }
- }
- else {
- }
- },
- error: function() {
- alert('Произошла ошибка! Попробуйте еще раз')
- }
- })
- })
- $(document).on('click', '#save-url', function(e) {
- var that = $(this);
- var prevHtml = that.html();
- that.text('Подождите...')
- var userPanelError = $('.userPanelError')
- userPanelError.text('')
- $.ajax({
- url: '/index.php/main/ajax_savelink',
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'saveLink',
- data: that.prev().val()
- },
- success: function(data) {
- if (data.status == 'success') {
- that.html(prevHtml)
- }
- else {
- that.html(prevHtml)
- }
- notification(data.msg);
- },
- error: function() {
- notification('Произошла ошибка! Попробуйте еще раз')
- that.html(prevHtml)
- }
- })
- })
- $(document).on('click', '#utlink', function(e) {
- var that = $(this);
- var prevHtml = that.html();
- that.text('Подождите...')
- var userPanelError = $('.userPanelError')
- userPanelError.text('')
- $.ajax({
- url: '/index.php/main/ajax_savelink',
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'saveLink',
- data: that.prev().val()
- },
- success: function(data) {
- if (data.status == 'success') {
- that.html(prevHtml)
- }
- else {
- that.html(prevHtml)
- }
- userPanelError.text(data.msg)
- },
- error: function() {
- userPanelError.text('Произошла ошибка! Попробуйте еще раз')
- that.html(prevHtml)
- }
- })
- })
- var lastWinners = $('#lastWinners')
- function loadLastWinners() {
- if (openingCase) return;
- $.ajax({
- url: '/index.php/main/ajax_lastorders',
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'lastWinners'
- },
- success: function(data) {
- var nickname;
- try {
- data.reverse().forEach(function(item) {
- if (lastWinners.find('.item' + item.id).length == 0) {
- if ( item.fake_nickname == '')
- nickname = item.v_nickname;
- else
- nickname = item.fake_nickname;
- var el = $(
- '<div title="'+item.weapon+'" class="oflo '+item.type+'">'+
- '<img src="'+getImage(item.weapon_image,150,150)+'" />'+
- '<div class="ofloname">'+nickname+'</div>'+
- '</div>'
- )
- el.hide().addClass('item'+item.id);
- lastWinners.prepend(el)
- el.fadeIn(1000)
- }
- })
- lastWinners.find(".oflo:gt(5)").remove()
- $('.oflo').tooltip()
- }
- catch(e) {
- }
- },
- error: function() {
- }
- })
- }
- function trade() {
- $.ajax({
- url: '/index.php/main/ajax_tradethings',
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'trade'
- },
- success: function() {
- },
- error: function() {
- }
- })
- }
- function inventory() {
- $.ajax({
- url: '/index.php/main/ajax_loadinventory',
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'trade'
- },
- success: function() {
- },
- error: function() {
- }
- })
- }
- function send() {
- $.ajax({
- url: '/index.php/main/ajax_sendthings',
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'trade'
- },
- success: function() {
- },
- error: function() {
- }
- })
- }
- loadLastWinners()
- setInterval(loadLastWinners, winnersInterval)
- setInterval(trade, 60000)
- setInterval(send, 60000)
- setInterval(inventory, inventoryInterval)
- var caseItems = $('#caseItems')
- var casesCarusel = $('#casesCarusel')
- var itemmodal = $('#itemmodal')
- var currentCase;
- var currentCasePrice;
- var upchancePrice = 0;
- $('.item').click(function(e) {
- currentCase = $(this).data('key')
- currentimg = $(this).data('img')
- currentCasePrice = $(this).data('price')
- upchancePrice = 0
- $('.upchance').removeClass('active')
- $('#currentCasePrice').text(currentCasePrice)
- $('#upchancePrice').text('')
- $('.case-name').text(currentCase)
- $('.case-info img').attr('src', currentimg );
- $('.syserrbox').hide()
- itemmodal.arcticmodal({
- closeOnOverlayClick: false,
- openEffect: {type: 'fade', speed: 400},
- closeEffect: {type: 'fade', speed: 5},
- beforeClose: function() {
- return !openingCase;
- },
- beforeOpen: function() {
- //caseItems.html('')
- },
- beforeOpen: function() {
- var el = ''
- cases[currentCase].forEach(function(item, index) {
- el += '<li class="weaponblock weaponblock1 '+item[2]+'">'+
- '<img src="'+getImage(item[3], 125, 125)+'" />'+
- '<div class="weaponblockinfo"><span>'+getName(item[0])+'<br/>'+getName(item[1])+'</span></div>'+
- '</li>'
- })
- caseItems.html(el)
- fillCarusel()
- }
- })
- })
- function fillCarusel() {
- var a1 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'milspec' }).slice(0).mul(5).shuffle()
- var a2 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'restricted' }).slice(0).mul(5).shuffle()
- var a3 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'classified' }).slice(0).mul(4).shuffle()
- var a4 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'covert' }).slice(0).mul(4).shuffle()
- var a5 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'rare' }).slice(0).mul(2).shuffle()
- var arr = a1.concat(a2, a3, a4, a5).shuffle().shuffle().shuffle()
- var el = ''
- arr.forEach(function(item, index) {
- el += '<div class="weaponblock weaponblock2 '+item[2]+'">'+
- '<img src="'+getImage(item[3], 125, 125)+'" />'+
- '<div class="weaponblockinfo"><span>'+getName(item[0])+'<br/>'+getName(item[1])+'</span></div>'+
- '</div>'
- })
- casesCarusel.css("margin-left", "0px")
- casesCarusel.html(el)
- }
- function updateBalance(data) {
- if (data.balance) $('.userBalance').text(data.balance)
- }
- var caseOpenAudio = new Audio();
- caseOpenAudio.src = "/audio/open.wav";
- caseOpenAudio.volume = 0.2;
- var caseCloseAudio = new Audio();
- caseCloseAudio.src = "/audio/close.wav";
- caseCloseAudio.volume = 0.2;
- var caseScrollAudio = new Audio();
- caseScrollAudio.src = "/audio/scroll.wav";
- caseScrollAudio.volume = 0.2;
- $('.upchance').click(function() {
- var that = $(this)
- upchancePrice = that.data('price')
- $('#upchancePrice').text('')
- if (that.is('.active')) {
- that.removeClass('active')
- }
- else {
- $('.upchance').removeClass('active')
- that.addClass('active')
- $('#upchancePrice').text(' + ' + upchancePrice)
- }
- })
- $('#openCase').click(function() {
- var that = $(this)
- var prevHtml = that.html()
- that.text('Открываем...').attr('disabled', 'disabled')
- $('.syserrbox').hide()
- openingCase = true
- $.ajax({
- url: '/index.php/main/ajax_opencase',
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'openCase',
- 'case': currentCase,
- 'upchancePrice': upchancePrice
- },
- success: function(data) {
- if (data.status == 'success') {
- updateBalance(data)
- var weapon = data.weapon
- var weaponName = weapon.name
- $('#casesCarusel > div:nth-child(30), #weaponBlock .recweap').removeClass('milspec restricted classified covert rare').addClass(weapon.type)
- $('#casesCarusel > div:nth-child(30) .weaponblockinfo span').html((weapon.stattrack ? 'StatTrakв„ў ' : '') + weaponName.replace(' | ', '<br/>'))
- $('#casesCarusel > div:nth-child(30)').find('img').attr('src', getImage(weapon.image, 100, 100))
- $('#weaponBlock .recweaptitle').toggleClass('stattrack', !!weapon.stattrack)
- $('#weaponBlock .recweaptitle .name').text(weaponName)
- $('#weaponBlock .recweap img').attr('src', getImage(weapon.image, 360, 360))
- var vkTitle = 'Кейсы CS:GO - Открывай с выгодой'
- var vkText = (weapon.stattrack ? 'StatTrakв„ў ' : '') + weaponName
- vkText = 'Я выиграл ' + vkText
- var vkImage = getImage(weapon.image, 360, 360);
- var a = 1431 + 16*124;
- $('#casesCarusel').animate({ marginLeft: -1 * Math.rand(a, a+109) }, {
- duration: 10000,
- easing: 'swing',
- //easing: 'easeInSine',
- start: function() {
- caseOpenAudio.play()
- },
- complete: function() {
- openingCase = false;
- caseCloseAudio.play()
- $('.shareBtn').html(VK.Share.button({
- url: 'http://'+document.domain+'/?utm_source=vkshare',
- title: vkTitle,
- description: vkText,
- image: vkImage,
- noparse: true
- }, {
- type: 'custom',
- text: '<img src="/images/vk_icon.png" /><span>Поделиться результатом</span>'
- }))
- $("#sellBlock").hide()
- $("#aftersellBlock1").hide()
- $("#aftersellBlock2").hide()
- $("#aftersellBlock3").hide()
- if (weapon.type == 'milspec') {
- $("#sellBlock").show()
- $("#sellBlock .sellBtn .sellPrice").text(weapon.price)
- $("#aftersellBlock1 .sellPrice").text(weapon.price + n2w(weapon.price, [' рубль', ' рубля', ' рублей']))
- $("#sellBlock .sellBtn").data('order', weapon.id)
- $("#sellBlock .waitBtn").data('order', weapon.id)
- }
- else {
- $("#aftersellBlock3").show()
- }
- setTimeout(function() {
- $('#weaponBlock').arcticmodal({
- closeOnOverlayClick: false,
- openEffect: {type: 'none', speed: 400},
- beforeClose: function() {
- that.text(prevHtml).attr('disabled', null)
- fillCarusel()
- }
- })
- }, 100)
- }
- })
- }
- else {
- updateBalance(data)
- $('#' + data.msg).fadeIn(500)
- if ( data.msg == 'authError' )
- {
- $('#auth').arcticmodal({
- closeOnOverlayClick: false,
- openEffect: {type: 'fade', speed: 400},
- closeEffect: {type: 'fade', speed: 5},
- })
- }
- that.text(prevHtml).attr('disabled', null)
- openingCase = false;
- }
- },
- error: function(data) {
- alert('Произошла ошибка');
- alert(dump(data));
- that.text(prevHtml).attr('disabled', null)
- openingCase = false;
- }
- })
- })
- $(document).on('click', ".sellBtn, .waitBtn", function(e) {
- var that = $(this)
- var type = that.is(".sellBtn") ? 'sell' : 'wait';
- $.ajax({
- url: '/index.php/main/ajax_sellorwait',
- type: 'POST',
- dataType: 'json',
- data: { action: 'sellORwait', type: type, order_id: that.data('order') },
- success: function(data) {
- if (data.status == 'success') {
- if (that.is('.Hist')) {
- that.parents('td').first().html('')
- }
- else {
- $("#sellBlock").hide()
- type == 'sell' ? $("#aftersellBlock1").show() : $("#aftersellBlock2").show()
- }
- updateBalance(data)
- }
- else {
- }
- },
- error: function(data) {
- alert('Произошла ошибка. Попробуйте еще раз')
- }
- })
- })
- /*
- $.each(cases, function(key, box) {
- box.forEach(function(weapon) {
- var img = new Image()
- img.src = getImage(weapon[3]);
- })
- })
- */
- })
- Array.prototype.shuffle = function() {
- var o = this;
- for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
- return o;
- }
- Array.prototype.mul = function(k) {
- var res = []
- for (var i = 0; i < k; ++i) res = res.concat(this.slice(0))
- return res
- }
- Math.rand = function getRandomInt(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- function dump(obj) {
- var out = "";
- if(obj && typeof(obj) == "object"){
- for (var i in obj) {
- out += i + ": " + obj[i] + "\n";
- }
- } else {
- out = obj;
- }
- alert(out);
- }
- function notification(text) {
- $('<div id="note-report">'+ text +'</div>').appendTo('body').delay(3000).fadeOut(500);
- }
- function n2w(n, w) {
- n %= 100;
- if (n > 19) n %= 10;
- switch (n) {
- case 1:
- return w[0];
- case 2:
- case 3:
- case 4:
- return w[1];
- default:
- return w[2];
- }
- }
- function getName(name) {
- var arr = name.split('|')
- return (arr.length == 1) ? name : arr[1]
- }
- function getImage(str, w, h) {
- w = w || 384
- h = h || 384
- str = str.replace(prefix, '')
- return '//steamcommunity-a.akamaihd.net/economy/image/'+ prefix + str + '/'+w+'fx'+h+'f'
- }
- function addWinner(item) {
- var lastWinners = $('#lastWinners')
- var el = $(
- '<div title="'+item.weapon.name+'" class="oflo '+item.type+'">'+
- '<img src="'+getImage(item.weapon.image,150,150)+'" />'+
- '<div class="ofloname">'+item.userName+'</div>'+
- '</div>'
- )
- el.hide()
- lastWinners.prepend(el)
- el.fadeIn(1000)
- lastWinners.find(".oflo:gt(5)").remove()
- $('.oflo').tooltip()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement