|
@@ -0,0 +1,131 @@
|
|
|
+
|
|
|
+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 list = []
|
|
|
+ for(var i = 0; i < typeList.length; i++) {
|
|
|
+ if(typeList[i].sort == sort) {
|
|
|
+ list.push(typeList[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.renderList(list)
|
|
|
+ }else {
|
|
|
+ self.renderList(typeList)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ $('[data-tab-sort|=hero] span').on('click', function() {
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ //搜索
|
|
|
+ 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 = ''
|
|
|
+ $('[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) {
|
|
|
+ console.log(i)
|
|
|
+ })
|
|
|
+ console.log(self.metaData.hero.jobs)
|
|
|
+ $('[data-tab-job]').html()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+$(function(){
|
|
|
+ new Hero()
|
|
|
+})
|