Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.86 KB | None | 0 0
  1. $(function() {
  2. var shopScript = '/ajax';
  3. var openingCase = false;
  4. var winnersInterval = 5*1000;
  5. var inventoryInterval = 60*1000;
  6. var paySum;
  7.  
  8.  
  9. /*var c_case = 'eSports 2014 Summer';
  10. $.ajax({
  11. url: '/index.php/main/update_weapon',
  12. type: 'POST',
  13. data: {
  14. data: JSON.stringify(cases['Winter Offensive']),
  15. case_n: c_case,
  16. },
  17. success: function(data) {
  18. alert('ok');
  19. },
  20. error: function() {
  21. alert('error')
  22. }
  23. })*/
  24.  
  25. $('.thumbnail').hover(
  26. function(){
  27. $(this).find('.caption').fadeIn(250); //.fadeIn(250)
  28. },
  29. function(){
  30. $(this).find('.caption').fadeOut(250); //.fadeOut(205)
  31. }
  32. );
  33.  
  34. $('.enter-circle').mouseenter(function(){
  35. $(".enter-text").show();
  36. });
  37.  
  38. $(".enter-circle").mouseleave(function(){
  39. $(".enter-text").hide();
  40. });
  41.  
  42. $('.no-auth').click(function() {
  43. $('#auth').arcticmodal({
  44. closeOnOverlayClick: false,
  45. openEffect: {type: 'fade', speed: 400},
  46. closeEffect: {type: 'fade', speed: 5},
  47. })
  48.  
  49. })
  50.  
  51. $('.item-wrapper:gt('+($('.item-wrapper').length - 6)+')').addClass('small')
  52.  
  53. $('[data-modal]').click(function() {
  54. $($(this).data('modal')).arcticmodal();
  55. return false;
  56. })
  57.  
  58.  
  59. $('[data-bonus]').click(function() {
  60. paySum = $(this).data('sum');
  61. var bonus = $(this).data('bonus');
  62. $('#paySum').text(paySum + n2w(paySum, [' рубль', ' рубля', ' рублей']))
  63. $('#payBonus').text('+ '+bonus+' Р±РѕРЅСѓСЃ')
  64. return false;
  65. })
  66.  
  67. $(document).on('click', '.btn-repeat', function(e) {
  68. var that = $(this);
  69. var prev = that.text()
  70. that.text('Подождите...').attr('disabled', 'disabled');
  71. $.ajax({
  72. url: shopScript,
  73. type: 'POST',
  74. dataType: 'json',
  75. data: { action: 'orderRepeat', order_id: that.data('order') },
  76. success: function(data) {
  77. if (data.status == 'success') {
  78. }
  79. else {
  80. }
  81. that.text('Готово').attr('disabled', 'disabled');
  82. },
  83. error: function() {
  84. alert('Произошла ошибка. Попробуйте еще раз')
  85. that.text(prev).attr('disabled', null)
  86. }
  87. })
  88. })
  89.  
  90.  
  91. $('form').submit(function() {
  92. return false;
  93. })
  94.  
  95. $(document).on('keypress', '.balanceInput', function(e) {
  96. if (!(e.which >= 48 && e.which <=57)) {
  97. e.preventDefault();
  98. }
  99. if (e.which == 13) $(this).next().click()
  100. })
  101.  
  102. var paySystems = $('#paySystems')
  103. $(document).on('click', '.addbal', function(e) {
  104. var userPanelError = $('.userPanelError')
  105. userPanelError.text('')
  106.  
  107. paySum = parseInt($(this).prev().val());
  108.  
  109.  
  110. $('#paySum').text(paySum + n2w(paySum, [' рубль', ' рубля', ' рублей']))
  111. $('#payBonus').text('+ '+0+' Р±РѕРЅСѓСЃ')
  112. paySystems.arcticmodal()
  113. })
  114.  
  115. $(document).on('click', '.paytype', function(e) {
  116. $.ajax({
  117. url: shopScript,
  118. type: 'POST',
  119. dataType: 'json',
  120. data: {
  121. action: 'addbalance',
  122. data: paySum,
  123. system: $(this).data('system'),
  124. },
  125. success: function(data) {
  126. if (data.status == 'success') {
  127. if (data.form) {
  128. var form = $('<form action="'+data.form.action+'" method="post"></form>')
  129. $.each(data.form.data, function(key, value) {
  130. form.append('<input type="hidden" name="'+key+'" value="'+value+'" />')
  131. })
  132. $(document.body).append(form)
  133. form.submit()
  134. }
  135. else {
  136. document.location = data.url;
  137. }
  138. }
  139. else {
  140. }
  141. },
  142. error: function() {
  143. alert('Произошла ошибка! Попробуйте еще раз')
  144. }
  145. })
  146. })
  147. $(document).on('click', '#save-url', function(e) {
  148. var that = $(this);
  149. var prevHtml = that.html();
  150.  
  151. that.text('Подождите...')
  152. var userPanelError = $('.userPanelError')
  153. userPanelError.text('')
  154.  
  155. $.ajax({
  156. url: '/index.php/main/ajax_savelink',
  157. type: 'POST',
  158. dataType: 'json',
  159. data: {
  160. action: 'saveLink',
  161. data: that.prev().val()
  162. },
  163. success: function(data) {
  164. if (data.status == 'success') {
  165. that.html(prevHtml)
  166. }
  167. else {
  168. that.html(prevHtml)
  169. }
  170. notification(data.msg);
  171. },
  172. error: function() {
  173. notification('Произошла ошибка! Попробуйте еще раз')
  174. that.html(prevHtml)
  175. }
  176. })
  177. })
  178.  
  179. $(document).on('click', '#utlink', function(e) {
  180. var that = $(this);
  181. var prevHtml = that.html();
  182.  
  183. that.text('Подождите...')
  184. var userPanelError = $('.userPanelError')
  185. userPanelError.text('')
  186.  
  187. $.ajax({
  188. url: '/index.php/main/ajax_savelink',
  189. type: 'POST',
  190. dataType: 'json',
  191. data: {
  192. action: 'saveLink',
  193. data: that.prev().val()
  194. },
  195. success: function(data) {
  196. if (data.status == 'success') {
  197. that.html(prevHtml)
  198. }
  199. else {
  200. that.html(prevHtml)
  201. }
  202. userPanelError.text(data.msg)
  203. },
  204. error: function() {
  205. userPanelError.text('Произошла ошибка! Попробуйте еще раз')
  206. that.html(prevHtml)
  207. }
  208. })
  209. })
  210.  
  211.  
  212. var lastWinners = $('#lastWinners')
  213. function loadLastWinners() {
  214. if (openingCase) return;
  215. $.ajax({
  216. url: '/index.php/main/ajax_lastorders',
  217. type: 'POST',
  218. dataType: 'json',
  219. data: {
  220. action: 'lastWinners'
  221. },
  222. success: function(data) {
  223. var nickname;
  224. try {
  225. data.reverse().forEach(function(item) {
  226. if (lastWinners.find('.item' + item.id).length == 0) {
  227.  
  228. if ( item.fake_nickname == '')
  229. nickname = item.v_nickname;
  230. else
  231. nickname = item.fake_nickname;
  232. var el = $(
  233. '<div title="'+item.weapon+'" class="oflo '+item.type+'">'+
  234. '<img src="'+getImage(item.weapon_image,150,150)+'" />'+
  235. '<div class="ofloname">'+nickname+'</div>'+
  236. '</div>'
  237. )
  238. el.hide().addClass('item'+item.id);
  239. lastWinners.prepend(el)
  240. el.fadeIn(1000)
  241. }
  242. })
  243. lastWinners.find(".oflo:gt(5)").remove()
  244. $('.oflo').tooltip()
  245. }
  246. catch(e) {
  247. }
  248. },
  249. error: function() {
  250. }
  251. })
  252. }
  253.  
  254. function trade() {
  255. $.ajax({
  256. url: '/index.php/main/ajax_tradethings',
  257. type: 'POST',
  258. dataType: 'json',
  259. data: {
  260. action: 'trade'
  261. },
  262. success: function() {
  263. },
  264. error: function() {
  265. }
  266. })
  267. }
  268.  
  269. function inventory() {
  270. $.ajax({
  271. url: '/index.php/main/ajax_loadinventory',
  272. type: 'POST',
  273. dataType: 'json',
  274. data: {
  275. action: 'trade'
  276. },
  277. success: function() {
  278. },
  279. error: function() {
  280. }
  281. })
  282. }
  283.  
  284. function send() {
  285. $.ajax({
  286. url: '/index.php/main/ajax_sendthings',
  287. type: 'POST',
  288. dataType: 'json',
  289. data: {
  290. action: 'trade'
  291. },
  292. success: function() {
  293. },
  294. error: function() {
  295. }
  296. })
  297. }
  298.  
  299. loadLastWinners()
  300. setInterval(loadLastWinners, winnersInterval)
  301. setInterval(trade, 60000)
  302. setInterval(send, 60000)
  303. setInterval(inventory, inventoryInterval)
  304.  
  305. var caseItems = $('#caseItems')
  306. var casesCarusel = $('#casesCarusel')
  307. var itemmodal = $('#itemmodal')
  308. var currentCase;
  309. var currentCasePrice;
  310. var upchancePrice = 0;
  311. $('.item').click(function(e) {
  312. currentCase = $(this).data('key')
  313. currentimg = $(this).data('img')
  314. currentCasePrice = $(this).data('price')
  315. upchancePrice = 0
  316. $('.upchance').removeClass('active')
  317. $('#currentCasePrice').text(currentCasePrice)
  318. $('#upchancePrice').text('')
  319. $('.case-name').text(currentCase)
  320. $('.case-info img').attr('src', currentimg );
  321. $('.syserrbox').hide()
  322. itemmodal.arcticmodal({
  323. closeOnOverlayClick: false,
  324. openEffect: {type: 'fade', speed: 400},
  325. closeEffect: {type: 'fade', speed: 5},
  326. beforeClose: function() {
  327. return !openingCase;
  328. },
  329. beforeOpen: function() {
  330. //caseItems.html('')
  331. },
  332. beforeOpen: function() {
  333. var el = ''
  334. cases[currentCase].forEach(function(item, index) {
  335. el += '<li class="weaponblock weaponblock1 '+item[2]+'">'+
  336. '<img src="'+getImage(item[3], 125, 125)+'" />'+
  337. '<div class="weaponblockinfo"><span>'+getName(item[0])+'<br/>'+getName(item[1])+'</span></div>'+
  338. '</li>'
  339. })
  340. caseItems.html(el)
  341. fillCarusel()
  342. }
  343. })
  344. })
  345.  
  346. function fillCarusel() {
  347. var a1 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'milspec' }).slice(0).mul(5).shuffle()
  348. var a2 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'restricted' }).slice(0).mul(5).shuffle()
  349. var a3 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'classified' }).slice(0).mul(4).shuffle()
  350. var a4 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'covert' }).slice(0).mul(4).shuffle()
  351. var a5 = cases[currentCase].filter(function(weapon) { return weapon[2] == 'rare' }).slice(0).mul(2).shuffle()
  352.  
  353. var arr = a1.concat(a2, a3, a4, a5).shuffle().shuffle().shuffle()
  354. var el = ''
  355. arr.forEach(function(item, index) {
  356. el += '<div class="weaponblock weaponblock2 '+item[2]+'">'+
  357. '<img src="'+getImage(item[3], 125, 125)+'" />'+
  358. '<div class="weaponblockinfo"><span>'+getName(item[0])+'<br/>'+getName(item[1])+'</span></div>'+
  359. '</div>'
  360. })
  361. casesCarusel.css("margin-left", "0px")
  362. casesCarusel.html(el)
  363. }
  364.  
  365. function updateBalance(data) {
  366. if (data.balance) $('.userBalance').text(data.balance)
  367. }
  368.  
  369. var caseOpenAudio = new Audio();
  370. caseOpenAudio.src = "/audio/open.wav";
  371. caseOpenAudio.volume = 0.2;
  372.  
  373. var caseCloseAudio = new Audio();
  374. caseCloseAudio.src = "/audio/close.wav";
  375. caseCloseAudio.volume = 0.2;
  376.  
  377. var caseScrollAudio = new Audio();
  378. caseScrollAudio.src = "/audio/scroll.wav";
  379. caseScrollAudio.volume = 0.2;
  380.  
  381. $('.upchance').click(function() {
  382. var that = $(this)
  383. upchancePrice = that.data('price')
  384. $('#upchancePrice').text('')
  385.  
  386. if (that.is('.active')) {
  387. that.removeClass('active')
  388. }
  389. else {
  390. $('.upchance').removeClass('active')
  391. that.addClass('active')
  392. $('#upchancePrice').text(' + ' + upchancePrice)
  393. }
  394. })
  395. $('#openCase').click(function() {
  396. var that = $(this)
  397.  
  398. var prevHtml = that.html()
  399. that.text('Открываем...').attr('disabled', 'disabled')
  400. $('.syserrbox').hide()
  401. openingCase = true
  402.  
  403. $.ajax({
  404. url: '/index.php/main/ajax_opencase',
  405. type: 'POST',
  406. dataType: 'json',
  407. data: {
  408. action: 'openCase',
  409. 'case': currentCase,
  410. 'upchancePrice': upchancePrice
  411. },
  412. success: function(data) {
  413. if (data.status == 'success') {
  414. updateBalance(data)
  415. var weapon = data.weapon
  416.  
  417. var weaponName = weapon.name
  418.  
  419. $('#casesCarusel > div:nth-child(30), #weaponBlock .recweap').removeClass('milspec restricted classified covert rare').addClass(weapon.type)
  420.  
  421. $('#casesCarusel > div:nth-child(30) .weaponblockinfo span').html((weapon.stattrack ? 'StatTrakв„ў ' : '') + weaponName.replace(' | ', '<br/>'))
  422. $('#casesCarusel > div:nth-child(30)').find('img').attr('src', getImage(weapon.image, 100, 100))
  423.  
  424. $('#weaponBlock .recweaptitle').toggleClass('stattrack', !!weapon.stattrack)
  425. $('#weaponBlock .recweaptitle .name').text(weaponName)
  426. $('#weaponBlock .recweap img').attr('src', getImage(weapon.image, 360, 360))
  427.  
  428. var vkTitle = 'Кейсы CS:GO - Открывай с выгодой'
  429. var vkText = (weapon.stattrack ? 'StatTrakв„ў ' : '') + weaponName
  430. vkText = 'Я выиграл ' + vkText
  431. var vkImage = getImage(weapon.image, 360, 360);
  432.  
  433. var a = 1431 + 16*124;
  434. $('#casesCarusel').animate({ marginLeft: -1 * Math.rand(a, a+109) }, {
  435. duration: 10000,
  436. easing: 'swing',
  437. //easing: 'easeInSine',
  438. start: function() {
  439. caseOpenAudio.play()
  440. },
  441. complete: function() {
  442. openingCase = false;
  443. caseCloseAudio.play()
  444. $('.shareBtn').html(VK.Share.button({
  445. url: 'http://'+document.domain+'/?utm_source=vkshare',
  446. title: vkTitle,
  447. description: vkText,
  448. image: vkImage,
  449. noparse: true
  450. }, {
  451. type: 'custom',
  452. text: '<img src="/images/vk_icon.png" /><span>Поделиться результатом</span>'
  453. }))
  454.  
  455. $("#sellBlock").hide()
  456. $("#aftersellBlock1").hide()
  457. $("#aftersellBlock2").hide()
  458. $("#aftersellBlock3").hide()
  459.  
  460. if (weapon.type == 'milspec') {
  461. $("#sellBlock").show()
  462.  
  463. $("#sellBlock .sellBtn .sellPrice").text(weapon.price)
  464. $("#aftersellBlock1 .sellPrice").text(weapon.price + n2w(weapon.price, [' рубль', ' рубля', ' рублей']))
  465. $("#sellBlock .sellBtn").data('order', weapon.id)
  466. $("#sellBlock .waitBtn").data('order', weapon.id)
  467. }
  468. else {
  469. $("#aftersellBlock3").show()
  470. }
  471.  
  472. setTimeout(function() {
  473. $('#weaponBlock').arcticmodal({
  474. closeOnOverlayClick: false,
  475. openEffect: {type: 'none', speed: 400},
  476. beforeClose: function() {
  477. that.text(prevHtml).attr('disabled', null)
  478. fillCarusel()
  479. }
  480. })
  481. }, 100)
  482. }
  483. })
  484. }
  485. else {
  486. updateBalance(data)
  487. $('#' + data.msg).fadeIn(500)
  488. if ( data.msg == 'authError' )
  489. {
  490. $('#auth').arcticmodal({
  491. closeOnOverlayClick: false,
  492. openEffect: {type: 'fade', speed: 400},
  493. closeEffect: {type: 'fade', speed: 5},
  494. })
  495. }
  496. that.text(prevHtml).attr('disabled', null)
  497. openingCase = false;
  498. }
  499. },
  500. error: function(data) {
  501. alert('Произошла ошибка');
  502. alert(dump(data));
  503. that.text(prevHtml).attr('disabled', null)
  504. openingCase = false;
  505. }
  506. })
  507. })
  508.  
  509. $(document).on('click', ".sellBtn, .waitBtn", function(e) {
  510. var that = $(this)
  511. var type = that.is(".sellBtn") ? 'sell' : 'wait';
  512. $.ajax({
  513. url: '/index.php/main/ajax_sellorwait',
  514. type: 'POST',
  515. dataType: 'json',
  516. data: { action: 'sellORwait', type: type, order_id: that.data('order') },
  517. success: function(data) {
  518. if (data.status == 'success') {
  519. if (that.is('.Hist')) {
  520. that.parents('td').first().html('')
  521. }
  522. else {
  523. $("#sellBlock").hide()
  524. type == 'sell' ? $("#aftersellBlock1").show() : $("#aftersellBlock2").show()
  525. }
  526. updateBalance(data)
  527. }
  528. else {
  529. }
  530. },
  531. error: function(data) {
  532. alert('Произошла ошибка. Попробуйте еще раз')
  533. }
  534. })
  535. })
  536. /*
  537. $.each(cases, function(key, box) {
  538. box.forEach(function(weapon) {
  539. var img = new Image()
  540. img.src = getImage(weapon[3]);
  541. })
  542. })
  543. */
  544. })
  545.  
  546. Array.prototype.shuffle = function() {
  547. var o = this;
  548. for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
  549. return o;
  550. }
  551. Array.prototype.mul = function(k) {
  552. var res = []
  553. for (var i = 0; i < k; ++i) res = res.concat(this.slice(0))
  554. return res
  555. }
  556. Math.rand = function getRandomInt(min, max) {
  557. return Math.floor(Math.random() * (max - min + 1)) + min;
  558. }
  559.  
  560. function dump(obj) {
  561. var out = "";
  562. if(obj && typeof(obj) == "object"){
  563. for (var i in obj) {
  564. out += i + ": " + obj[i] + "\n";
  565. }
  566. } else {
  567. out = obj;
  568. }
  569. alert(out);
  570. }
  571.  
  572. function notification(text) {
  573. $('<div id="note-report">'+ text +'</div>').appendTo('body').delay(3000).fadeOut(500);
  574. }
  575.  
  576.  
  577. function n2w(n, w) {
  578. n %= 100;
  579. if (n > 19) n %= 10;
  580.  
  581. switch (n) {
  582. case 1:
  583. return w[0];
  584. case 2:
  585. case 3:
  586. case 4:
  587. return w[1];
  588. default:
  589. return w[2];
  590. }
  591. }
  592. function getName(name) {
  593. var arr = name.split('|')
  594. return (arr.length == 1) ? name : arr[1]
  595. }
  596. function getImage(str, w, h) {
  597. w = w || 384
  598. h = h || 384
  599. str = str.replace(prefix, '')
  600. return '//steamcommunity-a.akamaihd.net/economy/image/'+ prefix + str + '/'+w+'fx'+h+'f'
  601. }
  602.  
  603. function addWinner(item) {
  604. var lastWinners = $('#lastWinners')
  605. var el = $(
  606. '<div title="'+item.weapon.name+'" class="oflo '+item.type+'">'+
  607. '<img src="'+getImage(item.weapon.image,150,150)+'" />'+
  608. '<div class="ofloname">'+item.userName+'</div>'+
  609. '</div>'
  610. )
  611. el.hide()
  612. lastWinners.prepend(el)
  613. el.fadeIn(1000)
  614.  
  615. lastWinners.find(".oflo:gt(5)").remove()
  616. $('.oflo').tooltip()
  617. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement