MediaWiki:Mobile.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* 这里的任何JavaScript将为使用移动版网站的用户加载 */
console.log("Mobile.js loaded");
/* 以下代码用于模板折叠文字 -- Hineven */
random_string = function(str_length) {
var str = "",
arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
for (var i = 0; i < str_length; i++) {
pos = Math.round(Math.random()*(arr.length - 1));
str += arr[pos];
}
return str;
}
collapse_click = function(id) { // 大力爆改css
var ptitle = document.getElementById(id);
if(id.match("disp") == null) {
ptitle.attributes.getNamedItem("style").value = "display:none";
document.getElementById(id+"-disp").attributes.getNamedItem("style").value = "display:visible";
document.getElementById(id.replace("-title", "-content")).attributes.getNamedItem("style").value = "display:visible";
} else {
ptitle.attributes.getNamedItem("style").value = "display:none";
document.getElementById(id.replace("-disp", "").replace("-title", "-content")).attributes.getNamedItem("style").value = "display:none";
document.getElementById(id.replace("-disp", "")).attributes.getNamedItem("style").value = "display:visible";
}
}
collapse_preprocess = function() {
var col_arr = document.getElementsByClassName("collapse-box");
for(var i = 0; i<col_arr.length; i++) {
var hashcode = random_string(16);
// console.log(col_arr[i].childNodes);
for(var j = 0; j<col_arr[i].childNodes.length; j++) {
if(col_arr[i].childNodes[j].className == "collapse-box-title") {
var ap_id = document.createAttribute("id");
ap_id.value = "col-title-"+hashcode;
col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
ap_id = document.createAttribute("onclick");
ap_id.value = "collapse_click(this.id)";
col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
} else if(col_arr[i].childNodes[j].className == "collapse-display-title") {
var ap_id = document.createAttribute("id");
ap_id.value = "col-title-"+hashcode+"-disp";
col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
ap_id = document.createAttribute("onclick");
ap_id.value = "collapse_click(this.id)";
col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
} else if(col_arr[i].childNodes[j].className == "collapse-box-content") {
var ap_id = document.createAttribute("id");
ap_id.value = "col-content-"+hashcode;
col_arr[i].childNodes[j].attributes.setNamedItem(ap_id);
}
}
}
}
collapse_preprocess();