跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
分类索引
最近更改
随便看看
灵兰秘典
捐助本站
帮助
帮助
联系我们
关于本站
MediaWiki帮助
USER-SIDEBAR
GROUP-SIDEBAR
CATEGORY-SIDEBAR
中医百科
搜索
搜索
外观
登录
个人工具
登录
查看“︁MediaWiki:Gadget-UnihanTooltips.js”︁的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
特殊页面
页面信息
外观
移至侧栏
隐藏
←
MediaWiki:Gadget-UnihanTooltips.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
/* 本小工具可以將[[Template:僻字]]的提示由原來的title提示改為元素式彈出提示,使觸控式裝置可以觀看有關提示 */ (function() { // 使用MediaWiki的Cookie方法 const dontLoad = mw.util.getParamValue("UTdontload"); if (dontLoad && !isNaN(dontLoad)) { mw.cookie.set("UTdontload", "1", { path: "/", expires: parseInt(dontLoad) }); } if (mw.cookie.get("UTdontload") === "1") return; (function() { // 使用MediaWiki提供的content容器 const bodyContent = mw.util.$content || document.body; const canonicalNamespace = mw.config.get('wgCanonicalNamespace'); // 只在这些命名空间运行 if (!['', 'Project', 'Help'].includes(canonicalNamespace)) return; // 更可靠的触摸检测 const isTouchscreen = window.matchMedia('(hover: none), (pointer: coarse)').matches || mw.config.get('wgDisplayResolution') === 'mobile' || 'ontouchstart' in document.documentElement; const timerLength = isTouchscreen ? 0 : 200; $(".inline-unihan").each(function() { let tooltipNode = null; let hideTimer = null; let showTimer = null; function hide(refLink) { if (tooltipNode && tooltipNode.parentNode === bodyContent) { hideTimer = setTimeout(() => { $(tooltipNode).animate({ opacity: 0 }, 100, function() { if (tooltipNode && tooltipNode.parentNode) { tooltipNode.parentNode.removeChild(tooltipNode); } }); }, isTouchscreen ? 16 : 100); } } function show() { if (!tooltipNode.parentNode || tooltipNode.parentNode.nodeType === 11) { bodyContent.appendChild(tooltipNode); } $(tooltipNode).stop().animate({ opacity: 1 }, 100); clearTimeout(hideTimer); } // 保存原始title并清空 const originalTitle = this.title; this.title = ""; // 使用jQuery的on方法代替hover $(this).on(isTouchscreen ? 'click' : 'mouseenter mouseleave', function(e) { const element = this; if (isTouchscreen && e.type === 'click') { e.preventDefault(); if (!tooltipNode || tooltipNode.parentNode !== bodyContent) { requestAnimationFrame(() => { const closeHandler = (e) => { const target = e.target || e.srcElement; let currentElement = target; while (currentElement && !currentElement.classList.contains("unihantooltip")) { currentElement = currentElement.parentNode; } if (!currentElement) { clearTimeout(showTimer); hide(element); $(bodyContent).off("click touchstart", closeHandler); } }; $(bodyContent).on("click touchstart", closeHandler); }); } } if (e.type === 'mouseleave') { clearTimeout(showTimer); hide(this); return; } showTimer && clearTimeout(showTimer); showTimer = setTimeout(() => { const tooltipContent = $("<ul class='reflist'></ul>"); const lines = originalTitle.split("\n"); lines.forEach(line => { if (line.trim()) { tooltipContent.append($("<li></li>").text(line)).append("<br>"); } }); if (!tooltipNode) { tooltipNode = document.createElement("div"); tooltipNode.className = "unihantooltip"; $(tooltipNode).append(tooltipContent); if (!isTouchscreen) { $(tooltipNode).on("mouseenter", show) .on("mouseleave", () => hide(element)); } } else { $(tooltipNode).empty().append(tooltipContent); } show(); const position = $(element).position(); const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight }; let top = position.top - tooltipNode.offsetHeight; let left = position.left - 7; // 边界检测 if (top < 0) { $(tooltipNode).addClass("UHflipped"); top = position.top + $(element).outerHeight(); } else { $(tooltipNode).removeClass("UHflipped"); } if (left + tooltipNode.offsetWidth > viewport.width) { left = viewport.width - tooltipNode.offsetWidth - 10; } $(tooltipNode).css({ top: Math.max(0, top), left: Math.max(0, left), opacity: 0 // 初始设置为透明以准备动画 }).stop().animate({ opacity: 1 }, 100); }, timerLength); }); }); })(); })();
返回
MediaWiki:Gadget-UnihanTooltips.js
。