Make WordPress Core

Changeset 31720


Ignore:
Timestamp:
03/11/2015 04:28:21 PM (11 years ago)
Author:
azaozz
Message:

Allow swiping of the admin menu on touch devices.
Props iseulde, ninnypants. See #31187.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/common.js

    r31674 r31720  
    713713        window.wpResponsive = {
    714714                init: function() {
    715                         var self = this;
     715                        var self = this,
     716                                x, y;
    716717
    717718                        // Modify functionality based on custom activate/deactivate event
     
    728729                                event.preventDefault();
    729730                                $wpwrap.toggleClass( 'wp-responsive-open' );
    730                                 if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) {
     731                                if ( self.isOpen() ) {
    731732                                        $(this).find('a').attr( 'aria-expanded', 'true' );
    732733                                        $( '#adminmenu a:first' ).focus();
     
    736737                        } );
    737738
     739                        $window.on( 'touchstart.wp-responsive', function( event ) {
     740                                var touches = event.originalEvent.touches;
     741
     742                                if ( 1 !== touches.length ) {
     743                                        return;
     744                                }
     745
     746                                x = touches[0].clientX;
     747                                y = touches[0].clientY;
     748                        } );
     749
     750                        $window.on( 'touchend.wp-responsive', function( event ) {
     751                                var touches = event.originalEvent.changedTouches,
     752                                        isOpen = self.isOpen(),
     753                                        distanceX;
     754
     755                                if ( 1 === touches.length && x && y ) {
     756                                        if ( ( window.isRtl && isOpen ) || ( ! window.isRtl && ! isOpen ) ) {
     757                                                distanceX = touches[0].clientX - x;
     758                                        } else {
     759                                                distanceX = x - touches[0].clientX;
     760                                        }
     761
     762                                        if ( distanceX > 30 && distanceX > Math.abs( touches[0].clientY - y ) ) {
     763                                                $( '#wp-admin-bar-menu-toggle' ).trigger( 'click' );
     764                                        }
     765                                }
     766
     767                                x = y = 0;
     768                        } );
     769
    738770                        // Add menu events
    739771                        $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
     
    757789                                }
    758790                        });
     791                },
     792
     793                isOpen: function() {
     794                        return $wpwrap.hasClass( 'wp-responsive-open' );
    759795                },
    760796
Note: See TracChangeset for help on using the changeset viewer.