Warning.png

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

Изменения

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

MediaWiki:Common.js

689 байтов добавлено, 12:45, 14 августа 2016
Нет описания правки
/* Keep track of delegated events on dynamic content */
mcw.events = {};
 
/* Добавляет дополнительные кнопки в классическую панель редактирования */
if ( mw.user.options.get( 'showtoolbar' ) && !mw.user.options.get( 'usebetatoolbar' ) ) {
mw.loader.load( '/index.php?title=MediaWiki:Toolbar.js&action=raw&ctype=text/javascript' );
}
 
/* Добавляет кнопки вставки часто используемых описаний правки */
if (wgAction == 'edit' || wgAction == 'submit') {
mw.loader.load( '/index.php?title=MediaWiki:AddSumButton.js&action=raw&ctype=text/javascript' );
}
/* Fired whenever wiki content is added. (#mw-content-text, live preview, load page, etc.) */
*
* 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() { var escapeChars mcw.minetip = { '\\&': '&#38;', '<': '&#60;', '>': '&#62;' }; var escape = function( text ) { // "\" must be escaped first return text.replace( /\\\\/gAdd normal minetip events, '&#92;' )removing legacy tooltip .replace( /\\&|[<>]/g, create: 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.attrdata( 'minetip-title' ), description = $elem.data-( 'minetip-titletext' ); // 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' ); 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 ).trimfilter( '[title]' ).removeAttr( 'title' ); if ( title === 0 ) { return; } var text = '<span class="title">' + title+ '&f</span>'; if ( description ) { text += '\n<span class="description">' + description.replace( /\\\//g, '&#47;' ).replace( /\//g, '\\<br>' ) + '&f</span>'; } if ( !$( '#minetip-tooltip' ) .length );{ $elem( 'body' ).attrappend( 'data<div id="minetip-tooltip"/>' ); } tooltip = $( '#minetip-titletooltip'); // Add classes for minecraft formatting codes while ( text.match( /&[0-9a-el-o]/ ) ) { text = text.replace( /&([0-9a-el-o])(.*?)(&f|$)/g, title '<span class="format-$1">$2</span>&f' );
}
} // No title or title only contains Remove reset formatting codes if ( title text === undefined || title !== '' && titletext.replace( /&([0-9a-fl-or])f/g, '' ) === '' ; tooltip.html( text ) {; // Find deepest child titleTrigger a mouse movement to position the tooltip var childElem = $elem[0].trigger( 'mousemove', childTitlee ); do }, 'mousemove.minetip': function( e, trigger ) { if ( childElem.hasAttribute!$( 'title#minetip-tooltip' ) .length ) { childTitle = childElem.title; } childElem = childElem$( this ).firstChild; } whiletrigger( childElem && childElem.nodeType === 1 'mouseenter' ); if ( childTitle === undefined ) {
return;
}
// Append child title as title may contain formatting codesGet 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 ( !title left + width > winWidth ) { title left -= ''width + 36;
}
title += $.trim( childTitle.replace( /&/g, '\\&' ) );
// Set If now going off to the retrieved title as data for future useleft 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 $elem} else if ( top < 0 ) { top = 0; // Don't go off the bottom of the screen } else if ( top + height > winHeight ) { top = winHeight - height; } // Apply the positions tooltip.attrcss( { top: top, left: left } ); }, 'data-mouseleave.minetip-title', title : function() { if ( !tooltip ) { return; } tooltip.remove();
}
}, '.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 Remove formatting codes while ( contenttext = text.searchreplace( /&([0-9a-fl-o])/ g, '' ) > -1 ) { content = content.replace( /\\\//g, '&([0-9a-fl-o]#47;' )( .*?)replace(&r|$)/\//g, '<span class="format-$1">$2</span>&r\n' ); } // Remove reset formatting content = content .replace( /&r#47;/g, '/' );
$tooltip = $( '<div id="minetip-tooltip">' ); $tooltip.html( content this ).appendToattr( '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( 'mousemovetitle', e text ); }, 'mousemove.minetip': function( e, trigger ) { if ( !$tooltip.length ) { $off( this )'.trigger( 'mouseenterminetip' ); return; } // Get event data from remote trigger e = trigger || e; // 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 ( left + width > winWidth ) { 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 mcw.useNativeMinetip ) { top += height + 47; } // 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 = winHeight - height; } // Apply the positions $tooltip.css( { top: top, left: left } ); }, 'mouseleave mcw.minetip': function() { if ( !$tooltip.length ) { return; } $tooltip.remove(); $tooltip = $native(); }else { }, 'mcw.minetip, .grid > .item, .invslot-item' create();}() );
} );
/* End DOM ready */
 
/* Добавляет кнопки вставки часто используемых описаний правки */
if (wgAction == 'edit' || wgAction == 'submit') {
mw.loader.load( '/index.php?title=MediaWiki:AddSumButton.js&action=raw&ctype=text/javascript' );
}
 
/* Добавляет дополнительные кнопки в классическую панель редактирования */
if ( mw.user.options.get( 'showtoolbar' ) && !mw.user.options.get( 'usebetatoolbar' ) ) {
mw.loader.load( '/index.php?title=MediaWiki:Toolbar.js&action=raw&ctype=text/javascript' );
}
 
}() );

Навигация