Warning.png

Поддержка Wiki прекращена, она доступна в режиме архива. Информация в ней устарела и может быть неактуальной.

Изменения

Перейти к: навигация, поиск

MediaWiki:Common.js

690 байтов добавлено, 11:08, 12 августа 2016
Нет описания правки
*
* Replaces normal tooltips. Supports minecraft [[formatting codes]] (except k), and a description with line breaks (/).
* Use mcw.useNativeMinetip = true to use normal tooltips, with the description added
*/
mcw.minetip = { // Add normal minetip events, removing legacy tooltip create: function() { var tooltip; $( '#mw-content-text' ).on( { 'mouseenter.minetip': function(e ) { var escapeChars $elem = $( this ), title = $elem.data( 'minetip-title' ), description = $elem.data( 'minetip-text' ); // No title or title only contains formatting codes if ( title === undefined || title && title.replace( /&([0-9a-fl-o])|\s+/g, '' ) = == '' ) { // Use title attribute of the element or the first link directly under it var attrTitle = $elem.attr( '\\&title' ) || $elem.find( '> a: first' ).attr( 'title'&#38); if ( title === undefined ) { title = attrTitle; } else { title += attrTitle; } if ( title ) { // Set the retrieved title as data for future use $elem.data( 'minetip-title', title ); } else { return; } } $elem.add( '*', $elem ).filter( '[title]'<).removeAttr( ': title'&#60); if ( title === 0 ) { return; } var text = ', '<span class="title">': + title + '&#62;f</span>' }; var escape = function if ( text description ) { // text += '\n<span class="\description" must be escaped first>' + return text description.replace( /\\\\//g, '&#9247;' ) .replace( /\\//g, '<br>' ) + '&|[f</span>]/g, function'; } if ( !$( char '#minetip-tooltip' ).length ) { return escapeChars[char]; } $( 'body' ).append( '<div id="minetip-tooltip"/>' ); }; var $ tooltip = $('#minetip-tooltip' ); var // Add classes for minecraft formatting codes while ( text.match( /&[0-9a-el-o]/ ) ) { text = text.replace( /&([0-9a-el-o])(.*?)(&f|$win )/g, '<span class= "format-$1">$2</span>&f' ); } // Remove reset formatting text = text.replace( window /&f/g, '' ); tooltip.html( text ), winWidth, winHeight, width, height; // Trigger a mouse movement to position the tooltip $elem.trigger( '#mw-content-textmousemove' , e ).on( {; }, 'mouseentermousemove.minetip': function( e , trigger ) { if ( !$( '#minetip-tooltip' ).remove(length );{ var $elem = $( this ), title = $elem.attrtrigger( 'data-minetip-titlemouseenter' ); if ( title return; } // Get event data from remote trigger e = trigger || e; var top =e.clientY - 34, left =e.clientX + 14, width = undefined tooltip.outerWidth( true ) {, title height = $elemtooltip.attrouterHeight( 'title' true );, if $win = $( title !== undefined window ) {, title winWidth = $win.trimwidth( title), winHeight = $win.replaceheight( ); /&/gIf going off the right of the screen, '\\&' go to the left of the cursor if ( left + width > winWidth ) );{ $elem.attr( 'dataleft -minetip-title', title )= width + 36;
}
} // No title or title only contains formatting codesIf now going off to the left of the screen, resort to going below the cursor if ( title === undefined || title !== '' && title.replace( /&([left < 0-9a-fl-or])/g, '' ) === '' ) { // Find deepest child title left = 0; var childElem top += $elem[0], childTitle82; do { // Go above the cursor if too low if ( childElem.hasAttribute( 'title' ) top + height > winHeight ) { childTitle top -= childElem.title77 + height;
}
childElem = childElem.firstChild; // Don't go off the top of the screen } whileelse if ( childElem && childElem.nodeType top < 0 ) { top === 1 )0; // Don't go off the bottom of the screen } else if ( childTitle === undefined top + height > winHeight ) { returntop = winHeight - height;
}
// Append child title as title may contain formatting codesApply the positions tooltip.css( { top: top, left: left } ); }, 'mouseleave.minetip': function() { if ( !title tooltip ) { title = ''return;
}
title += $.trim( childTitle.replace( /&/g, '\\&' ) );
// Set the retrieved title as data for future use $elemtooltip.attrremove( 'data-minetip-title', title );
}
}, '.minetip, .grid .image, .grid .item, .grid2 .item' ).off( '.minetipNative' );
},
// Remove all events
destroy: function() {
$( '#mw-content-text' ).off( '.minetip .minetipNative' );
$( '#minetip-tooltip' ).remove();
},
// Add native browser tooltip events, removing normal minetip
native: function() {
$( '#mw-content-text' ).on( 'mouseenter.minetipNative', '.minetip, .grid .image, .grid .item, .grid2 .item', function() {
var title = $( this ).data( 'minetip-title' ),
description = $( this ).data( 'minetip-text' ),
existingTitle = $( this ).attr( 'title' ) || $( this ).find( '> a:first' ).attr( 'title' );
if ( !title || title === 0 || $elem( this ).dataattr( 'minetip-readytitle' ) ) { // Remove title attributes titles within so the native tooltip doesnthey don't get in the wayinterfere $elem( this ).find( '[title]' ).addBack().removeAttr( 'title' ); $elem.data( 'minetip-ready', true );
}
if ( title === 0 ) { $( this ).removeAttr( 'title' ) {;
return;
} else if ( !title && ( !existingTitle || !description ) ) {
return;
} else if ( !title && existingTitle ) {
$( this ).data( 'minetip-title', existingTitle );
}
var content text = '<span class="minetip-title">' + escape( title ) + '&r</span>'; var description = $.trim( $elem.attr( 'data-minetip-text' ) )|| existingTitle;
if ( description ) {
// Apply normal escaping plus "/" description = escape( description ).replace( /\\\//g, '&#47;' ); content text += '<span class="minetip-description">\n' + description.replace( /\//g, '<br>' ) + '&r</span>'; } // Add classes for minecraft formatting codes while ( content.search( /&[0-9a-fl-o]/ ) > -1 ) { content = content.replace( /&([0-9a-fl-o])(.*?)(&r|$)/g, '<span class="format-$1">$2</span>&r' );
}
// Remove reset formatting
content = content.replace( /&r/g, '' );
$tooltip = $( '<div id="minetip-tooltip">' );
$tooltip.html( content ).appendTo( 'body' );
// Cache current window and tooltip size
winWidth = $win.width();
winHeight = $win.height();
width = $tooltip.outerWidth( true );
height = $tooltip.outerHeight( true );
// Trigger a mouse movement to position the tooltipRemove formatting $elemtext = text.triggerreplace( /&( 'mousemove', e [0-9a-fl-o]); }/g, 'mousemove.minetip': function( e, trigger ) { if ( !$tooltip.length ) { $( this ).triggerreplace( 'mouseenter' ); return; } /\\\/ Get event data from remote trigger e = trigger || e; // Get mouse position and add default offsets var top = e.clientY - 34g, '&#47; var left = e.clientX + 14; // If going off the right of the screen, go to the left of the cursor if ( left + width > winWidth ' ) { left -= width + 36; } // If now going off to the left of the screen, resort to going above the cursor if .replace( left < 0 ) { left = 0; top -= height - 22; // Go below the cursor if too high if ( top < 0 ) { top += height + 47; } \// Dong, 't go off the top of the screen } else if ( top < 0 ) { top = 0; // Don\n't go off the bottom of the screen } else if ( top + height > winHeight ) { top = winHeight - height; } // Apply the positions $tooltip.cssreplace( { top: top, left: left } )/&#47; }/g, 'mouseleave.minetip/': function() { if ( !$tooltip.length ) { return; }
$tooltip( this ).removeattr('title', text ); $tooltip = $ } ).off('.minetip' ); }}; if ( mcw.useNativeMinetip ) { }, 'mcw.minetip, .grid > .item, .invslot-item' native();}else { mcw.minetip.create() );}

Навигация