MediaWiki:Mobile.js:修订间差异
无编辑摘要 标签:移动版编辑 移动版网页编辑 |
无编辑摘要 标签:移动版编辑 移动版网页编辑 |
||
| (未显示同一用户的52个中间版本) | |||
| 第4行: | 第4行: | ||
Just replace span text and href to add links */ | Just replace span text and href to add links */ | ||
var navbar = function (data, textStatus, jqxhr) { | |||
var navlist = data.parse.text["*"]; | |||
const parser = new DOMParser(); | |||
const doc = parser.parseFromString(navlist, 'text/html'); | |||
var newul=doc.createElement("ul"); | |||
newul.id="p-toppage"; | |||
newul.classList.add("toggle-list__list"); | |||
var li=Array.from(doc.getElementsByTagName('li')); | |||
for(var i=0;i<li.length;i++) | |||
{ | |||
li[i].classList.add("toggle-list-item"); | |||
var prea=li[i].getElementsByTagName('a')[0]; | |||
var link=prea.getAttribute('href'); | |||
var newa=doc.createElement('a'); | |||
newa.href=link; | |||
newa.setAttribute("data-mw","interface"); | |||
newa.classList.add("toggle-list-item__anchor",`menu__item--link${i+1}`); | |||
var icon=li[i].getElementsByTagName('i')[0]; | |||
icon.style.width="20px"; | |||
icon.style.height="20px"; | |||
icon.style.color="var(--color-subtle,#54595d)"; | |||
icon.style.marginRight="8px"; | |||
icon.style.lineHeight="inherit"; | |||
icon.style.textAlign="center"; | |||
newa.appendChild(icon); | |||
var newspan=doc.createElement("span"); | |||
newspan.classList.add("toggle-list-item__label"); | |||
newspan.innerHTML=prea.innerHTML; | |||
newa.appendChild(newspan); | |||
li[i].insertBefore(newa,li[i].firstChild); | |||
prea.remove(); | |||
newul.appendChild(li[i]); | |||
} | |||
$('.menu ul#p-otherlink').after(newul); | |||
console.log(newul); | |||
}; | |||
var mfSidebar = function () { | |||
var purl = "/api.php?action=parse&text={{Template:置顶页面|sidebar}}&format=json"; | |||
$.ajax({ | |||
url: purl, | |||
success: navbar, | |||
error: function () { | |||
console.error("can\'t load customized navmenu") | |||
}, | |||
dataType: "json" | |||
}); | |||
}; | |||
mw.loader.using('mobile.site.styles'); | |||
if ($('.menu ul:first').length) { | if ($('.menu ul:first').length) { | ||
console.log("mobile menu exists"); | console.log("mobile menu exists"); | ||
| 第11行: | 第63行: | ||
<li class="toggle-list-item"> \ | <li class="toggle-list-item"> \ | ||
<a class="toggle-list-item__anchor menu__item--link1" href="https://discuss.jjjstudent.com" data-mw="interface"> \ | <a class="toggle-list-item__anchor menu__item--link1" href="https://discuss.jjjstudent.com" data-mw="interface"> \ | ||
<i class="fa fa- | <i class="fa fa-users" style="width: 20px; height: 20px; color: var(--color-subtle,#54595d); margin-right: 8px; line-height: inherit; text-align: center;"></i> \ | ||
<span class="toggle-list-item__label">论坛</span> \ | <span class="toggle-list-item__label">论坛</span> \ | ||
</a> \ | </a> \ | ||
| 第17行: | 第69行: | ||
<li class="toggle-list-item"> \ | <li class="toggle-list-item"> \ | ||
<a class="toggle-list-item__anchor menu__item--link2" href="https://old.jjjstudent.com" data-mw="interface"> \ | <a class="toggle-list-item__anchor menu__item--link2" href="https://old.jjjstudent.com" data-mw="interface"> \ | ||
<i class="fa fa-archive" style="width: 20px; height: 20px; color: var(--color-subtle,#54595d); margin-right: 8px; line-height: inherit; text-align: center;"></i> \ | |||
<span class="toggle-list-item__label"> | <span class="toggle-list-item__label">文档存档</span> \ | ||
</a> \ | </a> \ | ||
</li> \ | </li> \ | ||
</ul>' | </ul>' | ||
); | ); | ||
mfSidebar(); | |||
}; | }; | ||