Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. var isTouch = testTouch();
  2. var lastElement;
  3.  
  4. $(document).ready( function() {
  5.  
  6. if( isTouch ) {
  7. $('[role="navigation"] li a').on( 'touchstart', function(e) {
  8. e.stopPropagation();
  9.  
  10. var item = $($(this).parents('li')[0]);
  11.  
  12. if( item.children( 'ul' ).length ) {
  13.  
  14. if( !lastElement ) {
  15. lastElement = this;
  16. $( '[role="navigation"] ul ul' ).each( function( i, e ) {
  17. if( $(e).css( 'display' ) == 'block' ){
  18. $(e).css( 'display', 'none' );
  19. }
  20. })
  21. $(this).parent().next('ul').show();
  22. return false;
  23. }
  24. else {
  25. if( lastElement === this ) {
  26. window.location.href = $(this).attr( 'href' );
  27. return true;
  28. }
  29. else {
  30. $( '[role="navigation"] ul ul' ).each( function( i, e ) {
  31. if( $(e).css( 'display' ) == 'block' ){
  32. $(e).css( 'display', 'none' );
  33. }
  34. });
  35. $(this).parent().next('ul').show();
  36. return false;
  37. }
  38. }
  39. }
  40. window.location.href = $(this).attr( 'href' );
  41. return true;
  42. });
  43.  
  44.  
  45. $('[role="navigation"] li a').on( 'click', function(e) {
  46. e.stopPropagation();
  47. debugger;
  48.  
  49. var item = $($(this).parents('li')[0]);
  50.  
  51. if( item.children( 'ul' ).length ) {
  52.  
  53. if( lastElement === this ) {
  54. lastElement = null;
  55. return false;
  56. }
  57. }
  58.  
  59. return false;
  60. });
  61. }
  62.  
  63. });
  64.  
  65.  
  66. function testTouch() {
  67. if( ( 'ontouchstart' in window ) || window.touchEvent || window.DocumentTouch && document instanceof DocumentTouch ) {
  68. return true;
  69. }
  70. return false;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement