Користувач:Leh Palych/poems.js
Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.
- Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
- Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
- Internet Explorer / Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5
- Opera: натисніть Ctrl-F5
// User:Leh Palych/poems.js
//
$(function () {
if( mw.config.get( 'wgNamespaceNumber' ) !== 250 ) {
return;
}
if ($('#editform').length) {
$('#wpTextbox1').on( 'wikiEditor-toolbar-doneInitialSections', function() {
// for new item should add elenment of array Temps
var temps = new Array (
['replace','Заміна',replaceMain,false],
['table','Таблиця',table,false],
['shift','shift',"{{shift left|", "|2em}}",false],
['c_bold','c-bold',"{{c|'''","'''}}",false],
['c_','c_',"{{dhr}}\n{{c|","}}",false],
['Dash',' —','{{errata|| —}}','',false],
['bc-poem', 'bc-poem', '{{block center|<poem>', '</poem>}}',false],
['bc-s', 'bc/s', '{{block center/s}}','',true],
['bc-e', 'bc/e', '{{block center/e}}','',true],
['sc-b', 'section begin', '<section begin="', '"/>',false],
['sc-e', 'section end', '<section end="', '"/>',false],
['sec_b','sec/b-b/c-poem','<section begin=""/>{{block center/s}}<poem>','',false],
['sec_e','poem-b/e-sec/e','</poem>{{block center/e}}<section end=""/>\n{{dhr}}','',false],
['poem-s', 'poem', '<poem>','',false],
['poem-e', '/poem', '</poem>','',false],
['poems', 'poems', '<poem>', '</poem>',false],
['OnlyPage','{{тнс|}}','{{тнс|','}}',false],
['barObar','——O——','</poem>{{block center/e}}\n{{dhr|0.5em}}\n{{-o-}}<section end=""/>\n{{dhr|2em}}','',true]
);
var items = {};
for ( var i = 0; i < temps.length; i++ ) {
if (i === 0 || i === 1 ) {
items[temps[i][0]] = {
label: temps[i][1],
action: {
type: 'callback',
execute: temps[i][2]
}
};
} else {
items[temps[i][0]] = {
label: temps[i][1],
action: {
type: 'encapsulate',
options: {
pre: temps[i][2],
post: temps[i][3],
ownline: temps[i][4]
}
}
};
}
} // end for
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'main',
groups: {
poemtemp: {
tools: {
poemtemp: {
label: '4poem',
type: 'select',
list: items
}
}
}
}
}); // new select
});
}
});
function replaceMain()
{
var text = $('#wpTextbox1').val();
var nbsp = String.fromCharCode(160);
var dash1, dash2;
dash1 = nbsp.concat("—");
dash2 = nbsp.concat("— ");
var item;
var arr = [
[/([0-9])\)\s/g, "$1)"+nbsp],
[/\s([а-яґєїa-z])\)\s/g, " $1)"+nbsp],
[/\s([\.\!\?\:\;\,\)…])/g, '$1'],
[/([0-9])\)\?/g, "$1)"+nbsp+'?'],
[/\.\.\./g, "…"],
[/\…\./g, "...."],
[/\s"/g, ' „'],
[/"(?=[\.\s\,\!\?\:\;\)\<…])/g, '“'],
[/¬\n/g, ''],
[/\/g, ''],
[/ \n/g, '\n'],
[/[’‘]/g, "'"],
[/([A-Za-zА-ЯЇҐЄіа-яїґєі\.\!\?\:\;\,\)…„»«“”\"])—/g, '$1 —'],
[/—([A-Za-zА-ЯЇҐЄіа-яїґєі„»«“”\"])/g, '— $1'],
[/ —/g, dash1],
[/\t/g, " "],
[/^{{[-—]+}}/mg, "— "],
[/\{\{\-\-\}\}/g, dash2],
[/\s\{\{—\}\}\s/g, dash2],
[/\{\{—\}\}/g, dash2],
[/\-\-/g, dash2],
[/\s\|\|\s/g, '||'],
[/\s\|\|/g, '||'],
[/\|\|\s/g, '||'],
[/\|\s/g, '|'],
[/([0-9])\s([гр]\.)/g, '$1'+nbsp+'$2'],
[/([IVX])\s(в\.)/g, '$1'+nbsp+'$2'],
[/([IVX])\s(ст\.)/g, '$1'+nbsp+'$2'],
[/№\s/g, "№"+nbsp],
[/\sт\. ([пдєиі]\.)/g, " т."+nbsp+"$1"],
[/(і [тм]\.) ([іи]н\.)/g, "$1"+nbsp+"$2"],
[/т\. (з[нв]\.)/g, "т."+nbsp+"$1"],
[/п\. з\./g, "п."+nbsp+"з."],
[/іцб/g, "що"+'\u0301'],
[/([Щщ])б([\.\!\?\:\;\,\s\-…])/g, "$1о"+'\u0301'+"$2"],
[/\sіцо([\s\-])/g, " що"+"$1"],
[/\sіце\s/g, " ще "],
[/«\s/g,"« "]
];
// [/([A-ZА-ЯЇҐЄѲ]\.)\s([A-ZА-ЯЇҐЄѲ])/g, '$1'+nbsp+'$2'],
for (item of arr) {
text = text.replace(item[0], item[1]);
}
text = text.replace(/“ \/\>/g, '" />');
text = text.replace(/align:top“/g, 'align:top"');
text = text.replace(/wikitable“/g, 'wikitable"');
text = text.replace(/- „ -/g, '–"–');
/* text = text.replace(/([\.\!\?\…\:])\s\n/g, "$1\n");*/
$('#wpTextbox1').val(text);
}
function table()
{
var text = $('#wpTextbox1').val();
text = '<!-- -->\n'+text;
$('#wpTextbox1').val(text);
text = $('#wpHeaderTextbox').val();
text = '{| class="add"\n|-\n';
$('#wpHeaderTextbox').val(text);
text = $('#wpFooterTextbox').val();
text = '<!-- -->\n|}';
$('#wpFooterTextbox').val(text);
}