Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function() {
- var touched=false;
- jQuery(".nav").on('touchstart', 'li .has_children', function (e) { touched=true; });
- jQuery("html").on('mousemove', function (e) { touched=false; });
- jQuery("html").on('click', updatePreviousTouched );
- jQuery(".nav").on('click', 'li .has_children', function (e) {
- updatePreviousTouched(e);
- if( touched ) {
- if (jQuery(this).data('clicked_once')) {
- jQuery(this).data('clicked_once', false);
- return true;
- } else {
- e.preventDefault();
- jQuery(this).trigger("mouseenter");
- jQuery(this).data('clicked_once', true);
- }
- }
- touched=false;
- });
- var previous_touched;
- function updatePreviousTouched(e) {
- if( typeof previous_touched != 'undefined' && previous_touched != null && !previous_touched.is( jQuery(e.target) ) ) {
- previous_touched.data('clicked_once', false);
- }
- previous_touched=jQuery(e.target);
- }
- }
- $(function() {
- var touched = false,
- previous_touched;
- function updatePreviousTouched(e){
- if(typeof previous_touched !== 'undefined' && previous_touched !== null && !previous_touched.is($(e.target))){
- previous_touched.data('clicked_once', false);
- }
- previous_touched = $(e.target);
- }
- $(".nav").on({
- touchstart:function(e) {
- touched=true;
- },
- click:function(e);
- var $this = $(this);
- updatePreviousTouched(e);
- if(touched) {
- if ($this.data('clicked_once')) {
- $this.data('clicked_once', false);
- return true;
- } else {
- e.preventDefault();
- $this.trigger("mouseenter").data('clicked_once', true);
- }
- }
- touched = false;
- }
- },'li .has_children');
- $("html").on({
- mousemove:function(e){
- touched=false;
- },
- click:updatePreviousTouched
- });
- });
- .header-nav-menu ul li:hover > ul { display: inline-block; }
- .header-nav-menu ul li > ul.MenuActive { display: inline-block; }
- $(function(){
- var menuActive = false,
- touched = false,
- $nav = $('.nav');
- function removeActive(callback){
- $nav.find('.MenuActive').removeClass('MenuActive');
- callback();
- }
- function newActive($this,menu){
- removeActive(function(){
- $this.next().addClass('MenuActive').queue(function(){
- if(menu){
- menuActive = true;
- touched = false;
- } else {
- touched = true;
- }
- }).dequeue();
- });
- }
- $nav.on({
- touchstart:function(e){
- e.stopPropagation();
- newActive($(this),touched);
- },
- mouseenter:function(){
- newActive($(this),true);
- },
- click:function(e){
- e.preventDefault();
- if(menuActive){
- $(this).trigger('trueClick',e.target);
- }
- },
- trueClick:function(e,$target){
- $(this).parents('.nav').trigger('mouseleave');
- window.location.href = $target;
- }
- },'li .has_children').on('mouseleave',function(){
- removeActive(function(){
- menuActive = false;
- touched = false;
- });
- });
- $('html').on('touchstart',function(e){
- if(menuActive){
- $nav.trigger('mouseleave');
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement