MediaWiki:Gadget-lib-toolbar.js
Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5.
- Opera: Naciśnij klawisze Ctrl+F5.
/*
* @author: [[:pl:User:Beau]]
*/
var tbg = mw.libs.toolbarGadget = {
/** Version of the gadget */
version: 9,
/** An array of buttons, which were added before a toolbar was constructed */
buttons: []
},
tbgHook = mw.hook( 'toolbarGadget.ready' );
function addButtonWikiEditor( $toolbar ) {
var $image, $link, $section, $group,
title = this.title || '',
groupName = this.group || 'custom';
// FIXME: rewrite it using a toolbar api
$image = $( '<img>' )
.addClass( 'tool tool-button' )
.css( {
height: '18px',
paddingTop: '4px'
} )
.attr( {
alt: this.alt || title,
title: title,
id: this.id,
src: this.newIcon || this.icon
} );
$link = $( '<a>' )
.attr( 'href', this.href )
.append( $image )
.on( 'click', this.onclick );
// A section of the button
if ( this.section ) {
$section = $toolbar.find( 'div.section-' + this.section ).eq( 0 );
}
// A group of the button
$group = ( $section || $toolbar ).find( 'div.group-' + groupName ).eq( 0 );
if ( !$group.length ) {
// If the section does not exist, place the button in main section
if ( !$section ) {
$section = $toolbar.find( 'div.section-main' ).eq( 0 );
}
$group = $( '<div>' )
.addClass( 'group group-' + groupName )
.attr( 'rel', groupName )
.appendTo( $section );
}
$group.append( $link );
if ( this.oncreate ) {
this.oncreate( $image.get( 0 ) );
}
}
/**
* Adds a button to the toolbar
* @param button An object describing the button, its values:
* title - a title of the button
* alt - an alternative text displayed when image is not loaded
* id - an identifier of the button (img)
* href - a link
* onclick - a callback
* icon - an icon of the button
* oldIcon - an icon for the old toolbar (by default icon parameter is used)
* newIcon - an icon for the new toolbar (by default icon parameter is used)
* section - a name of a section to which the button should be added
* group - a name of a group to which the button should be added (it will be created if not exists)
* oncreate - a callback invoked after the button has been created
*/
tbg.addButton = function ( button ) {
tbg.buttons.push( button );
tbgHook.add( $.proxy( addButtonWikiEditor, button ) );
};
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
mw.loader.using( 'ext.wikiEditor' ).done( function () {
$( function () {
tbg.buttons.length = 0; // http://stackoverflow.com/q/1232040
tbgHook.fire( $( '#wikiEditor-ui-toolbar' ) );
} );
} );
}