|
@@ -0,0 +1,171 @@
|
|
|
+
|
|
|
+var itemTmpl = __inline('../../tpl/item.tmpl')
|
|
|
+class Hero {
|
|
|
+ constructor () {
|
|
|
+ this.getData()
|
|
|
+ this.metaData = {}
|
|
|
+ this.allData = []
|
|
|
+ this.type = 'hero'
|
|
|
+ }
|
|
|
+ getData() {
|
|
|
+ var self = this
|
|
|
+ $.ajax({
|
|
|
+ url: 'http://lol.duowan.com/s/zzqdata.js',
|
|
|
+ dataType: 'jsonp',
|
|
|
+ jsonpCallback: 'zzqjsonp',
|
|
|
+ success: function(ret) {
|
|
|
+ self.metaData = ret
|
|
|
+ _.each(self.metaData.equipment.data,function(i) { //装备点击不跳转
|
|
|
+ i.link = 'javasctipt:'
|
|
|
+ })
|
|
|
+ self.allData = [].concat(ret.hero.data,ret.equipment.data,ret.littleHero.data)
|
|
|
+ self.init()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ bindEvent() {
|
|
|
+ var self = this
|
|
|
+
|
|
|
+ //大分类
|
|
|
+ $('.tab-hd-item').on('click', function() {
|
|
|
+ $('.tab-hd-item').removeClass('active')
|
|
|
+ $(this).addClass('active')
|
|
|
+ var type = $(this).attr('data-type')
|
|
|
+ $('.hero-bd-box').toggle()
|
|
|
+ $('.compound-wrap').toggle()
|
|
|
+ if(!type) {
|
|
|
+ $('.hero-bd-box').hide()
|
|
|
+ $('.compound-wrap').show()
|
|
|
+ return false
|
|
|
+ }else {
|
|
|
+ $('.hero-bd-box').show()
|
|
|
+ $('.compound-wrap').hide()
|
|
|
+ }
|
|
|
+ $('[data-tab-sort]').removeClass('active')
|
|
|
+ $('[data-tab-sort|='+type+']').addClass('active')
|
|
|
+ self.renderList(self.metaData[type].data)
|
|
|
+ return false
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ //小分类
|
|
|
+ $('.hero-sort span:not([data-tab-sort|=hero] span)').on('click', function() {
|
|
|
+ var type = $(this).parent().attr('data-tab-sort')
|
|
|
+ var sort = $(this).attr('data-sort')
|
|
|
+ $('.hero-sort span').removeClass('active')
|
|
|
+ $(this).addClass('active')
|
|
|
+
|
|
|
+
|
|
|
+ var typeList = self.metaData[type].data
|
|
|
+ if(sort) {
|
|
|
+ var reg = new RegExp(sort)
|
|
|
+ var list = []
|
|
|
+ for(var i = 0; i < typeList.length; i++) {
|
|
|
+ if(reg.test(typeList[i].sort)) {
|
|
|
+ list.push(typeList[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.renderList(list)
|
|
|
+ }else {
|
|
|
+ self.renderList(typeList)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ $('[data-tab-sort|=hero] [data-sort]').on('click', function() {
|
|
|
+ $(this).parent().find('span').removeClass('active')
|
|
|
+ $(this).addClass('active')
|
|
|
+ self.doubleFilter()
|
|
|
+ })
|
|
|
+ $('[data-tab-sort|=hero] [data-job]').on('click', function() {
|
|
|
+ $(this).parent().find('span').removeClass('active')
|
|
|
+ $(this).addClass('active')
|
|
|
+ self.doubleFilter()
|
|
|
+ })
|
|
|
+
|
|
|
+ //搜索
|
|
|
+ var search = function() {
|
|
|
+ var val = $('#search').val()
|
|
|
+ if(!val) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var reg = new RegExp(val)
|
|
|
+ var list = []
|
|
|
+ _.each(self.allData,function(i) {
|
|
|
+ if(reg.test(i.name) || reg.test(i.pinyin)) {
|
|
|
+ list.push(i)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ self.renderList(list)
|
|
|
+ }
|
|
|
+ $('#search').on('focus',function() {
|
|
|
+ $('.hero-bd-box').show()
|
|
|
+ $('.compound-wrap').hide()
|
|
|
+ }).on('input',_.debounce(search,500))
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ init () {
|
|
|
+ this.renderList(this.metaData.hero.data)
|
|
|
+ this.renderSort()
|
|
|
+ this.bindEvent()
|
|
|
+ }
|
|
|
+
|
|
|
+ renderList(list) {
|
|
|
+ $('.hero-wrap').html(itemTmpl({list:list}))
|
|
|
+ }
|
|
|
+
|
|
|
+ renderSort() {
|
|
|
+ var self = this,html = '<span class="active" data-job="">全部</span>'
|
|
|
+ $('[data-tab-sort]').each(function(i,e) {
|
|
|
+ var sort = $(e).attr('data-tab-sort')
|
|
|
+ var sortList = self.metaData[sort].sorts
|
|
|
+ for(var i = 0; i < sortList.length; i++) {
|
|
|
+ $(e).append('<span data-sort="'+sortList[i].code+'">'+sortList[i].sort+'</span>')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ _.each(self.metaData.hero.jobs,function(i) {
|
|
|
+ html += '<span data-job="'+i.code+'">'+i.job+'</span>'
|
|
|
+ })
|
|
|
+ $('[data-tab-job]').html(html)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //英雄双向分类过滤
|
|
|
+ doubleFilter() {
|
|
|
+ var sort = $('[data-tab-sort|=hero] [data-sort].active').attr('data-sort')
|
|
|
+ var job = $('[data-tab-sort|=hero] [data-job].active').attr('data-job')
|
|
|
+ var list = [],
|
|
|
+ sortReg = new RegExp(sort)
|
|
|
+ jobReg = new RegExp(job)
|
|
|
+ if(sort && job) {
|
|
|
+ _.each(this.metaData.hero.data,function(i) {
|
|
|
+ if(sortReg.test(i.sort) && jobReg.test(i.job)) {
|
|
|
+ list.push(i)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else if(sort && !job) {
|
|
|
+ _.each(this.metaData.hero.data,function(i) {
|
|
|
+ if(sortReg.test(i.sort)) {
|
|
|
+ list.push(i)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else if(!sort && job) {
|
|
|
+ _.each(this.metaData.hero.data,function(i) {
|
|
|
+ if(jobReg.test(i.job)) {
|
|
|
+ list.push(i)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else {
|
|
|
+ list = this.metaData.hero.data
|
|
|
+ }
|
|
|
+
|
|
|
+ this.renderList(list)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+$(function(){
|
|
|
+ new Hero()
|
|
|
+})
|