Make WordPress Core

Changeset 58946


Ignore:
Timestamp:
08/28/2024 04:43:52 PM (4 months ago)
Author:
joedolson
Message:

Media: Fix viewport scrolling and code style in image rotation.

Change browsePopup to use onkeydown, pass the event parameter from the calling control, and adjust variable naming style.

The browsePopup method used for the image rotation menu used onkeyup to trigger events, which prevented capturing browser scroll actions with arrows occurring on onkeydown.

Props afercia, deepakvijayan, nirajgirixd, joedolson, antpb.
Fixes #60548.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/image-edit.js

    r58915 r58946  
    297297     *
    298298     * @since 6.3.0
    299      *
    300      * @memberof imageEdit
    301      *
     299     * @since 6.7.0 Added the event parameter.
     300     *
     301     * @memberof imageEdit
     302     *
     303     * @param {Event} event The key or click event.
    302304     * @param {HTMLElement} el The current element.
    303305     *
    304306     * @return {boolean} Always returns false.
    305307     */
    306     browsePopup : function(el) {
     308    browsePopup : function(event, el) {
    307309        var $el = $( el );
    308310        var $collection = $( el ).parent( '.imgedit-popup-menu' ).find( 'button' );
     
    317319            $next = 0;
    318320        }
    319         var $target = false;
     321        var target = false;
    320322        if ( event.keyCode === 40 ) {
    321             $target = $collection.get( $next );
     323            target = $collection.get( $next );
    322324        } else if ( event.keyCode === 38 ) {
    323             $target = $collection.get( $prev );
    324         }
    325         if ( $target ) {
    326             $target.focus();
     325            target = $collection.get( $prev );
     326        }
     327        if ( target ) {
     328            target.focus();
    327329            event.preventDefault();
    328330        }
  • trunk/src/wp-admin/includes/image-edit.php

    r58915 r58946  
    7676                $note_no_rotate = '';
    7777                ?>
    78                     <button type="button" class="imgedit-rleft button" onkeyup="imageEdit.browsePopup(this)" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90&deg; left' ); ?></button>
    79                     <button type="button" class="imgedit-rright button" onkeyup="imageEdit.browsePopup(this)" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90&deg; right' ); ?></button>
    80                     <button type="button" class="imgedit-rfull button" onkeyup="imageEdit.browsePopup(this)" onclick="imageEdit.rotate(180, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 180&deg;' ); ?></button>
     78                    <button type="button" class="imgedit-rleft button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90&deg; left' ); ?></button>
     79                    <button type="button" class="imgedit-rright button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90&deg; right' ); ?></button>
     80                    <button type="button" class="imgedit-rfull button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate(180, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 180&deg;' ); ?></button>
    8181                <?php
    8282            } else {
     
    8989            ?>
    9090                    <hr />
    91                     <button type="button" onkeyup="imageEdit.browsePopup(this)" onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()" class="imgedit-flipv button"><?php esc_html_e( 'Flip vertical' ); ?></button>
    92                     <button type="button" onkeyup="imageEdit.browsePopup(this)" onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()" class="imgedit-fliph button"><?php esc_html_e( 'Flip horizontal' ); ?></button>
     91                    <button type="button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()" class="imgedit-flipv button"><?php esc_html_e( 'Flip vertical' ); ?></button>
     92                    <button type="button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()" class="imgedit-fliph button"><?php esc_html_e( 'Flip horizontal' ); ?></button>
    9393                    <?php echo $note_no_rotate; ?>
    9494                </div>
Note: See TracChangeset for help on using the changeset viewer.