mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-04 20:36:03 +01:00
Implemented Undo / Redo buttons for Editor (fixes #420)
This commit is contained in:
@@ -64,8 +64,54 @@ export let strategies = {
|
||||
replaceRange() {}
|
||||
};
|
||||
|
||||
const flipDisabled = (codemirror, button, type) => {
|
||||
let hasHistory = codemirror.historySize()[type];
|
||||
let element = button.find('a');
|
||||
button[hasHistory ? 'removeClass' : 'addClass']('button-disabled');
|
||||
|
||||
if (!hasHistory) {
|
||||
element.attr('title-disabled', element.attr('title'));
|
||||
element.attr('data-hint-disabled', element.attr('data-hint'));
|
||||
element.removeAttr('title').removeAttr('data-hint');
|
||||
} else {
|
||||
element.attr('title', element.attr('title-disabled'));
|
||||
element.attr('data-hint', element.attr('data-hint-disabled'));
|
||||
element.removeAttr('title-disabled').removeAttr('data-hint-disabled');
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
navigation: [
|
||||
{
|
||||
undo: {
|
||||
identifier: 'undo',
|
||||
title: 'Undo',
|
||||
label: '<i class="fa fa-fw fa-undo"></i>',
|
||||
modes: [],
|
||||
action({ codemirror, button, textarea}) {
|
||||
button.addClass('button-disabled');
|
||||
codemirror.on('change', () => flipDisabled(codemirror, button, 'undo'));
|
||||
button.on('click.editor.undo', () => {
|
||||
codemirror.undo();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
redo: {
|
||||
identifier: 'redo',
|
||||
title: 'Redo',
|
||||
label: '<i class="fa fa-fw fa-repeat"></i>',
|
||||
modes: [],
|
||||
action({ codemirror, button, textarea}) {
|
||||
button.addClass('button-disabled');
|
||||
codemirror.on('change', () => flipDisabled(codemirror, button, 'redo'));
|
||||
button.on('click.editor.redo', () => {
|
||||
codemirror.redo();
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
bold: {
|
||||
identifier: 'bold',
|
||||
|
||||
2
themes/grav/css-compiled/preset.css
vendored
2
themes/grav/css-compiled/preset.css
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
16
themes/grav/js/admin.min.js
vendored
16
themes/grav/js/admin.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -785,6 +785,18 @@ form {
|
||||
border-right: 1px solid transparent;
|
||||
}
|
||||
}
|
||||
|
||||
.button-disabled a {
|
||||
color: #ccc;
|
||||
text-shadow: 0 1px white;
|
||||
|
||||
&:hover, &:focus {
|
||||
background: lighten($content-bg, 5%);
|
||||
color: #ccc;
|
||||
border-left: 1px solid transparent;
|
||||
border-right: 1px solid transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user