MediaWiki:Common.js:修订间差异
无编辑摘要 |
无编辑摘要 |
||
| 第13行: | 第13行: | ||
} | } | ||
/* | /* 以下代码用于模板折叠文字 -- Hineven */ | ||
add_load_event = function(func) { | |||
var oldonload = window.onload; | |||
if(typeof window.onload != 'function') { | |||
window.onload = func; | |||
} else { | |||
window.onload = function() { | |||
oldonload(); | |||
func(); | |||
} | |||
} | |||
} | |||
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); | |||
} 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); | |||
} 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); | |||
} | |||
} | |||
} | |||
} | |||
add_load_event(collapse_preprocess); | |||