Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var isTouch = testTouch();
- var lastElement;
- $(document).ready( function() {
- if( isTouch ) {
- $('[role="navigation"] li a').on( 'touchstart', function(e) {
- e.stopPropagation();
- var item = $($(this).parents('li')[0]);
- if( item.children( 'ul' ).length ) {
- if( !lastElement ) {
- lastElement = this;
- $( '[role="navigation"] ul ul' ).each( function( i, e ) {
- if( $(e).css( 'display' ) == 'block' ){
- $(e).css( 'display', 'none' );
- }
- })
- $(this).parent().next('ul').show();
- return false;
- }
- else {
- if( lastElement === this ) {
- window.location.href = $(this).attr( 'href' );
- return true;
- }
- else {
- $( '[role="navigation"] ul ul' ).each( function( i, e ) {
- if( $(e).css( 'display' ) == 'block' ){
- $(e).css( 'display', 'none' );
- }
- });
- $(this).parent().next('ul').show();
- return false;
- }
- }
- }
- window.location.href = $(this).attr( 'href' );
- return true;
- });
- $('[role="navigation"] li a').on( 'click', function(e) {
- e.stopPropagation();
- debugger;
- var item = $($(this).parents('li')[0]);
- if( item.children( 'ul' ).length ) {
- if( lastElement === this ) {
- lastElement = null;
- return false;
- }
- }
- return false;
- });
- }
- });
- function testTouch() {
- if( ( 'ontouchstart' in window ) || window.touchEvent || window.DocumentTouch && document instanceof DocumentTouch ) {
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement