123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- //为字符串类型添加去除左右空格的方法
- String.prototype.trim = function(){
- return this.replace(/(^\s*)|(\s*$)/g, "");
- };
- /**
- * 通过关键字搜索英雄 keyworld(String)可以针对英雄的中文名title,英文名name,称号displayName
- * champions(Json)全部英雄json格式的列表 返回匹配英雄的name(Array)
- */
- function searchChampionByKeyworld(keyworld, champions) {
- var key;
- var result = new Array();
- for (key in champions) {
- var name = champions[key]['name'];
- var nameLower = name.toLowerCase();
- var displayName = champions[key]['displayName'];
- var title = champions[key]['title'];
- // 按中文名,称号,英文名的优先级顺序查找
- if (title.indexOf(keyworld) != -1) {
- result.push(name);
- continue;
- }
- if (displayName.indexOf(keyworld) != -1) {
- result.push(name);
- continue;
- }
- // 不区分大小写,从开始位置进行匹配
- keyworld = keyworld.toLowerCase();
- if (nameLower.indexOf(keyworld) == 0) {
- result.push(name);
- continue;
- }
- }
- return result;
- }
- /*
- * var result = searchChampionByKeyworld('颂唱', champions);
- *
- * for(var key in result){ document.write(result[key]+'<br/>'); }
- */
- /**
- * 通过分类标签搜索英雄 tags(Array)分类标签 champions(Json)全部英雄json格式的列表 返回匹配英雄的name(Array)
- */
- function searchChampionByTags(tagsSearch, champions) {
- var key;
- var result = new Array();
- for (key in champions) {
- var tags = champions[key]['tags'];
- if (!tags) continue;
- var tagsArr = tags.split(',');
- var $result = isContain(tagsArr, tagsSearch);
- if ($result) {
- result.push(champions[key]['name']);
- }
- }
- return result;
- }
- /**
- * 通过分类标签搜索物品 tags(Array)物品分类标签 item(Json) 全部物品json格式的列表 返回匹配的物品的id(Array)
- */
- function searchItemByTags(tagsSearch, items) {
- var key;
- var result = new Array();
- for (key in items) {
- var tags = items[key]['tags'];
- if (tags == false)
- continue;
- var tagsArr = tags.split(',');
- var $result = isContain(tagsArr, tagsSearch);
- if ($result) {
- result.push(items[key]['id']); // 可能会修改
- }
- }
- return result;
- }
- /**
- * 判断数组arrOne是否包含数组arrTwo 如果是返回true,否则返回false 如果arrOne或arrTwo为空则返回false;
- */
- function isContain(arrOne, arrTwo) {
- if (arrOne.length == 0 || arrTwo.length == 0)
- return false;
- if (arrOne.length < arrTwo.length)
- return false;
- var keyOne, keyTwo;
- var result = true; //
- for (keyTwo in arrTwo) {
- var tag = arrTwo[keyTwo];// 要查找的目标标签
- var flag = false; // 默认找不到
- for (keyOne in arrOne) {
- if (tag == arrOne[keyOne]) {
- flag = true;
- break;
- }
- }
- if (!flag) {// 没有找到
- result = false;
- break;
- }
- }
- return result;
- }
- function getItemList(items) {
- // var category =
- // ['movement','mana_regen','health_regen','health','critical_strike','spell_damage','mana','armor','spell_block',
- // 'damage','attack_speed','life_steal','consumable','cooldown_reduction'];
- var disable_items = {'1080':1,'3206':1,'3207':1,'3208':1,'3209':1,'3204':1,'3205':1,'3154':1,'3160':1,'2037':1,'2039':1,'3131':1,'3123':1,'3005':1,'3122':1,'3104':1,'3159':1,'3090':1,'3188':1,'3084':1,'2040':1,'2048':1,'3107':1, '3007':1,'3073':1,'3029':1, '3008':1, '3350':1, '3351':1, '3352':1,'2010':1 ,'1075':1};
- var result = {};
- for ( var i in items) {
- if(typeof(disable_items[i])!=='undefined') continue;
- var tags = items[i]['tags'];
- if (tags == false)
- continue;
- var tagsArr = tags.split(',');
- for ( var j in tagsArr) {
- //alert(typeof(result[tagsArr[j]]));
- if (typeof(result[tagsArr[j]])==='undefined') {
- result[tagsArr[j]] = new Array();
- }
- result[tagsArr[j]].push(i);
- }
- }
- return result;
- }
- function showItems(item_list,items){
- var temp = "";
- var item_id;
- for(var key in item_list){
- item_id = item_list[key];
- temp += "<li item_id="+item_id+" id='item_"+item_id+
- "'><a href='#'><img alt='' title='"+items[item_id]['name']+" "+items[item_id]['description']+
- "' src='http://img.lolbox.duowan.com/zb/"+
- item_id+"_40x40.png' /></a></li>";
- }
- document.write(temp);
- }
- // 绑定搜索事件
- $(function() {
- // ----------------------------------------------------------
- // 分类搜索英雄
- var checkboxs = $('#champion_tags_search :checkbox');
- checkboxs.click(function() {
- var tags = new Array();
- checkboxs.each(function() {
- var tag = $(this);
- if (tag.attr("checked") == "checked") {
- tags.push(tag.attr('value'));
- }
- });
- if (tags.length == 0) { // 没有勾选,显示全部
- $("#champion_show li").css({
- display : 'block'
- });
- } else {// 有勾选,进行选择
- var res = searchChampionByTags(tags, heroesList);
- // 先对所有隐藏
- $("#champion_show li").css({
- display : 'none'
- });
- // 然后只显示匹配的
- for ( var key in res) {
- var target = "#cham_" + res[key];
- $(target).css({
- display : 'block'
- });
- }
- }
- });
- // ---------------------------------------------------------
- // 关键字搜索英雄
- var keyworldTxt = $("input#keyworld");
- keyworldTxt.keyup(function() {
- checkboxs.each(function() {
- $(this).removeAttr("checked");
- });
- var keyworld = keyworldTxt.attr('value').trim();
- if (keyworld.length == 0) { // 没有输入关键字
- $("#champion_show li").css({
- display : 'block'
- });
- } else {
- var res = searchChampionByKeyworld(keyworld, heroesList);
- $("#champion_show li").css({
- display : 'none'
- });
- for ( var key in res) {
- var target = "#cham_" + res[key];
- $(target).css({
- display : 'block'
- });
- }
- }
- });
- /*
- // ---------------------------------------------------------
- // 分类搜索物品
- var item_checkboxs = $('#item_tags_search :checkbox');
- item_checkboxs.click(function() {
- var tags = new Array();
- item_checkboxs.each(function() {
- var tag = $(this);
- if (tag.attr("checked") == "checked") {
- tags.push(tag.attr('value'));
- }
- });
- if (tags.length == 0) { // 没有勾选,显示全部
- $("#item_show li").css({
- display : 'block'
- });
- } else {// 有勾选,进行选择
- var res = searchItemByTags(tags, ZBItems);
- var temp = "";
- var key;
- for (key in res) {
- temp += res[key] + " ";
- }
- // alert(temp);
- // 先对所有隐藏
- $("#item_show li").css({
- display : 'none'
- });
- // 然后只显示匹配的
- for ( var key in res) {
- var target = "#item_" + res[key];
- $(target).css({
- display : 'block'
- });
- }
- }
- });
- */
- });
|