MediaWiki:Mobile.js:修订间差异
imported>Hice 黑幕 |
wth 标签:移动版编辑 移动版网页编辑 |
||
| (未显示4个用户的45个中间版本) | |||
| 第1行: | 第1行: | ||
/* 这里的任何JavaScript将只在移动端加载 */ | |||
/* 这里的任何JavaScript将只在移动端加载 | (function($, mw) { //使用匿名函数以避免污染顶级变量 | ||
/* capture支持检测 */ | |||
var captureSupported = false; | |||
try { | |||
(function ( | var options = Object.defineProperty({}, "capture", { | ||
get: function () { | |||
captureSupported = true; | |||
return true; | |||
}, | |||
}); | |||
window.addEventListener("test", null, options); | |||
} catch (err) { /* */ } | |||
/* 函数定义体 */ | /* 函数定义体 */ | ||
//页顶提示模板相关 | |||
function commonBoxs() { | |||
if (window.mw && !!mw.config.get('wgNamespaceNumber')) return; | |||
var contentParent = $('#mw-content-text')[0] ? $('#mw-content-text') : $('#content'), | |||
commonBoxes = contentParent.find('.common-box'); | |||
if (!commonBoxes[0]) return; | |||
var commonBoxContainer = $('<div id="commonBoxContainer"><div id="commonBoxInfo"></div></div>').prependTo(contentParent), | |||
commonBoxList = $('<div id="commonBoxList"></div>').appendTo('#commonBoxInfo'); | |||
commonBoxes.each(function() { | |||
var commonBoxButton = $('<div class="commonBoxButton"></div>').appendTo(commonBoxList), | |||
commonBox = $(this); | |||
commonBoxButton.data('element', commonBox).css({ | |||
'border-color': commonBox.css('border-left-color'), | |||
'background-image': 'url(' + commonBox.find('tbody > tr > td:first-child img').prop('src') + ')', | |||
}).on('click', function() { | |||
if (commonBox.is(':visible')[0]) { | |||
commonBoxes.hide(); | |||
$(this).add($(this).siblings()).removeClass('current'); | |||
commonBoxList.removeClass('open'); | |||
} else { | |||
commonBoxes.filter(':visible').not(commonBox).hide(); | |||
commonBox.show(); | |||
$(this).toggleClass('current', commonBox.is(':visible')).siblings().removeClass('current'); | |||
commonBoxList.toggleClass('open', commonBox.is(':visible')); | |||
} | |||
}); | |||
}).appendTo(commonBoxContainer).hide(); | |||
} | |||
//uuid | |||
function uuidv4() { | |||
var result; | |||
do { | |||
result = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function(c) { | |||
return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16); | |||
}); | |||
} while (document.querySelector('a[data-linkid="' + result + '"]')); | |||
return result; | |||
} | |||
// Mobile Navmenu by GFwiki | |||
function menuadjust(){var a = $("body").height()+"px";document.getElementById("mw-mf-page-left").style.height = a;}; | |||
$(function(){menuadjust();}); | |||
$(window).resize(function(){menuadjust()}); | |||
var navbar = function(data, textStatus, jqxhr) { | |||
var navlist = data.parse.text["*"]; | |||
$(navlist).insertBefore(".menu > .hlist") | |||
}; | |||
var mfSidebar = function() { | |||
var purl = "/api.php?action=parse&page=MediaWiki:MFSidebar&format=json"; | |||
$.ajax({ | |||
url: purl, | |||
success: navbar, | |||
error: function () {console.error("can\'t load customized navmenu")}, | |||
dataType: "json" | |||
}); | |||
}; | |||
//需要时载入对应的 scripts | |||
if (mw.config.get("wgAction") === "edit" || mw.config.get("wgAction") === "submit" || mw.config.get("wgCanonicalSpecialPageName") === "Search") { mw.loader.load("/index.php?title=MediaWiki:Common.js/edit.js&action=raw&ctype=text/javascript"); } | |||
$(function(){mfSidebar();}); | |||
/* 函数执行体 */ | /* 函数执行体 */ | ||
$(function () { | $(function() { | ||
//页顶提示模板相关 | |||
commonBoxs(); | |||
//黑幕 | //黑幕 | ||
$('.heimu a').on("click", function () { | $('.heimu a').on("click", function() { | ||
if (!$(this).closest('.heimu').is(':active, :focus')) return false; | if (!$(this).closest('.heimu').is(':active, :focus')) return false; | ||
}); | }); | ||
//Template:hide | //Template:hide | ||
if ($('.mw-collapsible')[0]) mw.loader.using('jquery.makeCollapsible').then(function () { | if ($('.mw-collapsible')[0]) mw.loader.using('jquery.makeCollapsible').then(function() { | ||
//console.debug('jquery.makeCollapsible is loaded.'); | //console.debug('jquery.makeCollapsible is loaded.'); | ||
$('.mw-collapsible').makeCollapsible(); | $('.mw-collapsible').makeCollapsible(); | ||
}); | }); | ||
// 桌面版页面外链改为移动端域名 | |||
document.body.addEventListener("click", function(e) { | |||
e.path.forEach(function(ele) { | |||
if (ele instanceof HTMLAnchorElement) { | |||
var url = new mw.Uri(ele.href); | |||
if (/www\.hmoegirl\.info?$/.test(url.host) && url.query.mobileaction !== "toggle_view_desktop") { | |||
url.host = mw.config.get("wgServer").replace(/^(?:(?:https?:)?\/\/)?www/, "m"); | |||
ele.href = url; | |||
} | |||
} | |||
}); | |||
}, captureSupported ? { | |||
capture: true, | |||
} : true); | |||
}); | }); | ||
})(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量 | })(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量 | ||
//页顶加入选项控制 | |||
if( mw.config.get('wgNamespaceNumber') != 2){ | |||
spanobj=document.createElement("span"); | |||
srch=document.getElementById("page-actions"); | |||
srch.parentElement.insertBefore(spanobj,srch); | |||
spanobj.innerHTML='<a href="#/talk">讨论</a> · <a href="' + mw.config.get('wgScript') + '?' + $.param({ title: mw.config.get('wgPageName'), action: 'info' }) +'">信息</a> · <a href="' + mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/特殊:链入页面/' + mw.config.get("wgPageName") + '">相关</a>'; | |||
} | |||
// </pre> | // </pre> | ||