feat: add move up/down functionality for alternate greetings (#4676)
* feat: add move up/down functionality for alternate greetings * Remove disabled cursor style
This commit is contained in:
+8
-1
@@ -7216,11 +7216,18 @@
|
||||
<div class="alternate_greeting">
|
||||
<details open>
|
||||
<summary>
|
||||
<div class="title_restorable">
|
||||
<div class="title_restorable gap5px">
|
||||
<div class="flex-container alignItemsCenter">
|
||||
<strong><span data-i18n="Alternate Greeting #">Alternate Greeting #</span><span class="greeting_index"></span></strong>
|
||||
<i class="editor_maximize fa-solid fa-maximize right_menu_button" title="Expand the editor" data-i18n="[title]Expand the editor"></i>
|
||||
</div>
|
||||
<span class="expander"></span>
|
||||
<div class="menu_button menu_button_icon move_up_alternate_greeting" title="Move up" data-i18n="[title]Move up">
|
||||
<i class="fa-solid fa-chevron-up"></i>
|
||||
</div>
|
||||
<div class="menu_button menu_button_icon move_down_alternate_greeting" title="Move down" data-i18n="[title]Move down">
|
||||
<i class="fa-solid fa-chevron-down"></i>
|
||||
</div>
|
||||
<div class="menu_button menu_button_icon delete_alternate_greeting">
|
||||
<i class="fa-solid fa-trash-alt"></i>
|
||||
<span data-i18n="Delete">Delete</span>
|
||||
|
||||
+52
-7
@@ -8450,6 +8450,8 @@ function openAlternateGreetings() {
|
||||
array.push('');
|
||||
addAlternateGreeting(template, '', index, getArray, popup);
|
||||
updateAlternateGreetingsHintVisibility(template);
|
||||
const list = template.find('.alternate_greetings_list');
|
||||
list.scrollTop(list.prop('scrollHeight'));
|
||||
});
|
||||
|
||||
popup.show();
|
||||
@@ -8466,6 +8468,7 @@ function openAlternateGreetings() {
|
||||
*/
|
||||
function addAlternateGreeting(template, greeting, index, getArray, popup) {
|
||||
const greetingBlock = $('#alternate_greeting_form_template .alternate_greeting').clone();
|
||||
greetingBlock.attr('data-index', index);
|
||||
greetingBlock.find('.alternate_greeting_text')
|
||||
.attr('id', `alternate_greeting_${index}`)
|
||||
.on('input', async function () {
|
||||
@@ -8479,15 +8482,57 @@ function addAlternateGreeting(template, greeting, index, getArray, popup) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if (confirm(t`Are you sure you want to delete this alternate greeting?`)) {
|
||||
const array = getArray();
|
||||
array.splice(index, 1);
|
||||
|
||||
// We need to reopen the popup to update the index numbers
|
||||
await popup.complete(POPUP_RESULT.AFFIRMATIVE);
|
||||
openAlternateGreetings();
|
||||
const confirm = await callGenericPopup(t`Are you sure you want to delete this alternate greeting?`, POPUP_TYPE.CONFIRM);
|
||||
if (!confirm) {
|
||||
return;
|
||||
}
|
||||
|
||||
const array = getArray();
|
||||
array.splice(index, 1);
|
||||
|
||||
// We need to reopen the popup to update the index numbers
|
||||
await popup.complete(POPUP_RESULT.AFFIRMATIVE);
|
||||
openAlternateGreetings();
|
||||
});
|
||||
greetingBlock.find('.move_up_alternate_greeting').on('click', function (event) {
|
||||
handleMoveAlternateGreeting(event, -1);
|
||||
});
|
||||
greetingBlock.find('.move_down_alternate_greeting').on('click', function (event) {
|
||||
handleMoveAlternateGreeting(event, 1);
|
||||
});
|
||||
|
||||
/**
|
||||
* Handles moving an alternate greeting up or down in the list.
|
||||
* @param {JQuery.ClickEvent} event - The click event
|
||||
* @param {number} direction - Direction to move: -1 for up, 1 for down
|
||||
*/
|
||||
function handleMoveAlternateGreeting(event, direction) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const array = getArray();
|
||||
const index = Number(greetingBlock.attr('data-index'));
|
||||
const newIndex = index + direction;
|
||||
|
||||
// Check bounds
|
||||
if (direction === -1 && index <= 0) {
|
||||
return;
|
||||
}
|
||||
if (direction === 1 && index >= array.length - 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Swap the greetings
|
||||
[array[index], array[newIndex]] = [array[newIndex], array[index]];
|
||||
|
||||
// Update current greeting
|
||||
greetingBlock.find('.alternate_greeting_text').val(array[index]);
|
||||
|
||||
// Update adjacent greeting
|
||||
const adjacentGreetingBlock = template.find(`.alternate_greeting[data-index="${newIndex}"]`);
|
||||
adjacentGreetingBlock.find('.alternate_greeting_text').val(array[newIndex]);
|
||||
}
|
||||
|
||||
template.find('.alternate_greetings_list').append(greetingBlock);
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -3464,10 +3464,17 @@ grammarly-extension {
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.alternate_greeting:first-of-type .move_up_alternate_greeting,
|
||||
.alternate_greeting:last-of-type .move_down_alternate_greeting {
|
||||
filter: brightness(75%) grayscale(1);
|
||||
opacity: 0.5;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.alternate_greeting summary {
|
||||
list-style-position: outside;
|
||||
margin-left: 1em;
|
||||
padding-left: 1em;
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.alternate_greeting textarea {
|
||||
|
||||
Reference in New Issue
Block a user