Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. jQuery(document).ready(function() {
  2. var touched=false;
  3. jQuery(".nav").on('touchstart', 'li .has_children', function (e) { touched=true; });
  4. jQuery("html").on('mousemove', function (e) { touched=false; });
  5.  
  6. jQuery("html").on('click', updatePreviousTouched );
  7.  
  8. jQuery(".nav").on('click', 'li .has_children', function (e) {
  9. updatePreviousTouched(e);
  10. if( touched ) {
  11. if (jQuery(this).data('clicked_once')) {
  12. jQuery(this).data('clicked_once', false);
  13. return true;
  14. } else {
  15. e.preventDefault();
  16. jQuery(this).trigger("mouseenter");
  17. jQuery(this).data('clicked_once', true);
  18.  
  19. }
  20. }
  21. touched=false;
  22. });
  23.  
  24. var previous_touched;
  25. function updatePreviousTouched(e) {
  26. if( typeof previous_touched != 'undefined' && previous_touched != null && !previous_touched.is( jQuery(e.target) ) ) {
  27. previous_touched.data('clicked_once', false);
  28. }
  29. previous_touched=jQuery(e.target);
  30. }
  31. }
  32.  
  33. $(function() {
  34. var touched = false,
  35. previous_touched;
  36.  
  37. function updatePreviousTouched(e){
  38. if(typeof previous_touched !== 'undefined' && previous_touched !== null && !previous_touched.is($(e.target))){
  39. previous_touched.data('clicked_once', false);
  40. }
  41.  
  42. previous_touched = $(e.target);
  43. }
  44.  
  45. $(".nav").on({
  46. touchstart:function(e) {
  47. touched=true;
  48. },
  49. click:function(e);
  50. var $this = $(this);
  51.  
  52. updatePreviousTouched(e);
  53.  
  54. if(touched) {
  55. if ($this.data('clicked_once')) {
  56. $this.data('clicked_once', false);
  57. return true;
  58. } else {
  59. e.preventDefault();
  60. $this.trigger("mouseenter").data('clicked_once', true);
  61. }
  62. }
  63.  
  64. touched = false;
  65. }
  66. },'li .has_children');
  67.  
  68. $("html").on({
  69. mousemove:function(e){
  70. touched=false;
  71. },
  72. click:updatePreviousTouched
  73. });
  74. });
  75.  
  76. .header-nav-menu ul li:hover > ul { display: inline-block; }
  77.  
  78. .header-nav-menu ul li > ul.MenuActive { display: inline-block; }
  79.  
  80. $(function(){
  81. var menuActive = false,
  82. touched = false,
  83. $nav = $('.nav');
  84.  
  85. function removeActive(callback){
  86. $nav.find('.MenuActive').removeClass('MenuActive');
  87. callback();
  88. }
  89.  
  90. function newActive($this,menu){
  91. removeActive(function(){
  92. $this.next().addClass('MenuActive').queue(function(){
  93. if(menu){
  94. menuActive = true;
  95. touched = false;
  96. } else {
  97. touched = true;
  98. }
  99. }).dequeue();
  100. });
  101. }
  102.  
  103. $nav.on({
  104. touchstart:function(e){
  105. e.stopPropagation();
  106. newActive($(this),touched);
  107. },
  108. mouseenter:function(){
  109. newActive($(this),true);
  110. },
  111. click:function(e){
  112. e.preventDefault();
  113.  
  114. if(menuActive){
  115. $(this).trigger('trueClick',e.target);
  116. }
  117. },
  118. trueClick:function(e,$target){
  119. $(this).parents('.nav').trigger('mouseleave');
  120. window.location.href = $target;
  121. }
  122. },'li .has_children').on('mouseleave',function(){
  123. removeActive(function(){
  124. menuActive = false;
  125. touched = false;
  126. });
  127. });
  128.  
  129. $('html').on('touchstart',function(e){
  130. if(menuActive){
  131. $nav.trigger('mouseleave');
  132. }
  133. });
  134. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement