Merge "Toolbar: Add a new 'toggle' tool type; declare as v0.5.2"

This commit is contained in:
jenkins-bot 2018-08-17 19:08:42 +00:00 committed by Gerrit Code Review
commit f31e9527b2
2 changed files with 23 additions and 9 deletions

View file

@ -1,6 +1,6 @@
{
"name": "WikiEditor",
"version": "0.5.1",
"version": "0.5.2",
"author": [
"Derk-Jan Hartman",
"Trevor Parscal",

View file

@ -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':