/*global mediaWiki, jQuery */
/*jslint browser: true, plusplus: true, white: true */
/*jshint browser:true, laxbreak:false, plusplus:false, white:false, undef:true, unused:true */
( function ( mw, $ ) {
'use strict';
if ( /*mw.config.get( 'wgNamespaceNumber' ) || */ !/^(edit|submit)$/.test( mw.config.get( 'wgAction' ) ) ) {
return;
}
$( document ).ready( function () {
var replacements = [
[
/(^|\n)(==+)(+)(\2) *(?=\n)/g,
function ( $0, $1, $2, $3, $4 ) {
return $1 + '\n' + $2 + ' ' + $.trim( $3 ) + ' ' + $4;
}
], [
/\n\{\{\s*\s*:\s*Vzor /g,
'\n\n{{subst:Vzor '
], [
/\n(+)(*)/g,
function ( $0, $1, $2 ) {
return '\n' + $1 + ' ' + $.trim( $2 );
}
], [
/# */g,
'# —'
], [
/# \{\{Překlady *\}\}/g,
'# {{Překlady\n}}'
], [
/\]+)\]\]/gi,
function ( $0, $1 ) {
return '\n]\n';
}
], [
/(\]+\]\])\n+(?!\)/g,
'$1\n'
], [
/\n+ *\|(+)=(?!*\|\|*\n)(*)(?=\n)/g,
function ( $0, $1, $2 ) {
return '\n | ' + $.trim( $1 ) + ' = ' + $.trim( $2 );
}
], [
/() +\n/g,
'$1\n'
], [
/() +/g,
'$1 '
], [
/\n{3,}/g,
'\n\n'
], [
/=== starší varianta zápisu ===/g,
'=== varianty ==='
], [
/=== novější varianta zápisu ===/g,
'=== varianty ==='
], [
/=== varianta zápisu ===/g,
'=== varianty ==='
], [
/(snom|sgen|sdat|sacc|svoc|sloc|sins|pnom|pgen|pdat|pacc|pvoc|ploc|pins|spre1|spre2|spre3|ppre1|ppre2|ppre3|sfut1|sfut2|sfut3|pfut1|pfut2|pfut3|simp2|pimp1|pimp2|sactm|sactf|sactn|pactm|pactf|actn|ptram|ptraf|ptrap|mtram|mtraf|mtrap|spasm|spasf|spasn|ppasm|ppasf|ppasn|snomma|snomm|snomf|snomn|pnomma|pnomm|pnomf|pnomn|sgenma|sgenm|sgenf|sgenn|pgenma|pgenm|pgenf|pgenn|sdatma|sdatm|sdatf|sdatn|pdatma|pdatm|pdatf|pdatn|saccma|saccm|saccf|saccn|paccma|paccm|paccf|paccn|slocma|slocm|slocf|slocn|plocma|plocm|plocf|plocn|sinsma|sinsm|sinsf|sinsn|pinsma|pinsm|pinsf|pinsn|snomma-jm|snomm-jm|snomf-jm|snomn-jm|pnomma-jm|pnomm-jm|pnomf-jm|pnomn-jm|saccma-jm|saccm-jm|saccf-jm|saccn-jm|paccma-jm|paccm-jm|paccf-jm|paccn-jm) *= *((({{Příznak2\|*}} *)?{}\/\n]+)( *\/ *({{Příznak2\|*}} *)?{}\/\n]+)*)$/gm,
function ($0,$1,$2) {
var pageName = mw.config.get( 'wgPageName' );
var innerRe = /({{Příznak2\|*}})? *({}\/\n]+)( \/ |$)/gm;
var text = $1 + " = " + $2.replace( innerRe, function($0,$1,$2,$3) {
if ($2 === pageName) return $1 ? $1 + " " + $2 : $2;
var result = $1 ? $1 + " ]" : "]";
if ($3) result += " / ";
return result;
});
return text;
}
],
];
var $button = $('<button>');
$button.text('AKÚ');
$('#wpDiff').after($button);
$button.click( function () {
$( '#wpTextbox1' ).val( function ( index, oldPageText ) {
var newPageText = oldPageText;
$.each( replacements, function ( index, replacement ) {
newPageText = newPageText.replace( replacement, replacement );
});
newPageText = $.trim( newPageText ) + '\n';
if ( newPageText !== oldPageText ) {
$( '#wpSummary' ).val( function ( index, summary ) {
var summarySeparator = '';
summary = $.trim( summary );
if ( summary !== '' ) {
summarySeparator = /^\/\*.*\*\/$/.test( summary ) ? ' ' : '; ';
}
return summary + summarySeparator + ']+';
});
}
return newPageText;
});
return false;
});
});
}( mediaWiki, jQuery ) );