Користувач:Konstrooktor/Metagraph.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
//Правила видання документів і пам'яток http://www.archives.gov.ua/Law-base/Pravila_vydannia.php
function orthEtym()
{
strInput = document.editform.wpTextbox1.textSelection( 'getSelection' );
//ъ
//прибирання ъ в кінці слова
strInput = strInput.replace(/(ъ)([^А-Яа-яҐґЄєІіЇї’ѢѣЫыЁёÎî\u0302])/g, '<s>$1</s>$2');
//ь
//прибирання ь в кінці слова після б, п, в, м, ф, ш, ч, ж
strInput = strInput.replace(/([бпвмфшчж])(ь)([^А-Яа-яҐґЄєІіЇї’ѢѣЫыЁёÎî\u0302])/g, '$1<s>$2</s>$3');
//ѣ
//заміна ѣ на і
strInput = strInput.replace(/(ѣ)/g, '<s>$1</s>і');
//діакритичні знаки
//заміна о̂ на початку слова на ві
strInput = strInput.replace(/([^А-Яа-яҐґЄєІіЇї’ѢѣЫыЁёÎî\u0302])([Оо]\u0302)/g, '$1<s>$2</s>ві');
//заміна о̂, е̂, и̂ на і
strInput = strInput.replace(/([ОоЕеИи]\u0302)/g, '<s>$1</s>і');
//ы
//заміна ы на и
strInput = strInput.replace(/(ы)/g, '<s>$1</s>и');
//е
//заміна е на початку слова на є
strInput = strInput.replace(/([^А-Яа-яҐґЄєІіЇї’ѢѣЫыЁёÎî\u0302])(е)(^\u0302)/g, '$1<s>$2</s>є$3');
//заміна е після голосних на є
strInput = strInput.replace(/([аоеиуі])(е)(^\u0302)/g, '$1<s>$2</s>є$3');
document.editform.wpTextbox1.value = strInput;
}
function clearStrike()
{
strInput = document.editform.wpTextbox1.textSelection( 'getSelection' );
strInput = strInput.replace(/\u003Cs\u003E[А-Яа-яҐґЄєІіЇї’ѢѣЫыЁёÎî\u0302]*\u003C\u002Fs\u003E/g, '');
document.editform.wpTextbox1.value = strInput;
}
var customizeToolbar = function() {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'oldorth': {
'type': 'toolbar',
'label': 'Старий правопис',
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'oldorth',
'groups': {
'metagraph': {
'label': 'Метаграф'
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'oldorth',
'group': 'metagraph',
'tools': {
'orthography': {
label: 'Правопис',
type: 'select',
list: {
'etymological' : {
label : 'Етимологічний',
action : {
type: 'callback',
execute: function(context){
orthEtym();
}
}
},
'zhelekhiv' : {
label : 'Желехівка',
action : {
type: 'callback',
execute: function(context){
orthZhel();
}
}
},
'yaryzhka' : {
label : 'Ярижка',
action : {
type: 'callback',
execute: function(context){
orthYar();
}
}
},
'drahomaniv' : {
label : 'Драгоманівка',
action : {
type: 'callback',
execute: function(context){
orthDrah();
}
}
}
}
}
}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'oldorth',
'group': 'metagraph',
'tools': {
'clearstr': {
label: 'Прибрати закреслене',
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/c/c9/Button_strike.png',
action: {
type: 'callback',
execute: function(context){
clearStrike();
}
}
}
}
} );
};
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
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', function () {
$(document).ready( customizeToolbar );
} );
}
} );
}