Allow swiping of the admin menu on touch devices.

Props iseulde, ninnypants. See #31187.
Built from https://develop.svn.wordpress.org/trunk@31720


git-svn-id: http://core.svn.wordpress.org/trunk@31701 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-03-11 16:29:26 +00:00
parent e5a7fc36d8
commit 4eba346517
3 changed files with 40 additions and 4 deletions

View File

@ -712,7 +712,8 @@ $(document).ready( function() {
window.wpResponsive = { window.wpResponsive = {
init: function() { init: function() {
var self = this; var self = this,
x, y;
// Modify functionality based on custom activate/deactivate event // Modify functionality based on custom activate/deactivate event
$document.on( 'wp-responsive-activate.wp-responsive', function() { $document.on( 'wp-responsive-activate.wp-responsive', function() {
@ -727,7 +728,7 @@ $(document).ready( function() {
$( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) { $( '#wp-admin-bar-menu-toggle' ).on( 'click.wp-responsive', function( event ) {
event.preventDefault(); event.preventDefault();
$wpwrap.toggleClass( 'wp-responsive-open' ); $wpwrap.toggleClass( 'wp-responsive-open' );
if ( $wpwrap.hasClass( 'wp-responsive-open' ) ) { if ( self.isOpen() ) {
$(this).find('a').attr( 'aria-expanded', 'true' ); $(this).find('a').attr( 'aria-expanded', 'true' );
$( '#adminmenu a:first' ).focus(); $( '#adminmenu a:first' ).focus();
} else { } else {
@ -735,6 +736,37 @@ $(document).ready( function() {
} }
} ); } );
$window.on( 'touchstart.wp-responsive', function( event ) {
var touches = event.originalEvent.touches;
if ( 1 !== touches.length ) {
return;
}
x = touches[0].clientX;
y = touches[0].clientY;
} );
$window.on( 'touchend.wp-responsive', function( event ) {
var touches = event.originalEvent.changedTouches,
isOpen = self.isOpen(),
distanceX;
if ( 1 === touches.length && x && y ) {
if ( ( window.isRtl && isOpen ) || ( ! window.isRtl && ! isOpen ) ) {
distanceX = touches[0].clientX - x;
} else {
distanceX = x - touches[0].clientX;
}
if ( distanceX > 30 && distanceX > Math.abs( touches[0].clientY - y ) ) {
$( '#wp-admin-bar-menu-toggle' ).trigger( 'click' );
}
}
x = y = 0;
} );
// Add menu events // Add menu events
$adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) { $adminmenu.on( 'click.wp-responsive', 'li.wp-has-submenu > a', function( event ) {
if ( ! $adminmenu.data('wp-responsive') ) { if ( ! $adminmenu.data('wp-responsive') ) {
@ -758,6 +790,10 @@ $(document).ready( function() {
}); });
}, },
isOpen: function() {
return $wpwrap.hasClass( 'wp-responsive-open' );
},
activate: function() { activate: function() {
setPinMenu(); setPinMenu();

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.2-alpha-31719'; $wp_version = '4.2-alpha-31720';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.