daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var sortBaseGame = {
  2.     filter: {
  3.         maxInPage: 25,
  4.         price: 0,
  5.         name: ''
  6.     },
  7.     games: [],
  8.     toArray: function(){
  9.         var _game = $('.games-list .box-game');
  10.         for(var i = 0; i < _game.length; i++) {
  11.             var _build = {
  12.                 name: $($(_game)[i]).find('.box-game__title')[0].innerHTML,
  13.                 src: ($($(_game)[i]).find('img')).attr('src'),
  14.                 price: 0,
  15.                 drop: []
  16.             };
  17.             if($($(_game)[i]).find('.box-game__info').length){
  18.                 for(var d = 0; d < $($(_game)[i]).find('.box-game__info a').length; d++) {
  19.                     _build.drop.push({
  20.                         name: $($(_game)[i]).find('.box-game__info a')[d].innerHTML,
  21.                         link: $($($(_game)[i]).find('.box-game__info a')[d]).attr('href')
  22.                     });
  23.                 }
  24.             }
  25.             this.games.push(_build);
  26.         }
  27.         console.log(this.games);
  28.         this.build();
  29.     },
  30.     build: function(){
  31.         $('.games-list .box-game').remove();
  32.         if(this.filter.price == 1){
  33.             this.games.sort(function(a, b) {
  34.                 return parseFloat(a.price) - parseFloat(b.price);
  35.             });
  36.         }
  37.         else{
  38.             this.games.sort(function(a, b) {
  39.                 return parseFloat(b.price) - parseFloat(a.price);
  40.             });
  41.         }
  42.         var _showed = 0;
  43.         for(var i = 0; i < this.games.length; i++) {
  44.             if(_showed >= this.filter.maxInPage){
  45.                 break;
  46.             }
  47.             if(this.filter.name == '' || (this.games[i].name.toLowerCase().indexOf((this.filter.name).toLowerCase()) > -1)) {
  48.                 var _games = '';
  49.                 for(var d = 0; d < this.games[i].drop.length; d++){
  50.                     _games += '<a href="'+this.games[i].drop[d].link+'" target="_blank">'+this.games[i].drop[d].name+'</a>';
  51.                 }
  52.                 var _build = '<div class="box-game">\
  53.                     <img src="'+this.games[i].src+'" style="width:161px;height:197px">\
  54.                     <div class="box-game__title gold">'+this.games[i].name+'</div>\
  55.                     '+(this.games[i].drop.length ? '<div class="box-game__info"><strong>Grę znajdziesz w skrzyniach:</strong>\
  56.                     '+_games+'\
  57.                     </div>\
  58.                     ' : '')+'\
  59.                 </div>';
  60.                 $('.games-list').append(_build);
  61.                 _showed++;
  62.             }
  63.         }
  64.     }
  65. }
  66.  
  67. sortBaseGame.toArray();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top