| | 742 | $( window ).on( 'touchstart.wp-responsive', function( e ) { |
| | 743 | var touches = e.originalEvent.touches, |
| | 744 | touch, |
| | 745 | winWidth = Math.max( window.innerWidth, document.documentElement.clientWidth ); |
| | 746 | |
| | 747 | // if it's multi touch bail |
| | 748 | if ( 1 !== touches.length ) { |
| | 749 | return; |
| | 750 | } |
| | 751 | |
| | 752 | touch = touches[0]; |
| | 753 | |
| | 754 | // if the menu is open and we're starting from the |
| | 755 | // outside it start closing the menu |
| | 756 | if ( wpTouchMenu.open && ! $( e.target ).closest( '#adminmenu' ).length ) { |
| | 757 | wpTouchMenu.started = true; |
| | 758 | wpTouchMenu.startPosition = touch.screenX; |
| | 759 | return; |
| | 760 | } |
| | 761 | |
| | 762 | // if it's within the left 20% of the screen |
| | 763 | // note that it has started |
| | 764 | if ( |
| | 765 | ( ! wpTouchMenu.rtl && touch.screenX <= ( winWidth * 0.2 ) ) || |
| | 766 | ( wpTouchMenu.rtl && ( winWidth - ( winWidth * 0.2 ) ) <= touch.screenX ) |
| | 767 | ) { |
| | 768 | wpTouchMenu.started = true; |
| | 769 | wpTouchMenu.startPosition = touch.screenX; |
| | 770 | } |
| | 771 | } ); |
| | 772 | |
| | 773 | $( window ).on( 'touchmove.wp-responsive', function( e ) { |
| | 774 | var touches, touch; |
| | 775 | // if it didn't qualify for potential menu |
| | 776 | // open bail |
| | 777 | if ( ! wpTouchMenu.started ) { |
| | 778 | return; |
| | 779 | } |
| | 780 | |
| | 781 | touches = e.originalEvent.changedTouches; |
| | 782 | |
| | 783 | // no multitouch |
| | 784 | if ( 1 !== touches.length ) { |
| | 785 | return; |
| | 786 | } |
| | 787 | |
| | 788 | // stop back action |
| | 789 | e.preventDefault(); |
| | 790 | |
| | 791 | touch = touches[0]; |
| | 792 | |
| | 793 | // cancel open if we're not going in the right direction |
| | 794 | if ( |
| | 795 | ( ! wpTouchMenu.rtl && ! wpTouchMenu.open && touch.screenX <= wpTouchMenu.startPosition ) || |
| | 796 | ( ! wpTouchMenu.rtl && wpTouchMenu.open && wpTouchMenu.startPosition <= touch.screenX ) || |
| | 797 | ( wpTouchMenu.rtl && ! wpTouchMenu.open && wpTouchMenu.startPosition <= touch.screenX ) || |
| | 798 | ( wpTouchMenu.rtl && wpTouchMenu.open && touch.screenX <= wpTouchMenu.startPosition ) |
| | 799 | ) { |
| | 800 | wpTouchMenu.started = false; |
| | 801 | wpTouchMenu.startPosition = 0; |
| | 802 | return; |
| | 803 | } |
| | 804 | |
| | 805 | wpTouchMenu.tracking = true; |
| | 806 | } ); |
| | 807 | |
| | 808 | $( window ).on( 'touchend.wp-responsive', function( e ) { |
| | 809 | var touches = e.originalEvent.changedTouches, |
| | 810 | touch, |
| | 811 | winWidth = Math.max( window.innerWidth, document.documentElement.clientWidth ), |
| | 812 | moved = 0; |
| | 813 | |
| | 814 | // only process if we're tracking |
| | 815 | if ( ! wpTouchMenu.tracking ) { |
| | 816 | return; |
| | 817 | } |
| | 818 | |
| | 819 | // no multitouch |
| | 820 | if ( 1 !== touches.length ) { |
| | 821 | wpTouchMenu.started = false; |
| | 822 | wpTouchMenu.startPosition = 0; |
| | 823 | wpTouchMenu.tracking = false; |
| | 824 | return; |
| | 825 | } |
| | 826 | |
| | 827 | touch = touches[0]; |
| | 828 | // calculate how far we've moved |
| | 829 | if ( wpTouchMenu.rtl ) { |
| | 830 | if ( wpTouchMenu.open ) { |
| | 831 | moved = touch.screenX - wpTouchMenu.startPosition; |
| | 832 | } else { |
| | 833 | moved = wpTouchMenu.startPosition - touch.screenX; |
| | 834 | } |
| | 835 | } else { |
| | 836 | if ( wpTouchMenu.open ) { |
| | 837 | moved = wpTouchMenu.startPosition - touch.screenX; |
| | 838 | } else { |
| | 839 | moved = touch.screenX - wpTouchMenu.startPosition; |
| | 840 | } |
| | 841 | } |
| | 842 | |
| | 843 | // if it's 20% or more trigger the menu |
| | 844 | if ( ( winWidth * 0.2 ) <= moved ) { |
| | 845 | $( '#wp-admin-bar-menu-toggle' ).trigger( 'click' ); |
| | 846 | } |
| | 847 | |
| | 848 | // reset our values |
| | 849 | wpTouchMenu.started = false; |
| | 850 | wpTouchMenu.startPosition = 0; |
| | 851 | wpTouchMenu.tracking = false; |
| | 852 | } ); |
| | 853 | |