MediaWiki talk:Gadget-ReferenceTooltips.js
添加话题外观
AnYiLin在话题“編輯請求 2021-09-07”中的最新留言:4年前
尝试解决在"现代“皮肤无法使用”参考文献提示工具“的问题
[编辑]{{editprotected}}
// See [[mw:Reference Tooltips]]
if (wgAction == 'view' && ! mw.user.options.get('gadget-Navigation_popups')) { // 启用导航Popup则禁用本js
window.pg || $(document).ready( function($) {
// Make sure we are in article, project, or help namespace
if ( wgCanonicalNamespace === '' || wgCanonicalNamespace === 'Project' || wgCanonicalNamespace === 'Help' ) {
function toggleRT(o){
mw.loader.using("jquery.cookie",function(){
$.cookie("RTsettings",o+"|"+ settings[1] + "|" + settings[2], {path:"/",expires:90});
location.reload();
})
}
var settings = document.cookie.split("RTsettings=")[1];
settings = settings ? settings.split(";")[0].split("%7C") : [1, 200, +("ontouchstart" in document.documentElement)];
if( settings[0] == 0 ) {
var footer = $("#footer-places, #f-list");
if( footer.length === 0 ) {
footer = $("#footer li").parent();
}
footer.append($("<li>").append($("<a>").text("启用参考文献提示工具").attr("href","javascript:(function(){})()").click(function(){toggleRT(1)})));
return;
}
var isTouchscreen = +settings[2],
timerLength = isTouchscreen ? 0 : +settings[1],
settingsMenu;
$(".reference").each( function() {
var tooltipNode, hideTimer, showTimer;
function findRef( h ){
h = h.firstChild.getAttribute("href"); h = h && h.split("#"); h = h && h[1];
h = h && document.getElementById( h );
h = h && h.nodeName == "LI" && h;
return h;
}
function hide( refLink ){
if( tooltipNode && ( document.getElementById('bodyContent') !==null&& tooltipNode.parentNode == document.getElementById('bodyContent') ) ) {
hideTimer = setTimeout( function() {
$(tooltipNode).animate({opacity: 0}, 100, function(){ document.getElementById('bodyContent').removeChild( tooltipNode ) })
}, isTouchscreen ? 16 : 100)
} else if(tooltipNode && tooltipNode.parentNode == document.body){
hideTimer = setTimeout( function() {
$(tooltipNode).animate({opacity: 0}, 100, function(){ document.body.removeChild( tooltipNode ) })
}, isTouchscreen ? 16 : 100)
}
else {
var h = findRef( refLink );
h && (h.style.border = "");
}
}
function show(){
if( !tooltipNode.parentNode || tooltipNode.parentNode.nodeType === 11 ){
if(document.getElementById('bodyContent') !==null){
document.getElementById('bodyContent').appendChild( tooltipNode );
}else{
document.body.appendChild( tooltipNode );
checkFlip = true ;
}
}
$(tooltipNode).stop().animate({opacity: 1}, 100)
clearTimeout( hideTimer );
}
function openSettingsMenu(){
if( settingsMenu ) {
settingsMenu.dialog( "open" );
} else {
settingsMenu = $("<form>").append(
$("<button>").css("width","100%").text("关闭参考文献提示工具").button().click(function(){toggleRT(0)}),
"<br>",
$("<small>").text("一旦关闭,参考文献提示工具还可以从页面底部的一个链接重新启用。"),
"<hr>",
$("<label>").text("出现提示的延迟时间(毫秒): ").append($("<input>").attr({"type":"number","value":settings[1],step:50,min:0,max:5000})),
"<br>",
$("<span>").text("弹出提示的方式:"),
$("<label>").append(
$("<input>").attr({"type":"radio", "name":"RTActivate", "checked":settings[2]==0&&"checked", "disabled":"ontouchstart" in document.documentElement&&"disabled"}),
"悬停"
),
$("<label>").append(
$("<input>").attr({"type":"radio", "name":"RTActivate", "checked":settings[2]==1&&"checked"}),
"点击"
)
).submit(function(e){e.preventDefault()}).dialog({modal:true,width:500,title:"参考文献提示工具选项",buttons:{"保存设置":function(){
var a = this.getElementsByTagName("input"),
b = +a[0].value;
$.cookie("RTsettings","1|"+ (b > -1 && b < 5001 ? b : settings[1]) + (a[1].checked ? "|0" : "|1"), {path:"/",expires:90});
location.reload();
}}});
}
}
$(this)[ isTouchscreen ? 'click' : 'hover' ](function( e ){
var _this = this;
if( isTouchscreen ) {
e.preventDefault();
if(document.getElementById('bodyContent') !==null){
(tooltipNode && tooltipNode.parentNode == document.getElementById('bodyContent')) || setTimeout( function(){
$( document.getElementById('bodyContent') ).bind("click touchstart", function( e ) {
e = e || event;
e = e.target || e.srcElement;
for( ; e && e.className!="referencetooltip"; )
e = e.parentNode;
if( !e ){
clearTimeout( showTimer );
hide( _this );
$(document.getElementById('bodyContent')).unbind("click touchstart", arguments.callee)
}
})
}, 0);}else {
(tooltipNode && tooltipNode.parentNode == document.body) || setTimeout( function(){
$( document.body ).on("click touchstart", function( e ) {
e = e || event;
e = e.target || e.srcElement;
for( ; e && !$( e ).hasClass( "referencetooltip" ) ; )
e = e.parentNode;
if( !e ){
clearTimeout( showTimer );
hide( _this );
$(document.body).off("click touchstart", arguments.callee)
}
})
}, 0);
}
}
showTimer && clearTimeout( showTimer );
showTimer = setTimeout( function() {
var h = findRef( _this );
if( !h ){return};
if( !isTouchscreen && ( window.pageYOffset || document.documentElement.scrollTop || document.getElementById('bodyContent').scrollTop || 0 ) + $(window).height() > $( h ).offset().top + h.offsetHeight ) {
h.style.border = "#3366bb 2px solid";
return;
}else if(!isTouchscreen && ( window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0 ) + $(window).height() > $( h ).offset().top + h.offsetHeight){
h.style.border = "#3366bb 2px solid";
return;
}
if(!tooltipNode){
tooltipNode = document.createElement("ul");
tooltipNode.className = "referencetooltip references-small";
var c = tooltipNode.appendChild( h.cloneNode( true ) );
try {
if( c.firstChild.nodeName != "A" ) {
while( c.childNodes[1].nodeName == "A" && c.childNodes[1].getAttribute( "href" ).indexOf("#cite_ref-") !== -1 ) {
do { c.removeChild( c.childNodes[1] ) } while ( c.childNodes[1].nodeValue == " " );
}
}
} catch (e) { mw.log(e) }
c.removeChild( c.firstChild );
$( tooltipNode.firstChild.insertBefore( document.createElement( "span" ), tooltipNode.firstChild.firstChild ) ).addClass("RTsettings").attr("title", "设置").click(function(){
mw.loader.using(["jquery.cookie","jquery.ui.dialog"], openSettingsMenu);
})
tooltipNode.appendChild( document.createElement( "li" ) );
isTouchscreen || $(tooltipNode).hover(show, hide);
}
show();
var o = $(_this).position(), oH = tooltipNode.offsetHeight;
$(tooltipNode).css({top: o.top - oH, left: o.left - 7 });
if( tooltipNode.offsetHeight > oH ) { // is it squished against the right side of the page?
$(tooltipNode).css({left:'auto',right:0});
tooltipNode.lastChild.style.marginLeft = (o.left - tooltipNode.offsetLeft) + "px";
}
if( o.top < tooltipNode.offsetHeight ) { // is it above the top of the page?
$(tooltipNode).addClass("RTflipped").css({top: o.top + 12});
} else if( tooltipNode.className === "referencetooltip RTflipped" ) { // cancel previous
$(tooltipNode).removeClass("RTflipped");
}
}, timerLength);
}, isTouchscreen ? undefined : function(){clearTimeout(showTimer); hide(this); } )
} );
}
} );
}
有没有其他什么方法可以调试的?--李Lee凡其Fanchy 2013年1月3日 (四) 16:04 (UTC)
问题描述详见Wikipedia:互助客栈/技术#中文维基百科的“现代”皮肤无法使用"参考文献提示工具"的问题--李Lee凡其Fanchy 2013年1月3日 (四) 16:07 (UTC)
代码比较--李Lee凡其Fanchy 2013年1月3日 (四) 16:14 (UTC)
看了以下各个皮肤,好像有5个用到了bodyContent,4个没有用。对上面的代码又做了更改--李Lee凡其Fanchy 2013年1月3日 (四) 16:35 (UTC)
- 完成,丢到顶上去了。--Jimmy Xu 查 · 论 · 编 2013年1月4日 (五) 10:31 (UTC)
注釋中的綠鏈
[编辑]點擊注釋{{noteTag}}中的綠鏈會跑到正在建立頁面,而不是該外語維基的對應頁面。為何不能直接點擊進入?否則就要透過下方注釋欄{{noteFoot}}的綠鏈,多一個步驟,感覺流程不順暢。--Tp0910(留言) 2017年5月6日 (六) 16:26 (UTC)
- 這不是{{noteTag}}的問題,是參考文獻提示與綠鏈兩個小工具在設計的時候沒有互相配合。@Jimmy Xu、Liangent:有沒有辦法解決?(出現在Special:permalink/44266215的註2)--街燈電箱150號 開箱維修 抄錶 檢驗證明 2017年5月7日 (日) 04:09 (UTC)
引入新版
[编辑]
请求已拒绝
目前参考文献提示框已有新版,介绍见mw:Reference_Tooltips。
附: MediaWiki:Gadget-ReferenceTooltips.js | MediaWiki:Gadget-ReferenceTooltips.css——小老虎3018☂ 2019年4月8日 (一) 16:42 (UTC)
- 有進行本地化跟測試過了嗎?--Xiplus#Talk 2019年4月13日 (六) 06:55 (UTC)
未完成,待本地化。--Xiplus#Talk 2019年5月3日 (五) 11:52 (UTC)
編輯請求 2021-09-07
[编辑]
请求已处理。--安忆Talk 2021年9月8日 (三) 13:56 (UTC)
优化几个翻译。请作如下修改:
'rt-delay': '工具提示显示延迟(毫秒)',
'rt-tooltipsForComments': '为<span title="提示工具范例" class="' + (COMMENTED_TEXT_CLASS || 'rt-commentedText') + '" style="border-bottom: 1px dotted; cursor: help;">虚下划线</span>文本显示参考文献提示样式的工具提示(可以在不支持鼠标的设备上显示工具提示)',
'rt-disabledNote': '您可以通过页脚中的链接重新启用参考文献提示工具',
'rt-done': '完成',
请一并修改第40行和第41行的繁体中文翻译。--Tranve (✉) 2021年9月7日 (二) 14:02 (UTC)
- 我感觉现在的“可以在不支持鼠标的设备上显示提示工具”更明确些…--安忆Talk 2021年9月7日 (二) 14:11 (UTC)
- 可以,请查看上方(Tooltip 应该译为“工具提示”而非“提示工具”)。--Tranve (✉) 2021年9月7日 (二) 15:07 (UTC)