MediaWiki:Common.js:修订间差异
无编辑摘要 |
无编辑摘要 |
||
| 第18行: | 第18行: | ||
e.stopPropagation(); | e.stopPropagation(); | ||
var temp = this, link = this.getAttribute('data-link') || ''; | var temp = this, link = this.getAttribute('data-link') || ''; | ||
if(link. | if(link.includes('http:') || link.includes('https:')){ | ||
window.open(link, '_blank'); | window.open(link, '_blank'); | ||
}else{ | }else{ | ||
2024年6月6日 (四) 13:37的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 加载bootstrap
mw.loader.load("https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap-grid.min.css", "text/css");
//mw.loader.load("https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js", "text/javascript");
var initCount = 0
function initEvent(){
// 确保一定生效
setTimeout(function(){
var tempBtns = $('.template-btn-container');
if(tempBtns.length === 0){
if(initCount++ >= 20) return;
return initEvent()
}
// 模板 - 按钮的click事件初始化
tempBtns.click(function(e){
e.stopPropagation();
var temp = this, link = this.getAttribute('data-link') || '';
if(link.includes('http:') || link.includes('https:')){
window.open(link, '_blank');
}else{
window.open('/' + link, '_blank');
}
})
// 模板-按钮-图标svg处理
tempBtns.each( function(index, btnDom){
var imgDom = $(btnDom).find('img')[0]
if(imgDom && imgDom.src.indexOf('.svg/')>0){
var svgSrc = imgDom.src.replace(/svg\/.+\.png/g, 'svg').replace('thumb/','')
fetch(svgSrc).then(function(res){return res.text()}).then(function(svgHtml){
$(imgDom.parentNode.parentNode).replaceWith(svgHtml)
})
}
})
console.log('init event~')
}, 100)
}
initEvent()
console.log('js init~')