mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-27 09:42:11 +00:00
Merge "Toolbar: Add a new 'toggle' tool type; declare as v0.5.2"
This commit is contained in:
commit
f31e9527b2
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "WikiEditor",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.2",
|
||||
"author": [
|
||||
"Derk-Jan Hartman",
|
||||
"Trevor Parscal",
|
||||
|
|
|
@ -305,7 +305,7 @@
|
|||
return $group;
|
||||
},
|
||||
buildTool: function ( context, id, tool ) {
|
||||
var i, label, $button, icon, $select, $options, oouiButton,
|
||||
var i, label, $button, config, icon, $select, $options, oouiButton,
|
||||
option, optionLabel;
|
||||
if ( 'filters' in tool ) {
|
||||
for ( i = 0; i < tool.filters.length; i++ ) {
|
||||
|
@ -317,13 +317,19 @@
|
|||
label = $.wikiEditor.autoMsg( tool, 'label' );
|
||||
switch ( tool.type ) {
|
||||
case 'button':
|
||||
case 'toggle':
|
||||
if ( tool.oouiIcon ) {
|
||||
oouiButton = new OO.ui.ButtonWidget( {
|
||||
config = {
|
||||
framed: false,
|
||||
classes: [ 'tool' ],
|
||||
icon: tool.oouiIcon,
|
||||
title: label
|
||||
} );
|
||||
};
|
||||
if ( tool.type === 'button' ) {
|
||||
oouiButton = new OO.ui.ButtonWidget( config );
|
||||
} else if ( tool.type === 'toggle' ) {
|
||||
oouiButton = new OO.ui.ToggleButtonWidget( config );
|
||||
}
|
||||
$button = oouiButton.$element;
|
||||
$button.attr( 'rel', id );
|
||||
$button.data( 'ooui', oouiButton );
|
||||
|
@ -349,8 +355,8 @@
|
|||
$button.toggleClass( 'tool-active', active );
|
||||
|
||||
// OOUI button
|
||||
if ( $button.data( 'ooui' ) ) {
|
||||
$button.data( 'ooui' ).setFlags( { progressive: active } );
|
||||
if ( $button.data( 'ooui' ) && tool.type === 'toggle' ) {
|
||||
$button.data( 'ooui' ).setValue( active );
|
||||
}
|
||||
} );
|
||||
if ( 'action' in tool ) {
|
||||
|
@ -361,14 +367,22 @@
|
|||
// No dragging!
|
||||
e.preventDefault();
|
||||
return false;
|
||||
} )
|
||||
.click( function ( e ) {
|
||||
} );
|
||||
if ( $button.data( 'ooui' ) ) {
|
||||
$button.data( 'ooui' ).on( 'click', function () {
|
||||
$.wikiEditor.modules.toolbar.fn.doAction(
|
||||
$( this ).data( 'context' ), $( this ).data( 'action' ), $( this )
|
||||
context, tool.action
|
||||
);
|
||||
} );
|
||||
} else {
|
||||
$button.on( 'click', function ( e ) {
|
||||
$.wikiEditor.modules.toolbar.fn.doAction(
|
||||
context, tool.action
|
||||
);
|
||||
e.preventDefault();
|
||||
return false;
|
||||
} );
|
||||
}
|
||||
}
|
||||
return $button;
|
||||
case 'select':
|
||||
|
|
Loading…
Reference in a new issue