Warning.png

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

Изменения

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

MediaWiki:Common.js

690 байтов убрано, 09:05, 6 августа 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 ( function() { var escapeChars = {'\\&': '&#38;', '<': '&#60;', '>': '&#62;' }; var escape = function( text ) { // "\" must be escaped first return text.replace( /\\\\/ Add normal minetip eventsg, removing legacy tooltip'&#92;' ) create: .replace( /\\&|[<>]/g, function(char ) {return escapeChars[char]; } ); }; var $tooltip= $(); var $win = $( window ), winWidth, winHeight, width, height; $( '#mw-content-text' ).on( { 'mouseenter.minetip': function( e ) { $tooltip.remove(); var $elem = $( this ), title = $elem.dataattr( 'data-minetip-title' ); if ( title === undefined ) { title = $elem.attr( 'title' ); if ( title !== undefined ) { title = $.trim( title.replace( /&/g,'\\&' ) ); description = $elem.dataattr( 'data-minetip-texttitle' , title ); } } // No title or title only contains formatting codes if ( title === undefined || title !== '' && title.replace( /&([0-9a-fl-oor])|\s+/g, '' ) === '' ) { // Use Find deepest child title attribute of the element or the first link directly under it var attrTitle childElem = $elem.attr( 'title' ) || $elem.find( '> a:first' ).attr( 'title' )[0], childTitle; if ( title === undefined ) do { title = attrTitle; } else { title += attrTitle; } if ( title ) { // Set the retrieved title as data for future use $elemchildElem.datahasAttribute( 'minetip-title', title ); } else ) { returnchildTitle = childElem.title;
}
childElem = childElem.firstChild; } $elem.addwhile( '*', $elem )childElem && childElem.filter( '[title]' ).removeAttr( 'title' nodeType === 1 ); if ( title childTitle === 0 undefined ) {
return;
}
var text = '<span class="// Append child title">' + as title + '&f</span>'; if ( description ) { text += '\n<span class="description">' + description.replace( /\\\//g, '&#47;' ).replace( /\//g, '<br>' ) + '&f</span>'; } if ( !$( '#minetip-tooltip' ).length ) { $( 'body' ).append( '<div id="minetip-tooltip"/>' ); } tooltip = $( '#minetip-tooltip' ); // Add classes for minecraft may contain formatting codes while ( text.match( /&[0-9a-el-o]/ ) ) { text = text.replace( /&([0-9a-el-o])(.*?)(&f|$)/g, '<span class="format-$1">$2</span>&f' ); } // Remove reset formatting text = text.replace( /&f/g, '' ); tooltip.html( text ); // Trigger a mouse movement to position the tooltip $elem.trigger( 'mousemove', e ); }, 'mousemove.minetip': function( e, trigger ) { if ( !$( '#minetip-tooltip' ).length title ) { $( this ).trigger( 'mouseenter' ); return; } // Get event data from remote trigger e = trigger || e; var top = e.clientY - 34, left = e.clientX + 14, width = tooltip.outerWidth( true ), height = tooltip.outerHeight( true ), $win = $( window ), winWidth = $win.width(), winHeight = $win.height(); // 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 below the cursor if ( left < 0 ) { left = 0; top += 82; // Go above the cursor if too low if ( top + height > winHeight ) { top -= 77 + height; } // Don't go off the top of the screen } else if ( top < 0 ) { top = 0; // Don't go off the bottom of the screen } else if ( top + height > winHeight ) { top title = winHeight - height; } // Apply the positions tooltip.css( { top: top, left: left } ); }, 'mouseleave.minetip': function() { if ( !tooltip ) { return;
}
title += $.trim( childTitle.replace( /&/g, '\\&' ) );
tooltip// Set the retrieved title as data for future use $elem.removeattr('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 || !$( this )elem.attrdata( 'titleminetip-ready' ) ) { // Remove titles within title attributes so they donthe native tooltip doesn't interfereget in the way $( this )elem.find( '[title]' ).addBack().removeAttr( 'title' ); $elem.data( 'minetip-ready', true );
}
if ( title === 0 ) { $( this ).removeAttr( 'title' );{
return;
} else var content = '<span class="minetip-title">' + escape( title ) + '&r</span>'; var description = $.trim( $elem.attr( 'data-minetip-text' ) ); if ( !title description ) { // Apply normal escaping plus "/" description = escape( description ).replace( /\\\//g, '&#47;' ); content += '<span class="minetip-description">' + description.replace( /\//g, '<br>' ) + '&r</span>'; } // Add classes for minecraft formatting codes while ( content.search( /&[0-9a-fl-o]/ ) > -1 ) { content = content.replace( /& ( !existingTitle |[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 tooltip $elem.trigger( 'mousemove', e ); }, 'mousemove.minetip': function( e, trigger ) { if ( !description $tooltip.length ) { $( this ) .trigger( 'mouseenter' ) {;
return;
} else if ( !title && existingTitle ) {
$( this ).data( 'minetip-title', existingTitle );
}
var text // Get event data from remote trigger e = title trigger || existingTitlee; // Get mouse position and add default offsets var top = e.clientY - 34; var left = e.clientX + 14; // If going off the right of the screen, go to the left of the cursor if ( description left + width > winWidth ) { text left -= width +36; } // If now going off to the left of the screen, resort to going above the cursor if ( left < 0 ) { left = 0; top -= height - 22; // Go below the cursor if too high if ( top < 0 ) { top += height + 47; } // Don'\nt go off the top of the screen } else if ( top < 0 ) { top = 0; // Don' t go off the bottom of the screen } else if ( top + descriptionheight > winHeight ) { top = winHeight - height;
}
// Remove formattingApply the positions text = text$tooltip.replacecss( /&([0-9a-fl-o])/g{ top: top, '' left: left } ); .replace( /\\\//g }, '&#47;mouseleave.minetip' : function(){ if ( !$tooltip.replace( /\//g, '\n' length ){ .replace( /&#47;/g, '/' )return; }
$( this )tooltip.attrremove( 'title', text ); } ).off $tooltip = $( '.minetip' ); } }; if ( mcw, '.minetip, .useNativeMinetip ) { mcwgrid > .minetipitem, .native(invslot-item' );} else { mcw.minetip.create() );}

Навигация