feat: add move up/down functionality for alternate greetings (#4676) * feat: add move up/down functionality for alternate greetings * Remove disabled cursor style

5c62c3a90d44f1692be75433f9277368b7ad7426

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
3 files changed, +68 -9Ignore whitespace
public/index.html+8 -1
@@ -7216,11 +7216,18 @@
7216 <div class="alternate_greeting">7216 <div class="alternate_greeting">
7217 <details open>7217 <details open>
7218 <summary>7218 <summary>
7219 <div class="title_restorable">7219 <div class="title_restorable gap5px">
7220 <div class="flex-container alignItemsCenter">7220 <div class="flex-container alignItemsCenter">
7221 <strong><span data-i18n="Alternate Greeting #">Alternate Greeting #</span><span class="greeting_index"></span></strong>7221 <strong><span data-i18n="Alternate Greeting #">Alternate Greeting #</span><span class="greeting_index"></span></strong>
7222 <i class="editor_maximize fa-solid fa-maximize right_menu_button" title="Expand the editor" data-i18n="[title]Expand the editor"></i>7222 <i class="editor_maximize fa-solid fa-maximize right_menu_button" title="Expand the editor" data-i18n="[title]Expand the editor"></i>
7223 </div>7223 </div>
7224 <span class="expander"></span>
7225 <div class="menu_button menu_button_icon move_up_alternate_greeting" title="Move up" data-i18n="[title]Move up">
7226 <i class="fa-solid fa-chevron-up"></i>
7227 </div>
7228 <div class="menu_button menu_button_icon move_down_alternate_greeting" title="Move down" data-i18n="[title]Move down">
7229 <i class="fa-solid fa-chevron-down"></i>
7230 </div>
7224 <div class="menu_button menu_button_icon delete_alternate_greeting">7231 <div class="menu_button menu_button_icon delete_alternate_greeting">
7225 <i class="fa-solid fa-trash-alt"></i>7232 <i class="fa-solid fa-trash-alt"></i>
7226 <span data-i18n="Delete">Delete</span>7233 <span data-i18n="Delete">Delete</span>
public/script.js+52 -7
@@ -8450,6 +8450,8 @@ function openAlternateGreetings() {
8450 array.push('');8450 array.push('');
8451 addAlternateGreeting(template, '', index, getArray, popup);8451 addAlternateGreeting(template, '', index, getArray, popup);
8452 updateAlternateGreetingsHintVisibility(template);8452 updateAlternateGreetingsHintVisibility(template);
8453 const list = template.find('.alternate_greetings_list');
8454 list.scrollTop(list.prop('scrollHeight'));
8453 });8455 });
84548456
8455 popup.show();8457 popup.show();
@@ -8466,6 +8468,7 @@ function openAlternateGreetings() {
8466 */8468 */
8467function addAlternateGreeting(template, greeting, index, getArray, popup) {8469function addAlternateGreeting(template, greeting, index, getArray, popup) {
8468 const greetingBlock = $('#alternate_greeting_form_template .alternate_greeting').clone();8470 const greetingBlock = $('#alternate_greeting_form_template .alternate_greeting').clone();
8471 greetingBlock.attr('data-index', index);
8469 greetingBlock.find('.alternate_greeting_text')8472 greetingBlock.find('.alternate_greeting_text')
8470 .attr('id', `alternate_greeting_${index}`)8473 .attr('id', `alternate_greeting_${index}`)
8471 .on('input', async function () {8474 .on('input', async function () {
@@ -8479,15 +8482,57 @@ function addAlternateGreeting(template, greeting, index, getArray, popup) {
8479 event.preventDefault();8482 event.preventDefault();
8480 event.stopPropagation();8483 event.stopPropagation();
84818484
8482 if (confirm(t`Are you sure you want to delete this alternate greeting?`)) {8485 const confirm = await callGenericPopup(t`Are you sure you want to delete this alternate greeting?`, POPUP_TYPE.CONFIRM);
8483 const array = getArray();8486 if (!confirm) {
8484 array.splice(index, 1);8487 return;
8485
8486 // We need to reopen the popup to update the index numbers
8487 await popup.complete(POPUP_RESULT.AFFIRMATIVE);
8488 openAlternateGreetings();
8489 }8488 }
8489
8490 const array = getArray();
8491 array.splice(index, 1);
8492
8493 // We need to reopen the popup to update the index numbers
8494 await popup.complete(POPUP_RESULT.AFFIRMATIVE);
8495 openAlternateGreetings();
8490 });8496 });
8497 greetingBlock.find('.move_up_alternate_greeting').on('click', function (event) {
8498 handleMoveAlternateGreeting(event, -1);
8499 });
8500 greetingBlock.find('.move_down_alternate_greeting').on('click', function (event) {
8501 handleMoveAlternateGreeting(event, 1);
8502 });
8503
8504 /**
8505 * Handles moving an alternate greeting up or down in the list.
8506 * @param {JQuery.ClickEvent} event - The click event
8507 * @param {number} direction - Direction to move: -1 for up, 1 for down
8508 */
8509 function handleMoveAlternateGreeting(event, direction) {
8510 event.preventDefault();
8511 event.stopPropagation();
8512
8513 const array = getArray();
8514 const index = Number(greetingBlock.attr('data-index'));
8515 const newIndex = index + direction;
8516
8517 // Check bounds
8518 if (direction === -1 && index <= 0) {
8519 return;
8520 }
8521 if (direction === 1 && index >= array.length - 1) {
8522 return;
8523 }
8524
8525 // Swap the greetings
8526 [array[index], array[newIndex]] = [array[newIndex], array[index]];
8527
8528 // Update current greeting
8529 greetingBlock.find('.alternate_greeting_text').val(array[index]);
8530
8531 // Update adjacent greeting
8532 const adjacentGreetingBlock = template.find(`.alternate_greeting[data-index="${newIndex}"]`);
8533 adjacentGreetingBlock.find('.alternate_greeting_text').val(array[newIndex]);
8534 }
8535
8491 template.find('.alternate_greetings_list').append(greetingBlock);8536 template.find('.alternate_greetings_list').append(greetingBlock);
8492}8537}
84938538
public/style.css+8 -1
@@ -3464,10 +3464,17 @@ grammarly-extension {
3464 padding: 2px;3464 padding: 2px;
3465}3465}
34663466
3467.alternate_greeting:first-of-type .move_up_alternate_greeting,
3468.alternate_greeting:last-of-type .move_down_alternate_greeting {
3469 filter: brightness(75%) grayscale(1);
3470 opacity: 0.5;
3471 pointer-events: none;
3472}
3473
3467.alternate_greeting summary {3474.alternate_greeting summary {
3468 list-style-position: outside;3475 list-style-position: outside;
3469 margin-left: 1em;3476 margin-left: 1em;
3470 padding-left: 1em;3477 padding-left: 5px;
3471}3478}
34723479
3473.alternate_greeting textarea {3480.alternate_greeting textarea {