MediaWiki:Common.js — различия между версиями
Ivgon (обсуждение | вклад) |
Ivgon (обсуждение | вклад) |
||
| Строка 1: | Строка 1: | ||
function injectWikificatorLink() { | function injectWikificatorLink() { | ||
| − | |||
if ( $( '#wikif-custom-btn-final' ).length ) return; | if ( $( '#wikif-custom-btn-final' ).length ) return; | ||
var $target = $( '.editButtons' ); | var $target = $( '.editButtons' ); | ||
if ( $target.length ) { | if ( $target.length ) { | ||
| − | |||
var $button = $( '<button>' ) | var $button = $( '<button>' ) | ||
.attr( { | .attr( { | ||
'id': 'wikif-custom-btn-final', | 'id': 'wikif-custom-btn-final', | ||
| − | 'type': 'button', | + | 'type': 'button', |
'style': 'font-weight: bold; color: #252525; background: #f8f9fa; border: 1px solid #a2a9b1; padding: 3px 8px; margin-right: 8px; border-radius: 2px; cursor: pointer; display: inline-block; margin-top: 5px; vertical-align: middle;' | 'style': 'font-weight: bold; color: #252525; background: #f8f9fa; border: 1px solid #a2a9b1; padding: 3px 8px; margin-right: 8px; border-radius: 2px; cursor: pointer; display: inline-block; margin-top: 5px; vertical-align: middle;' | ||
} ) | } ) | ||
.text( 'Викификатор' ); | .text( 'Викификатор' ); | ||
| − | |||
$button.on( 'click', function ( e ) { | $button.on( 'click', function ( e ) { | ||
| − | e.preventDefault(); | + | e.preventDefault(); |
| − | e.stopPropagation(); | + | e.stopPropagation(); |
if ( typeof Wikify === 'function' ) { | if ( typeof Wikify === 'function' ) { | ||
Wikify(); | Wikify(); | ||
} else { | } else { | ||
| − | // | + | // Формируем железобетонный абсолютный URL |
| − | + | var scriptUrl = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript'; | |
| + | |||
| + | $.getScript( scriptUrl ) | ||
.done( function () { | .done( function () { | ||
if ( typeof Wikify === 'function' ) { | if ( typeof Wikify === 'function' ) { | ||
| Строка 32: | Строка 31: | ||
} ) | } ) | ||
.fail( function() { | .fail( function() { | ||
| − | alert( 'Не удалось загрузить файл | + | alert( 'Не удалось загрузить файл по адресу:\n' + scriptUrl ); |
} ); | } ); | ||
} | } | ||
} ); | } ); | ||
| − | |||
$target.append( $button ); | $target.append( $button ); | ||
} | } | ||
Версия 13:10, 1 ноября 2026
function injectWikificatorLink() {
if ( $( '#wikif-custom-btn-final' ).length ) return;
var $target = $( '.editButtons' );
if ( $target.length ) {
var $button = $( '<button>' )
.attr( {
'id': 'wikif-custom-btn-final',
'type': 'button',
'style': 'font-weight: bold; color: #252525; background: #f8f9fa; border: 1px solid #a2a9b1; padding: 3px 8px; margin-right: 8px; border-radius: 2px; cursor: pointer; display: inline-block; margin-top: 5px; vertical-align: middle;'
} )
.text( 'Викификатор' );
$button.on( 'click', function ( e ) {
e.preventDefault();
e.stopPropagation();
if ( typeof Wikify === 'function' ) {
Wikify();
} else {
// Формируем железобетонный абсолютный URL
var scriptUrl = mw.config.get( 'wgServer' ) + mw.config.get( 'wgScript' ) + '?title=MediaWiki:Wikificator.js&action=raw&ctype=text/javascript';
$.getScript( scriptUrl )
.done( function () {
if ( typeof Wikify === 'function' ) {
Wikify();
} else {
alert( 'Функция Wikify не найдена внутри MediaWiki:Wikificator.js' );
}
} )
.fail( function() {
alert( 'Не удалось загрузить файл по адресу:\n' + scriptUrl );
} );
}
} );
$target.append( $button );
}
}
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
$( document ).ready( injectWikificatorLink );
}