Warning.png

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

Изменения

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

MediaWiki:Common.js

580 байтов добавлено, 13:02, 14 августа 2016
Нет описания правки
/**
* Creates minecraft style tooltips * * 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/ */( function() {mcw.minetip var escapeChars = { // Add normal minetip events, removing legacy tooltip create'\\&': function() { var tooltip'&#38; $( '#mw-content-text, '<': '&#60;' ).on( { , 'mouseenter.minetip>': function( e ) {'&#62;' }; var $elem escape = $function( this text ),{ title = $elem // "\" must be escaped first return text.datareplace( /\\\\/g, 'minetip-title&#92;' ), description = $elem .datareplace( 'minetip-text' ); /\\&|[<>]/ No title or title only contains formatting codesg, function( char ) { return escapeChars[char]; } ); }; if var $tooltip = $( title =); var $win == undefined || title && title.replace$( /&([0window ), winWidth, winHeight, width, height; $( '#mw-9acontent-fl-o]text' )|\s+/g, '' ) === .on( { 'mouseenter.minetip' : function( e ) { // Use title attribute of the element or the first link directly under it $tooltip.remove(); var attrTitle $elem = $( this ), title = $elem.attr( 'data-minetip-title' ) || ; if ( title === undefined ) { title = $elem.find( '> a:first' ).attr( 'title' ); if ( title =!== undefined ) { title = attrTitle; } else { $.trim( title += attrTitle; } if .replace( title ) { /&/ Set the retrieved title as data for future useg, '\\&' ) ); $elem.dataattr( 'data-minetip-title', title ); } else { return; } } // No title or title only contains formatting codes $elem.add if ( title === undefined || title !== '*', $elem )&& title.filterreplace( /&( '[title0-9a-fl-or])/g, '' ).removeAttr( === 'title' ){ // Find deepest child title var childElem = $elem[0], childTitle; do { if ( childElem.hasAttribute( 'title === 0 ' ) ) { return childTitle = childElem.title; } childElem = childElem.firstChild; var text } while( childElem && childElem.nodeType == '<span class="title">' + title + '&f</span>'1 ); if ( description childTitle === undefined ) { text += '\n<span class="description">' + return; } description.replace( /\\\//g, Append child title as title may contain formatting codes if ( !title ) { title = ''&#47;' ) } title += $.trim( childTitle.replace( /\/&/g, '<br>\\&' ) + '&f</span>'); } if ( ! // Set the retrieved title as data for future use $elem.attr( '#data-minetip-tooltiptitle' , title ).length ) {; } if ( !$( 'body' )elem.appenddata( '<div id="minetip-tooltip"/>ready' );) { } // Remove title attributes so the native tooltip doesn't get in the way tooltip = $elem.find( '#minetip-tooltip[title]' ); // Add classes for minecraft formatting codes while .addBack( text).matchremoveAttr( /&[0-9a'title' ); $elem.data( 'minetip-el-o]/ ready', true ) ) {; } text if ( title == text.replace( /&([0-9a-el-o]= '' )(.*?)(&f|$)/g, { return; } var content = '<span class="formatminetip-$1title">$2' + escape( title ) + '&r</span>&f' ); } // Remove reset formatting text var description = text$.replacetrim( $elem.attr( /&f/g, 'data-minetip-text' ) ); tooltip.html if ( text description );{ // Trigger a mouse movement to position the tooltipApply normal escaping plus "/" $elem description = escape( description ).triggerreplace( /\\\//g, '&#47;'mousemove', e ); }, content += 'mousemove.<span class="minetip-description">': function+ description.replace( e/\//g, trigger ) { if ( !$( '#minetip-tooltip<br>' ).length ) { $( this ).trigger( + 'mouseenter&r</span>' ); return; } // Get event data from remote triggerAdd classes for minecraft formatting codes e = trigger || e; var top = e while ( content.clientY search( /&[0-9a-fl-o]/ ) > - 34,1 ) { left content = econtent.clientX + 14, width = tooltip.outerWidthreplace( true ), height = tooltip.outerHeight/&( true [0-9a-fl-o]), $win = $( window .*?), winWidth = (&r|$win.width()/g, winHeight '<span class= "format-$1">$win.height(2</span>&r' ); } // If going off the right of the screen, go to the left of the cursorRemove reset formatting if content = content.replace( left + width > winWidth /&r/g, '' ) { left -= width + 36; } // If now going off to the left of the screen, resort to going below the cursor if $tooltip = $( left '< 0 div id="minetip-tooltip">' ) {; left = 0 $tooltip.html( content ).appendTo( 'body' ); top += 82; // Go above the cursor if too lowCache current window and tooltip size if winWidth = $win.width( top + height > winHeight ) {; top - winHeight = 77 + $win.height(); } width = $tooltip.outerWidth( true ); // Don't go off the top of the screen } else if height = $tooltip.outerHeight( top < 0 true ) {; top = 0; // Don't go off Trigger a mouse movement to position the bottom of the screentooltip } else if $elem.trigger( top + height > winHeight 'mousemove', e ) { top = winHeight - height; }, // Apply the positions 'mousemove.minetip': function( e, trigger ) { if ( !$tooltip.css( length ) { top: top, $( this ).trigger( 'mouseenter' ); left: left return; } ); }, 'mouseleave.minetip': function() { // Get event data from remote trigger if ( !tooltip ) { return e = trigger || e; } // Get mouse position and add default offsets tooltip var top = e.remove()clientY - 34; } }, ' var left = e.minetipclientX + 14; // If going off the right of the screen, .grid .image, .grid .item, .grid2 .item' ).offgo to the left of the cursor if ( '.minetipNative' left + width > winWidth ){ left -= width + 36; }, // Remove all events destroy: function() { $If now going off to the left of the screen, resort to going above the cursor if ( '#mw-content-text' ).off( '.minetip .minetipNative' left < 0 ){ left = 0; $( '#minetip top -= height -tooltip' ).remove()22; }, // Add native browser tooltip events, removing normal minetipGo below the cursor if too high native: function if (top < 0 ) { $( top += height + 47; } // Don'#mw-content-text' ).ont go off the top of the screen } else if ( top < 0 ) { top = 0; // Don'mouseenter.minetipNative', '.minetip, .grid .image, .grid .item, .grid2 .item', function(t go off the bottom of the screen } else if ( top + height > winHeight ) { var title top = $( this ).data( 'minetipwinHeight -title' ),height; } // Apply the positions description = $( this )tooltip.datacss( 'minetip-text' { top: top, left: left } ); }, existingTitle = $ 'mouseleave.minetip': function( this ).attr{ if ( 'title' !$tooltip.length ) || { return; } $tooltip.remove( this ).find( '> a:first' ).attr; $tooltip = $( 'title' ); } if ( title || title === 0 || $( this ).attr( 'title' ) ) { // Remove titles within so they don't interfere $( this ).find( '[title]' ).removeAttr( 'title' ); } if ( title === 0 ) { $( this ).removeAttr( 'title' ); return; } else if ( !title && ( !existingTitle || !description ) ) { return; } else if ( !title && existingTitle ) { $( this ).data( 'minetip-title', existingTitle ); } var text = title || existingTitle; if ( description ) { text += '\n' + description; } // Remove formatting text = text.replace( /&([0-9a-fl-o])/g, '' ) .replace( /\\\//g }, '.minetip, '&#47;' ) .replace( /\//ggrid > .item, '\n' ) .replace( /&#47;/g, '/' ); $( this ).attr( 'title', text ); } ).off( '.minetipinvslot-item' ); }}; if ( mcw.useNativeMinetip ) { mcw.minetip.native();} else { mcw.minetip.create();} 
} );

Навигация