MediaWiki:Common.js: различия между версиями



Материал из Энциклопедия нашего транспорта
Перейти к навигации Перейти к поиску
 
(не показано 10 промежуточных версий этого же участника)
Строка 1: Строка 1:
/* MediaWiki:Common.js */
/* MediaWiki:Common.js */
/* Размещённый здесь JavaScript код будет загружаться всем пользователям при обращении к каждой странице */
/* Размещённый здесь JavaScript код будет загружаться всем пользователям при обращении к каждой странице */
/**
* EditTools support: add a selector, change <a> into buttons.
* The special characters to insert are defined at [[MediaWiki:Edittools]].
*
* @author Arnomane, 2006 (on the commons.wikimedia.org/wiki/MediaWiki:Edittools.js)
* @author Kaganer, 2007 (adapting to www.mediawiki.org)
* @author Krinkle, 2012
* @source www.mediawiki.org/wiki/MediaWiki:Gadget-Edittools.js
* @revision 2012-02-29
*/
/*jslint browser: true*/
/*global jQuery, mediaWiki*/
(function ($, mw) {
"use strict";
var conf, editTools, $sections;
conf = {
initialSubset: window.EditTools_initial_subset === undefined ? window.EditTools_initial_subset : 0
};
editTools = {
/**
* Creates the selector
*/
setup: function () {
var $container, $select, initial;
$container = $('#mw-edittools-charinsert');
if (!$container.length) {
return;
}
$sections = $container.find('.mw-edittools-section');
if ($sections.length <= 1) {
// Only care if there is more than one
return;
}
$select = $('<select>').css('display', 'inline');
initial = conf.initialSubset;
if (isNaN(initial) || initial < 0 || initial >= $select.length) {
initial = 0;
}
$sections.each(function (i, el) {
var $section, sectionTitle, $option;
$section = $(el);
sectionTitle = $section.data('sectionTitle');
$option = $('<option>')
.text(sectionTitle)
.prop('value', i)
.prop('selected', i === initial);
$select.append($option);
});
$select.change(editTools.handleOnchange);
$container.prepend($select);
editTools.chooseSection(initial);
},
/**
* Handle onchange event of the <select>
*
* @context {Element}
* @param e {jQuery.Event}
*/
handleOnchange: function () {
editTools.chooseSection(Number($(this).val()));
return true;
},
/**
* Toggle the currently visible section
*
* @param sectionNr {Number}
* @param setFocus {Boolean}
*/
chooseSection: function (sectionNr) {
var $choise = $sections.eq(sectionNr);
if ($choise.length !== 1) {
return;
}
// Making these buttons is a little slow,
// If we made them all at once the browser would hang
// for over 2 seconds, so instead we're doing it on-demand
// for each section. No need to do it twice thoguh, so remember
// in data whether it was done already
if (!$choise.data('charInsert.buttonsMade')) {
$choise.data('charInsert.buttonsMade', true);
editTools.makeButtons($choise);
}
$choise.show();
$sections.not($choise).hide();
},
/**
* Convert the <a onclick> links to buttons in a given section.
*
* @param $section {jQuery}
*/
makeButtons: function ($section) {
var $links;
if (!$section.length) {
return;
}
$links = $section.find('a');
$links.each(function (i, a) {
var $a, $button, start, end;
$a = $(a);
$button = $( '<input>' ).attr( 'type', 'button' );
start = $a.data( 'mw-charinsert-start' );
end = $a.data( 'mw-charinsert-end' );
if ( start !== undefined && end !== undefined ) {
$button.click( function( e ) {
e.preventDefault();
$('#wpTextbox1').textSelection('encapsulateSelection', {pre: start, post: end});
} );
} else {
$button[0].onclick = a.onclick;
                                }
$button[0].value = $a.text();
$a.replaceWith($button);
});
}
};
$(document).ready(editTools.setup);
}(jQuery, mediaWiki));


/*WikiEditor/Викификатор*/
/*WikiEditor/Викификатор*/
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
         mw.loader.load( '/extensions/Wikificator/Wikificator.js' );
         mw.loader.load( '//ru.wikipedia.org/w/index.php?title=MediaWiki:Gadget-wikificator.js&action=raw&ctype=text/javascript' );
}
}


Строка 180: Строка 37:
         } );
         } );
}
}
// define image path
var wikEdImagePath = '/extensions/wikEd/images';
// diff script URL
var wikEdDiffScriptSrc = '/extensions/wikEd/diff.js&action=raw&ctype=text/javascript';
// wikEdDiff script URL
var wikEdDiffSrc = '/extensions/wikEd/wikEdDiff.js&action=raw&ctype=text/javascript';
// InstaView script URL
var wikEdInstaViewSrc = '/extensions/wikEd/instaview.js&action=raw&ctype=text/javascript';
// help page link (if you do not host your own translation)
var wikEdText = {
  'wikEdHelpPageLink': ' | <a href="https://en.wikipedia.org/wiki/User:Cacycle/wikEd_help" target="helpwindow">wikEd help</a>';
}
// auto update: set to false or create a wiki version page
// var wikEdAutoUpdate = false;
// auto update: version url (Ajax)
var wikEdAutoUpdateUrl = '//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd_current_version&action=raw&maxage=0';
// RegExTypoFix rules page, the address must have the exact same domain name as the used wiki
//var wikEdRegExTypoFixURL = '//YOUR-DOMAIN.WHATEVER/PATH-TO-YOUR-WIKI/index.php?title=AutoWikiBrowser_typos&action=raw';
// install the wikEd translation (omit if no translation needed)
( function () { var script = document.createElement( 'script' ); script.src = '//YOUR-DOMAIN.WHATEVER/PATH-TO-YOUR-WIKI/index.php?title=wikEd_translation.js&action=raw&ctype=text/javascript'; script.async = true; document.getElementsByTagName( 'head' )[ 0 ].appendChild( script ); } ) ();
// install [https://en.wikipedia.org/wiki/User:Cacycle/wikEd] in-browser text editor
( function () { var script = document.createElement( 'script' ); script.src = '/extensions/wikEd/WikiEd.js&action=raw&ctype=text/javascript'; script.async = true; document.getElementsByTagName( 'head' )[ 0 ].appendChild( script ); } ) ();

Текущая версия на 00:06, 23 января 2021

/* MediaWiki:Common.js */
/* Размещённый здесь JavaScript код будет загружаться всем пользователям при обращении к каждой странице */

/*WikiEditor/Викификатор*/
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.load( '//ru.wikipedia.org/w/index.php?title=MediaWiki:Gadget-wikificator.js&action=raw&ctype=text/javascript' );
}

var customizeToolbar = function() {

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'format',
        'tools': {
                'wikify': {
                        label: 'Викификатор',
                        type: 'button',
                        icon: '//upload.wikimedia.org/wikipedia/commons/0/06/Wikify-toolbutton.png',
                             action: {
                                  type: 'callback',
                                       execute: function(context){
                                              Wikify();
                                       } 
                             }
                }
        }
} );
};
 
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor.toolbar', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}