User:BZPN/PNHelper.js: Difference between revisions
From Test Wiki
Content deleted Content added
Created page with "// <nowiki> mw.loader.using(['oojs-ui-core', 'oojs-ui-windows'], function () { mw.hook('wikipage.content').add(function ($content) { // Tworzenie przycisku var $button = $('<li id="t-custom-task"><a href="#"></a></li>'); $button.find('a').text('Dodaj zadanie'); // Dodanie przycisku do paska narzędzi $('#p-tb ul').append($button); // Funkcja tworząca okno dialogowe function createDialog() { var di..." |
No edit summary Tag: Reverted |
||
| Line 1: | Line 1: | ||
// <nowiki> |
// <nowiki> |
||
mw.loader.using(['oojs-ui-core', 'oojs-ui-windows'], function () { |
mw.loader.using(['oojs-ui-core', 'oojs-ui-windows', 'oojs-ui-widgets'], function () { |
||
mw.hook('wikipage.content').add(function ($content) { |
mw.hook('wikipage.content').add(function ($content) { |
||
// Tworzenie przycisku |
// Tworzenie przycisku |
||
| Line 12: | Line 12: | ||
function createDialog() { |
function createDialog() { |
||
var dialog = new OO.ui.MessageDialog({ |
var dialog = new OO.ui.MessageDialog({ |
||
size: ' |
size: 'large' |
||
}); |
}); |
||
| Line 22: | Line 22: | ||
var descriptionInput = new OO.ui.MultilineTextInputWidget({ |
var descriptionInput = new OO.ui.MultilineTextInputWidget({ |
||
placeholder: 'Wpisz opis zadania', |
placeholder: 'Wpisz opis zadania', |
||
rows: |
rows: 10, |
||
autosize: true |
|||
}); |
}); |
||
// Przyciski edycji tekstu |
|||
var boldButton = new OO.ui.ButtonWidget({ |
|||
icon: 'bold', |
|||
title: 'Pogrubienie' |
|||
}); |
|||
var italicButton = new OO.ui.ButtonWidget({ |
|||
icon: 'italic', |
|||
title: 'Kursywa' |
|||
}); |
|||
var underlineButton = new OO.ui.ButtonWidget({ |
|||
icon: 'underline', |
|||
title: 'Podkreślenie' |
|||
}); |
|||
var editButtons = new OO.ui.ButtonGroupWidget({ |
|||
items: [boldButton, italicButton, underlineButton] |
|||
}); |
|||
// Przycisk dodawania linków |
|||
var addLinkButton = new OO.ui.ButtonWidget({ |
var addLinkButton = new OO.ui.ButtonWidget({ |
||
label: 'Dodaj link', |
label: 'Dodaj link', |
||
icon: 'link' |
|||
}); |
|||
// Funkcje edycji tekstu |
|||
function wrapSelection(before, after) { |
|||
var textarea = descriptionInput.$input[0]; |
|||
var start = textarea.selectionStart; |
|||
var end = textarea.selectionEnd; |
|||
var selectedText = textarea.value.substring(start, end); |
|||
var replacement = before + selectedText + after; |
|||
textarea.value = textarea.value.substring(0, start) + replacement + textarea.value.substring(end); |
|||
descriptionInput.setValue(textarea.value); |
|||
} |
|||
boldButton.on('click', function() { wrapSelection("'''", "'''"); }); |
|||
italicButton.on('click', function() { wrapSelection("''", "''"); }); |
|||
underlineButton.on('click', function() { wrapSelection("<u>", "</u>"); }); |
|||
// Funkcja dodawania linków |
|||
addLinkButton.on('click', function() { |
|||
var selectedText = descriptionInput.$input[0].value.substring( |
|||
descriptionInput.$input[0].selectionStart, |
|||
descriptionInput.$input[0].selectionEnd |
|||
); |
|||
if (selectedText) { |
|||
// Proste automatyczne wyszukiwanie - używamy zaznaczonego tekstu jako tytułu strony |
|||
var link = '[[' + selectedText + ']]'; |
|||
wrapSelection(link, ''); |
|||
} else { |
|||
alert('Zaznacz tekst, aby dodać link.'); |
|||
} |
|||
}); |
}); |
||
| Line 39: | Line 89: | ||
align: 'top' |
align: 'top' |
||
}), |
}), |
||
new OO.ui.FieldLayout( |
new OO.ui.FieldLayout(editButtons, { |
||
label: ' |
label: 'Edycja tekstu', |
||
align: 'top' |
align: 'top' |
||
}), |
}), |
||
new OO.ui.FieldLayout(addLinkButton, { |
new OO.ui.FieldLayout(addLinkButton, { |
||
align: 'top' |
|||
}), |
|||
new OO.ui.FieldLayout(descriptionInput, { |
|||
label: 'Opis', |
|||
align: 'top' |
align: 'top' |
||
}) |
}) |
||