Redaktor:Gateshebe/common2.js
Poznámka: Aby sa zmeny prejavili, po uložení musíte vymazať vyrovnávaciu pamäť vášho prehliadača. Mozilla / Firefox / Safari: držte stlačený Shift a kliknite na Reload alebo stlačte buď Ctrl-F5 alebo Ctrl-R (Command-R na Macintosh); Konqueror:: kliknite na tlačidlo Reload alebo stlačte F5; Opera vymazať vyrovnávaciu pamäť prehliadača v ponuke Tools→Preferences; Internet Explorer: držte Ctrl a kliknite na Refresh alebo stlačte Ctrl-F5;
/**
* Interface for the classic edit toolbar.
*
* Adapted from MediaWiki Core, before it was removed from it on 2018-10-17
*/
( function () {
var toolbar, isReady, $toolbar, queue, slice, $currentFocused;
/**wpTextbox1').val(cssk_srclang
* Internal helper that does the actual insertion of the button into the toolbar.
*
* For backwards-compatibility, passing `imageFile`, `speedTip`, `tagOpen`, `tagClose`,
* `sampleText` and `imageId` as separate arguments (in this order) is also supported.
*
* @private
*
* @param {Object} button Object with the following properties.
* You are required to provide *either* the `onClick` parameter, or the three parameters
* `tagOpen`, `tagClose` and `sampleText`, but not both (they're mutually exclusive).
* @param {string} [button.imageFile] Image to use for the button.
* @param {string} button.speedTip Tooltip displayed when user mouses over the button.
* @param {Function} [button.onClick] Function to be executed when the button is clicked.
* @param {string} [button.tagOpen]
* @param {string} [button.tagClose]
* @param {string} [button.sampleText] Alternative to `onClick`. `tagOpen`, `tagClose` and
* `sampleText` together provide the markup that should be inserted into page text at
* current cursor position.
* @param {string} [button.imageId] `id` attribute of the button HTML element. Can be
* used to define the image with CSS if it's not provided as `imageFile`.
* @param {string} [speedTip]
* @param {string} [tagOpen]
* @param {string} [tagClose]
* @param {string} [sampleText]
* @param {string} [imageId]
*/
function insertButton( button, speedTip, tagOpen, tagClose, sampleText, imageId ) {
var $button;
// Backwards compatibility
if ( typeof button !== 'object' ) {
button = {
imageFile: button,
speedTip: speedTip,
tagOpen: tagOpen,
tagClose: tagClose,
sampleText: sampleText,
imageId: imageId
};
}
if ( button.imageFile ) {
$button = $( '<img>' ).attr( {
src: button.imageFile,
alt: button.speedTip,
title: button.speedTip,
id: button.imageId || undefined,
'class': 'mw-toolbar-editbutton'
} );
} else {
$button = $( '<div>' ).attr( {
title: button.speedTip,
id: button.imageId || undefined,
'class': 'mw-toolbar-editbutton'
} );
}
$button.click( function ( e ) {
if ( button.onClick !== undefined ) {
button.onClick( e );
} else {
toolbar.insertTags( button.tagOpen, button.tagClose, button.sampleText );
}
return false;
} );
$toolbar.append( $button );
}
isReady = false;
$toolbar = false;
/**
* @private
* @property {Array}
* Contains button objects (and for backwards compatibility, it can
* also contains an arguments array for insertButton).
*/
queue = [];
slice = queue.slice;
toolbar = {
/**
* Add buttons to the toolbar.
*
* Takes care of race conditions and time-based dependencies by placing buttons in a queue if
* this method is called before the toolbar is created.
*
* For backwards-compatibility, passing `imageFile`, `speedTip`, `tagOpen`, `tagClose`,
* `sampleText` and `imageId` as separate arguments (in this order) is also supported.
*
* @inheritdoc #insertButton
*/
addButton: function () {
if ( isReady ) {
insertButton.apply( toolbar, arguments );
} else {
// Convert arguments list to array
queue.push( slice.call( arguments ) );
}
},
/**
* Add multiple buttons to the toolbar (see also #addButton).
*
* Example usage:
*
* addButtons( [ { .. }, { .. }, { .. } ] );
* addButtons( { .. }, { .. } );
*
* @param {...Object|Array} [buttons] An array of button objects or the first
* button object in a list of variadic arguments.
*/
addButtons: function ( buttons ) {
if ( !Array.isArray( buttons ) ) {
buttons = slice.call( arguments );
}
if ( isReady ) {
buttons.forEach( function ( button ) {
insertButton( button );
} );
} else {
// Push each button into the queue
queue.push.apply( queue, buttons );
}
},
/**
* Apply tagOpen/tagClose to selection in currently focused textarea.
*
* Uses `sampleText` if selection is empty.
*
* @param {string} tagOpen
* @param {string} tagClose
* @param {string} sampleText
*/
insertTags: function ( tagOpen, tagClose, sampleText ) {
if ( $currentFocused && $currentFocused.length ) {
$currentFocused.textSelection(
'encapsulateSelection', {
pre: tagOpen,
peri: sampleText,
post: tagClose
}
);
}
}
};
// For backwards compatibility. Used to be called from EditPage.php, maybe other places as well.
toolbar.init = $.noop;
// Expose API publicly
mw.toolbar = toolbar;
$( function () {
var $textBox, i, button;
// Used to determine where to insert tags
$currentFocused = $( '#wpTextbox1' );
// Populate the selector cache for $toolbar
$toolbar = $( '#toolbar' );
if ( $toolbar.length === 0 ) {
$textBox = $( '#wpTextbox1' );
if ( $textBox.length === 0 ) {
return;
}
$toolbar = $( '<div>' ).attr( { id: 'toolbar' } );
$toolbar.insertBefore( $textBox );
}
for ( i = 0; i < queue.length; i++ ) {
button = queue[ i ];
if ( Array.isArray( button ) ) {
// Forwarded arguments array from mw.toolbar.addButton
insertButton.apply( toolbar, button );
} else {
// Raw object from mw.toolbar.addButtons
insertButton( button );
}
}
// Clear queue
queue.length = 0;
// This causes further calls to addButton to go to insertion directly
// instead of to the queue.
// It is important that this is after the one and only loop through
// the queue
isReady = true;
// Apply to dynamically created textboxes as well as normal ones
$( document ).on( 'focus', 'textarea, input:text', function () {
$currentFocused = $( this );
} );
} );
}() );
var wgContentLanguage = mw.config.get('wgContentLanguage');
var cssk_srclang = (wgContentLanguage == 'sk' ? 'cs' : 'sk');
var cssk_tgtlang = (wgContentLanguage == 'sk' ? 'sk' : 'cs');
function cssk_start() {
var wgTitle = mw.config.get('wgTitle');
cssk_srctitle = prompt((cssk_srclang == 'sk' ? 'Zadejte název ze skwiki:' : 'Zadajte názov z cswiki:'), wgTitle);
cssk_running();
mw.loader.load('https://cssk.toolforge.org/scripts/cssk.php?'+srclang+'='+cssk_srclang+'&'+tgtlang+'='+cssk_tgtlang+'&'+title+'='+cssk_srctitle);
}
function cssk_running() {
$('#wpTextbox1').val(cssk_srclang == 'sk' ? 'Překlad se připravuje, prosím čekejte...' : 'Preklad sa pripravuje, prosím čakajte...');
}
function cssk_done(json) {
if(json.hasOwnProperty('text'))
$('#wpTextbox1').val(text);
else
$('#wpTextbox1').val(cssk_srclang == 'sk' ? 'Chyba: Překlad se nepodařilo získat.' : 'Chyba: Preklad sa nepodarilo získať.');
if(json.hasOwnProperty('summary')) $('#wpSummary').val(json.summary);
}
function cssk_button() {
var msg = '';
var cssk_buttonlabel = (cssk_srclang == 'sk' ? 'Start' : 'Štart');
var cssk_buttonicon = (cssk_srclang == 'sk' ? '//tools.wmflabs.org/cssk/img/icon_sk-cs.png' : '//tools.wmflabs.org/cssk/img/icon_cs-sk.png');
var cssk_buttonicon_classic = (cssk_srclang == 'sk' ? '//tools.wmflabs.org/cssk/img/icon_sk-cs_classic.png' : '//tools.wmflabs.org/cssk/img/icon_cs-sk_classic.png');
// add button to the advanced toolbar generated by Extension:WikiEditor, if it is active
mw.loader.using('user.options', function() {
if(mw.user.options.get('usebetatoolbar')) {
mw.loader.using('ext.wikiEditor', function() {
$(function() {
$('#wpTextbox1').wikiEditor('addToToolbar', {
'section': 'advanced',
'group': 'insert',
'tools': {
'cssk': {
label: cssk_buttonlabel,
type: 'button',
icon: cssk_buttonicon,
action: {
type: 'callback',
execute: function(context) {
cssk_start();
}
}
}
}
} );
});
});
}
});
// add button to the classic edit toolbar - code inspired by [[:en:User:V111P/js/addToolbarButtons.js]]
mw.loader.using('mediawiki.action.edit', function () {
mw.toolbar.addButton(cssk_buttonicon_classic, cssk_buttonlabel, '', '', '', 'csskButtonTemp', 'csskButtonTemp');
var tempButton = $('#csskButtonTemp');
if(tempButton.length) {
var newButton = tempButton[0].cloneNode();
newButton.id = 'csskButton';
tempButton.after(newButton).remove();
$(newButton).click(cssk_start);
}
});
}
// only launch the script when editting and unless it's a user JS/CSS page
var wgAction = mw.config.get('wgAction');
var wgNamespaceNumber = mw.config.get('wgNamespaceNumber');
var wgPageName = mw.config.get('wgPageName');
if((wgAction == 'edit' || wgAction == 'submit') && !((wgNamespaceNumber == 2 || wgNamespaceNumber == 4) && (wgPageName.indexOf('.js') != -1 || wgPageName.indexOf('.css') != -1 ))) {
$(cssk_button);
}