User:Jack who built the house/Gadget-referenceTooltips.js: Difference between revisions
Content deleted Content added
←Created page with '// See mw:Reference Tooltips ( function () { // enwiki settings var REF_LINK_SELECTOR = '.reference, a[href^="#CITEREF"]', COMMENTED_TEXT_CLASS = 'ts-comm...' |
No edit summary |
||
(33 intermediate revisions by the same user not shown) | |||
Line 1:
// See [[mw:Reference Tooltips]]
// Source https://en.wikipedia.org/wiki/MediaWiki:Gadget-ReferenceTooltips.js
( function () {
Line 5 ⟶ 6:
// enwiki settings
var REF_LINK_SELECTOR = '.reference, a[href^="#CITEREF"]',
COMMENTED_TEXT_CLASS = '
COMMENTED_TEXT_SELECTOR = ( COMMENTED_TEXT_CLASS ? '.' + COMMENTED_TEXT_CLASS + ', ' : '') +
'abbr[title]'; mw.messages.set( {
Line 20 ⟶ 22:
'rt-clicking': 'clicking',
'rt-delay': 'Delay before the tooltip appears (in milliseconds)',
'rt-tooltipsForComments': 'Show tooltips over <span title="Tooltip example" class="' + ( COMMENTED_TEXT_CLASS || 'rt-commentedText' ) + '" style="border-bottom: 1px dotted; cursor: help;">text with a dotted underline</span> in Reference Tooltips style (allows to see such tooltips on devices with no mouse support)',
'rt-disabledNote': 'You can re-enable Reference Tooltips using a link in the footer of the page.',
'rt-done': 'Done',
Line 61 ⟶ 63:
Number( enabled ) + '|' + delay + '|' + Number( activatedByClick ) + '|' +
Number( tooltipsForComments ),
{ path: '/', expires: 90 * SECONDS_IN_A_DAY, prefix: '' }
);
}
Line 104 ⟶ 106:
function TooltippedElement( $element ) {
var tooltip,
events,
te = this;
Line 109 ⟶ 112:
var showRefArgs;
if ( activatedByClick && te.type !== 'commentedText' && e.type !== 'contextmenu' ) {
e.preventDefault();
}
Line 148 ⟶ 151:
}
this.$element.addClass('rt-commentedText');
if ( activatedByClick ) {
events = {
// Adds an ability to see tooltips for links
if ( this.type === 'commentedText' &&
( this.$element.closest( 'a' ).length ||
this.$element.has( 'a' ).length
events[ 'contextmenu.rt' ] = onStartEvent;
}
} else {
events = {
'mouseleave.rt': onEndEvent
};
}
this.$element.on(
▲ { 'click.rt': onStartEvent } :
▲ { 'mouseenter.rt': onStartEvent, 'mouseleave.rt': onEndEvent }
▲ );
this.hideRef = function ( immediately ) {
Line 182 ⟶ 201:
if ( window.pg ) {
disableRt();
return;
}
if ( this.tooltip && !this.tooltip.$content.length ) {
return;
}
Line 422 ⟶ 445:
);
new TooltippedElement(
this.tooltipsForCommentsField.$element.find(
'.' + ( COMMENTED_TEXT_CLASS || 'rt-commentedText' ) )
);
Line 452 ⟶ 477:
$( '<tr>' ).append(
$( '<td>' ).append(
$( '<img>' ).attr( 'src', 'https://
),
$( '<td>' )
Line 551 ⟶ 576:
this.id = 'rt-' + this.te.$originalElement.attr( 'id' );
this.$content = this.te.$ref
.
.
var $this = $( this );
return this.nodeType === Node.TEXT_NODE ||
!( $this.is( '.mw-cite-backlink' ) ||
( i === 0 &&
// Template:Cnote, Template:Note
( $this.is( 'b' ) ||
// Template:Note_label
$this.is( 'a' ) &&
$this.attr( 'href' ).indexOf( '#ref' ) === 0
)
)
);
} )
.clone( true );
break;
Line 581 ⟶ 619:
}
// We need the $content interlayer here in order for the settings icon to have
// margins
this.$content = this.$content
Line 587 ⟶ 625:
.parent()
.addClass( 'rt-tooltipContent' )
.addClass( 'mw-parser-output' )
.appendTo( this.$element );
Line 642 ⟶ 681:
// Tooltip tail element is inside tooltip content element in order for the tooltip
// not to disappear when the mouse is above the tail
this.$tail = $( '<div>' )
.addClass( 'rt-tooltipTail' )
.prependTo( this.$element );
Line 682 ⟶ 721:
if ( tooltip.isPresent ) {
tooltip.$element.detach();
▲ }
if ( activatedByClick ) {
Line 701 ⟶ 738:
offsetYCorrection = 0;
▲ }
teElement = this.te.$element.get( 0 );
Line 768 ⟶ 803:
} );
if ( tooltipTailLeft ) {
▲ ( tooltipTailLeft + 12 ) + 'px; }'
▲ );
}
} else {
Line 785 ⟶ 817:
if ( tooltipTailLeft ) {
// 12 is the tail element width/height
▲ tooltipTailLeft + 'px; }'
▲ );
}
}
Line 829 ⟶ 858:
}
settingsString = mw.cookie.get( 'RTsettings', '' );
if ( settingsString ) {
settings = settingsString.split( '|' );
|