LLWiki正在建设中,欢迎加入我们!
“User:Bhsd/widget/songposition.js”的版本间差异
跳转到导航
跳转到搜索
(创建页面,内容为“//<nowiki> // 用于Widget:Songposition,可以使用ES6语法 "use strict"; document.querySelectorAll( '.member-symbol' ).forEach(ele => { ele.dataset.titl…”) |
|||
第2行: | 第2行: | ||
// 用于[[Widget:Songposition]],可以使用ES6语法 |
// 用于[[Widget:Songposition]],可以使用ES6语法 |
||
"use strict"; |
"use strict"; |
||
/*global mw, $, OO*/ |
|||
document.querySelectorAll( '.member-symbol' ).forEach(ele => { |
|||
(() => { |
|||
ele.dataset.title = ele.title; |
|||
let popup, label; |
|||
ele.removeAttribute('title'); |
|||
function prepare() { |
|||
⚫ | |||
label = $('<span>'); |
|||
mw.loader.using( 'oojs-ui-core' ).then(() => { |
|||
popup = new OO.ui.PopupWidget({$content: label, classes: ['member-popup'], padded: true, width: null}); |
|||
popup.$element.appendTo( 'body' ); |
|||
}); |
|||
} |
|||
function main($content) { |
|||
$content.find( '.member-symbol' ).each(function() { this.dataset.title = this.title; }).removeAttr( 'title' ) |
|||
.attr('tabIndex', -1).on('mouseenter focus', function() { |
|||
const self = $(this); |
|||
label.text( self.data('title') ); |
|||
popup.setFloatableContainer( self ).toggle(true); |
|||
}).on('mouseleave blur', () => { popup.toggle(false); }); |
|||
} |
|||
console.log( 'setInterval: 等待jQuery加载完毕' ); |
|||
const timerStart = Date.now(), |
|||
jqueryTimer = setInterval(() => { |
|||
if (!window.jQuery) { return; } |
|||
clearInterval(jqueryTimer); |
|||
console.log(`End setInterval: jQuery加载完毕,用时 ${Date.now() - timerStart} ms`); |
|||
prepare(); |
|||
mw.hook( 'wikipage.content' ).add($content => { main($content); }); |
|||
}, 500); |
|||
⚫ | |||
//</nowiki> |
//</nowiki> |
||
// [[category: |
// [[category:jQuery小部件]] {{DEFAULTSORT:Songposition}} |
2020年12月12日 (六) 05:18的版本
//<nowiki> // 用于[[Widget:Songposition]],可以使用ES6语法 "use strict"; /*global mw, $, OO*/ (() => { let popup, label; function prepare() { label = $('<span>'); mw.loader.using( 'oojs-ui-core' ).then(() => { popup = new OO.ui.PopupWidget({$content: label, classes: ['member-popup'], padded: true, width: null}); popup.$element.appendTo( 'body' ); }); } function main($content) { $content.find( '.member-symbol' ).each(function() { this.dataset.title = this.title; }).removeAttr( 'title' ) .attr('tabIndex', -1).on('mouseenter focus', function() { const self = $(this); label.text( self.data('title') ); popup.setFloatableContainer( self ).toggle(true); }).on('mouseleave blur', () => { popup.toggle(false); }); } console.log( 'setInterval: 等待jQuery加载完毕' ); const timerStart = Date.now(), jqueryTimer = setInterval(() => { if (!window.jQuery) { return; } clearInterval(jqueryTimer); console.log(`End setInterval: jQuery加载完毕,用时 ${Date.now() - timerStart} ms`); prepare(); mw.hook( 'wikipage.content' ).add($content => { main($content); }); }, 500); }) (); //</nowiki> // [[category:jQuery小部件]] {{DEFAULTSORT:Songposition}}