/*! Project: lol
 *  Version: 1.1.0
 *  Date: 2016-05-24 02:44:13 PM
 *  Author: 
 */$(function(){function a(a){var b=location.search.match(new RegExp("[?&]"+a+"=([^&]*)(&?)","i"));return b?decodeURIComponent(b[1]):b}var b=encodeURIComponent(a("serverName")),c=encodeURIComponent(a("playerName")),d=a("gameZone"),e=a("userId"),f=a("championId"),g=(a("favor"),a("hero"));encodeURIComponent($.cookie("boxServerName")),encodeURIComponent($.cookie("boxPlayerName"));jiathis_config={title:"#无盒子 不开撸# 我是"+c+"，我在使用LOL盒子。来看看我的战斗力有多少吧！",appkey:{tsina:"3629014272",tqq:"801220649",qzone:"100302822"},summary:" ",ralateuid:{tsina:"2909042820"}},playerMostUsedHero&&(jiathis_config.pic="http://lolbox.duowan.com/images/champions/"+playerMostUsedHero+"_120x120.png"),SnsShare&&SnsShare.init();var h=function(){this.baseUrl="http://api.lolbox.duowan.com/api/v2/player/",this.serverName=b,this.playerName=c,this.favorate=0,this.suffix="&serverName="+this.serverName+"&playerName="+this.playerName+"&favorate="+this.favorate,g&&(this.suffix+="&hero="+g),this.p=1,this.listData=null,this.$loading=$("#loading"),this.$recordDetail=$("#recordDetail"),this.$boxContentTemplate=$("#boxContentTemplate"),this.$boxContent=$("#boxContent"),this.$recordDetail=$("#recordDetail"),this.$recordDetailTemplate=$("#recordDetailTemplate"),this.$collect=$("#collect"),this.$recordTarget=$("#recordTarget"),this.$body=$("body"),this.$wanScriptName=$("#wanScriptName")};h.prototype={constructor:h,init:function(){var a=this;this._getListData().done(function(f,g,h){if(h&&h.status&&200==h.status){var i=f.game_list,j=i.slice(0,8);a.isSelf=f.is_myself,a.listData=i,a.totalPage=Math.ceil(i.length/8),a._renderList(j);var k=f.isSelf?"我的收藏":"TA的收藏";a.$collect.html(k);var l=i[0]?i[0].game_zone.alias:null,m=l?decodeURIComponent(c)+"("+l+")":decodeURIComponent(c);a.$recordTarget.attr("href","playerDetail.html?serverName="+b+"&playerName="+c+"&userId="+e+"&gameZone="+d).html(m)}}).fail(function(){}),this.$collect.on("click",function(b){b.preventDefault();for(var c=[],d=0,e=a.listData.length;e>d;d++){var f=a.listData[d];f.collect&&c.push(f)}a.listData=c;var g=c.slice(0,8);a.$recordDetail.html(""),a._renderList(g)}),this.$body.delegate(".zj-page .zj-s","click",function(b){b.preventDefault();var c=$(this).attr("data-page");0!=c&&c!=a.totalPage+1&&(a.p=c,a._renderList(a.listData.slice(8*(c-1),8*c)))}),this.$body.delegate(".zj-page .go-page","click",function(b){b.preventDefault();var c=$(".zj-cur").val();0>=c||c>=a.totalPage+1||(a.p=c,a._renderList(a.listData.slice(8*(c-1),8*c)))}),this.$body.delegate(".zj-page .zj-cur","keyup",function(b){if(13==event.keyCode){var c=$(this).val();if(0>=c||c>=a.totalPage+1)return;a.p=c,a._renderList(a.listData.slice(8*(c-1),8*c))}}),this.$body.delegate(".l-box>ul>li","click",function(b){b.preventDefault();var c=$(this).attr("data-id");$(this).addClass("hover").siblings().removeClass("hover"),a.matchId=c,a._getDetailDataDone(c)}),this.$body.delegate(".fav-btn","click",function(a){a.preventDefault(),a.stopPropagation();var b=$(this).hasClass("add-fav"),c=this,f=b?"collect":"delete",g=parseInt($(this).attr("data-id")),h="http://api.lolbox.duowan.com/api/v2/player/"+d+"/"+e+"/game/"+f+"/?game_id="+g;$.ajax({url:h,type:"get",dataType:"jsonp",success:function(a){console.log(a),a&&(b?$(c).removeClass("add-fav").addClass("fav").attr("title","点击删除此收藏"):confirm("确认删除此收藏吗？")&&$(c).removeClass("fav").addClass("add-fav").attr("title","点击收藏比赛"))}})})},_getListData:function(){var a=this.baseUrl+d+"/"+e+"/game_recent/";return f&&(a=a+"?champion_id="+f),$.ajax({url:a,type:"GET",dataType:"jsonp"})},_getDetailData:function(a){var b=this.baseUrl+d+"/"+e+"/game/"+a+"/";return $.ajax({url:b,type:"GET",dataType:"jsonp"})},_getDetailDataDone:function(a){var b=this;this.$loading.show(),b.$recordDetail.hide(),this._getDetailData(a).done(function(a){b._renderDetail(a),b.$loading.hide(),b.$recordDetail.show()}).fail(function(){b.$loading.hide(),b.$recordDetail.show()})},_renderList:function(a){a&&a.length>0&&(this.matchId=a[0].game_id,this._getDetailDataDone(this.matchId)),a.totalPage=this.totalPage,a.p=this.p,a.isSelf=this.isSelf;var b=_.template(this.$boxContentTemplate.html());this.$boxContent.html(b({data:a}))},_renderDetail:function(a){var b;a.player_game_list?(b=_.template(this.$recordDetailTemplate.html()),this.$recordDetail.html(b({data:a}))):(b="<div class='tip-no-data'><img src='img/clothes-commit-fail.png'><p>由于未知原因，此场比赛消失在遥远的二次元空间中。</p></div>",this.$recordDetail.html(b))}};var i=new h;i.init()});