全站通知:
MediaWiki:Common.js
刷
历
编
跳到导航
跳到搜索
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
/* :英雄图鉴 */
if($(".page-英雄图鉴").length==1){
$("<input>").attr({"id":"searchBox","type":"text"}).css("height","20px")
.appendTo($("<li>").attr("class","bili-list-style").appendTo($(".resp-tabs-list")))
.on('input',function () {
$(".resp-tab-content>div").stop().hide()
.filter(":contains('"+$(this).val()+"'),[title*='"+$(this).val()+"']").show();
});
}
/* :英雄图鉴 结束 */
/* :装备图鉴 */
if($(".page-英雄联盟装备图鉴").length==1){
$("<input>").attr({"id":"searchBox","type":"text"}).css("height","20px")
.appendTo($("<li>").attr("class","bili-list-style").appendTo($(".resp-tabs-list")))
.on('input',function () {
$(".resp-tab-content>div").stop().hide()
.filter(":contains('"+$(this).val()+"'),[title*='"+$(this).val()+"']").show();
});
}
/* :英雄联盟手游英雄图鉴 */
if($(".page-英雄联盟手游英雄图鉴").length==1){
$("<input>").attr({"id":"searchBox","type":"text"}).css("height","20px")
.appendTo($("<li>").attr("class","bili-list-style").appendTo($(".resp-tabs-list")))
.on('input',function () {
$(".resp-tab-content>div").stop().hide()
.filter(":contains('"+$(this).val()+"'),[title*='"+$(this).val()+"']").show();
});
}
if($(".page-英雄联盟手游装备图鉴").length==1){
$("<input>").attr({"id":"searchBox","type":"text"}).css("height","20px")
.appendTo($("<li>").attr("class","bili-list-style").appendTo($(".resp-tabs-list")))
.on('input',function () {
$(".resp-tab-content>div").stop().hide()
.filter(":contains('"+$(this).val()+"'),[title*='"+$(this).val()+"']").show();
});
}
/* :手游英雄图鉴 结束 */
/* 模板:背景 */
if($("#pagebg")[0]){
$("body").css("background","url("+$("#pagebg").data("bg")+") 50% 0px / cover no-repeat fixed");
$(".wiki-header").append($("<div>").css({
"display": "block",
"content": "",
"top": "0",
"left": "0",
"bottom": "0",
"right": "0",
"position": "absolute",
"z-index": "-1",
"background": "url("+$("#pagebg").data("header")+") 50% 0px / cover no-repeat",
"opacity": "0.6"
})).css("background","#fff");
}
/* 模板:背景 结束 */
/* 模板:技能标签 */
$('.skill-tabs:not(.made-skill-tabs)').each(function() {
var tabs = $(this).addClass('made-skill-tabs');
var dts = $(this).find('> dt');
if(dts.length === 2) tabs.addClass('toggle-tabs');
dts.each(function(i) {
var dt = $(this);
if(i > 0) {
dt.addClass('hidden-tab').find('+ dd').addClass('hidden-tab');
dt.prepend($('<span class="prev-tab" title="点击浏览更多信息。">«</span>').mousedown(function(e) {
e.preventDefault();
}).click(function() {
dts.addClass('hidden-tab').find('+ dd').addClass('hidden-tab');
$(dts[i-1]).removeClass('hidden-tab').find('+ dd').removeClass('hidden-tab');
}));
}
if(i < dts.length-1) {
dt.append($('<span class="next-tab" title="点击浏览更多信息。">»</span>').mousedown(function(e) {
e.preventDefault();
}).click(function() {
dts.addClass('hidden-tab').find('+ dd').addClass('hidden-tab');
$(dts[i+1]).removeClass('hidden-tab').find('+ dd').removeClass('hidden-tab');
}));
}
});
});
/* 模板:技能标签 结束 */
/* 模板:文本提示 */
$(".itemhover").mousemove(function(e) {
$(this).children(".iteminfo").css({
"left":(e.clientX+20-$(this).children(".iteminfo").width()/2+$(this).children(".iteminfo").width()>$("body")[0].clientWidth?$("body")[0].clientWidth-$(this).children(".iteminfo").width()-20:e.clientX-$(this).children(".iteminfo").width()/2) + "px",
"top":(e.clientY+10+20+$(this).children(".iteminfo").height()>$("body")[0].clientHeight?e.clientY+10-$(this).children(".iteminfo").height()-20:e.clientY+10) + "px"
});
});
$(".itemhover").find("[title]").removeAttr("title");
$(function () {
var x = 10;
var y = 20;
$(":not(.itemhover) [title]").mouseover(function (e) {
this.myTitle = this.title;
this.title = "";
var tooltip = "<div id='tooltip' class='iteminfo'>" + this.myTitle + "<\/div>";
$("body").append(tooltip);
$("#tooltip").show();
}).mouseout(function () {
this.title = this.myTitle;
$("#tooltip").remove();
}).mousemove(function (e) {
$("#tooltip").css({
"top": (e.clientY+y+20+$("#tooltip").height()>$("body")[0].clientHeight?e.pageY + y-$("#tooltip").height()-20:e.pageY + y) + "px",
"left": (e.pageX+x+20+$("#tooltip").width()>$("body")[0].clientWidth?$("body")[0].clientWidth-$("#tooltip").width()-20:e.pageX + x) + "px"
});
});
});
/* 模板:文本提示 结束 */
/* 缺少图片时的提示图 */
$(".new[title^=文件]").html('<img src="//wiki.biligame.com/lol/Special:Redirect/file/%E6%B2%A1%E5%9B%BE%E7%89%87.png" width="90px">');
/* 缺少图片时的提示图 结束 */
/* 筛选表格 */
$(function() {
//解决手机上按键选项hover效果不消失的问题
//筛选页面列表筛选
$('.filter li').on('mouseenter touchstart',function(e) {
$(this).children().addClass('hover');
});
$('.filter li').on('mouseleave touchend',function(e) {
$(this).children().removeClass('hover');
});
$('.filter li').on('click',function(e) {
$(this).siblings().children().removeClass('active');
$(this).children().toggleClass('active');
var item = new Array();
$('.filter').find('.active').parent().each(function() {
var data_type = $(this).parent().attr('data-type');
item.push("[data-param" + data_type + "='" + $(this).attr("data-value") + "']");
});
if(item.length != 0) {
$('#wiki_table tbody').children().hide(400);
$('#wiki_table tbody').children(item.toString().replace(/,/g, '')).show(300);
//$('#wiki_table tbody').children().not(item.toString().replace(/,/g, '')).hide(1000);
} else {
$('#wiki_table tbody').children().show(300);
}
});
});
$(function InitCardSelect() {
var self = {};
var selectOptions; //所有筛选按钮
var filters = {}; //当前筛选规则
var filterKeys = []; //所有筛选Key
var showAll = true; //不筛选,显示全部
var tableRows; //所有要被筛选的行
var computedRows; //筛选后的行
var $sorter; //当前进行排序的表头
var sortDesent = false; //反向排序
function isNil(s) {
return s === '' || s === undefined || s === null || s === false
}
//点击筛选按钮时
function OnSelectOptionClick(e) {
var $x = e.data;
e.preventDefault();
var label = '['+$.trim($x.text())+'] 筛选';
console.time(label);
//显示全部
if ($x.FilterKey == 0) {
for (i in selectOptions) {
selectOptions[i].Select = false;
selectOptions[i].removeClass('selected');
}
filters = {};
showAll = true;
//更新表格
self.FilterRows();
console.timeEnd(label);
return;
}
showAll = false;
var select = !$x.Select;
$x.Select = select;
//变更筛选状态
var key = $x.FilterKey;
filters[key] = filters[key] || {};
var opt = $x.FilterOpt == "AND" ? "AND" : "OR";
filters[key][opt] = filters[key][opt] || [];
if (select) {
filters[key][opt].push($x.FilterValue);
} else {
filters[key][opt] = filters[key][opt].filter(function(x) {
return x !== $x.FilterValue;
});
if (filters[key][opt].length < 1) delete filters[key][opt];
}
select ? $x.addClass('selected') : $x.removeClass('selected');
self.FilterRows();
console.timeEnd(label);
}
function OnHeaderSortClick(e) {
var $x = e.data;
e.preventDefault();
var label = '['+$.trim($x.text())+'] 排序';
console.time(label);
if ($sorter !== $x) {
//第一次:新的排序
$sorter = $x;
sortDesent = false;
} else if (!sortDesent) {
//第二次:切换排序
sortDesent = true;
} else {
//第三次:不进行排序
$sorter = null;
}
self.SortRows();
console.timeEnd(label);
}
//初始化
self.Init = function () {
selectOptions = $('.cardSelectOption').toArray().map(function(x) {
var $x = $(x);
var dataOption = $.trim($x.data('option'));
var dataGroup = $.trim($x.data('group'));
if (isNil(dataOption) || isNil(dataGroup)) return $x;
var splt = dataOption.split('|');
$x.FilterKey = dataGroup;
$x.FilterValue = $.trim(splt[1]);
$x.FilterOpt = $.trim($x.data('opt') || 'OR').toUpperCase();
if (filterKeys.indexOf(dataGroup) < 0)
filterKeys.push(dataGroup);
$x.click($x, OnSelectOptionClick);
return $x;
});
//$head = $('#CardSelectTabHeader');
tableRows = $('#CardSelectTr>tbody>tr').toArray().map( function(x) {
var $x = $(x);
//if (x == $head[0]) continue;
for (i in filterKeys) {
var key = filterKeys[i];
var val = $x.data('param'+key);
if (val === undefined) continue;
if (typeof val == 'number'){
val = val.toString(10);
}
var splt = val.split(',');
for (j in splt) {
var s = $.trim(splt[j]);
if (!isNil(s)) {
$x.FilterData = $x.FilterData || {};
$x.FilterData[key] = $x.FilterData[key] || [];
$x.FilterData[key].push(s);
}
}
}
return $x;
});
//computedRows = tableRows.concat([]);
$('#CardSelectTr>thead>tr>th').each(function(index, x) {
var $x = $(x);
$x.off('click').off('mousedown');
if ($x.hasClass('headerSort')) {
$x.Index = index;
//$x.SortKey = $x.data('group');
$x.click($x, OnHeaderSortClick);
}
});
}
//t1中包含t2中所有项
function includeAll(t1, t2) {
for (i in t2) {
if (t1.indexOf(t2[i]) < 0) return false;
}
return true;
}
//t1中包含t2中的任一项
function includeAny(t1, t2) {
if (t2.length == 0) return true;
for (i in t2) {
if (t1.indexOf(t2[i]) > -1) return true;
}
return false;
}
//使用show/hide来显示表格行
self.FilterRows = function() {
if (showAll) {
filters = {};
}
$('#CardSelectTr>tbody').hide();
for (var idx in tableRows) {
var $x = tableRows[idx];
var data = $x.FilterData;
var hide = false;
for (key in filters) {
hide = !data || !data[key];
if (!hide && filters[key]['AND']) {
hide = !includeAll(data[key],filters[key]['AND']);
}
if (!hide && filters[key]['OR']) {
hide = !includeAny(data[key],filters[key]['OR']);
}
if (hide) break;
}
if (!hide != !$x.Hide) {
$x.Hide = hide;
hide ? $x.hide() : $x.show();
}
}
$('#CardSelectTr .headerSort').removeClass('headerSortDown headerSortUp');
$('#CardSelectTr>tbody').show();
$sorter = null;
}
function grabSortData($tr, index) {
$tr.SortData = $tr.SortData || [];
if ($tr.SortData[index] !== undefined) return $tr.SortData[index];
var td = $tr.children('td')[index];
if (!td) {
$tr.SortData[index] = -1;
return -1;
}
var text = $.trim(td.textContent);
$tr.SortData[index] = text;
return text;
}
//对行排序,不显示的行会被移除
self.SortRows = function() {
//var residues = [];
if (!$sorter) {
computedRows = tableRows.filter(function($x) { return !$x.Hide; });
$('#CardSelectTr .headerSort').removeClass('headerSortDown headerSortUp');
}
else if (!sortDesent) {
var index = $sorter.Index;
computedRows = tableRows.filter(function($x) { return !$x.Hide; });
computedRows.sort(function compareFunction($x, $y) {
var x = grabSortData($x, index);
var y = grabSortData($y, index);
var nx = + x;
var ny = + y;
return (isNaN(nx) || isNaN(ny))
? isNaN(nx) && isNaN(ny)
? x < y ? -1 : 1
: isNaN(nx) ? 1 : -1 //字符串排后
: nx === ny
? 0
: nx < ny ? -1 : 1; //数值小的排前
//console.log (`${x} ~ ${y} => ${ret}`);
//return ret;
});
$('#CardSelectTr .headerSort').removeClass('headerSortDown headerSortUp');
$sorter.addClass('headerSortDown');
}
else {
computedRows.reverse();
$('#CardSelectTr .headerSort').removeClass('headerSortDown headerSortUp');
$sorter.addClass('headerSortUp');
}
$('#CardSelectTr>tbody').hide()
.prepend(computedRows)
.show();
}
$('.cardSelectOption').off('click').off('mousedown');
if ($('#CardSelectTabHeader').parent().is('tbody')){
$('#CardSelectTr').prepend( $('<thead/>').append($('#CardSelectTabHeader')));
}
self.Init();
console.log('CardSelectTr.js Initialized.');
return self;
});
/* 筛选表格 结束*/

沪公网安备 31011002002714 号