samedi 25 avril 2015

Workaround for a premature touchcancel event

I'm trying to modify a jquery code for a website-based dropdown menu for a workaround of a premature touchcancel event being fired on 4.4.2 build samsung galaxy s4.

Here's the code I'm trying to work with:

jQuery(document).ready(function ($) {
'use strict';
    $('.taptap-by-bonfire ul li ul').before($('<span><svg version="1.1" xmlns="http://ift.tt/nvqhV5" xmlns:xlink="http://ift.tt/PGV9lw" viewBox="0 0 512 512" xml:space="preserve"><polygon id="arrow-24-icon" points="206.422,462 134.559,390.477 268.395,256 134.559,121.521 206.422,50 411.441,256 "/></svg></span>'));

    $(".menu > li > span, .sub-menu > li > span").on('touchstart click', function(e) {
    e.preventDefault();
        if (false == $(this).next().is(':visible')) {
            $(this).parent().siblings().find(".sub-menu").slideUp(300);
            $(this).siblings().find(".sub-menu").slideUp(300);
            $(this).parent().siblings().find("span").removeClass("taptap-submenu-active");
        }
        $(this).next().slideToggle(300);
        $(this).toggleClass("taptap-submenu-active");
    })  


    $(".menu > li > span").on('touchstart click', function(e) {
    e.preventDefault();
        if($(".sub-menu > li > span").hasClass('taptap-submenu-active'))
            {
                $(".sub-menu > li > span").removeClass("taptap-submenu-active");
            }
    })

    $(".taptap-menu-button-wrapper").on('touchstart click', function(e) {
        if($(".menu > li > span, .sub-menu > li > span").hasClass('taptap-submenu-active'))
            {
                $(".menu > li").find(".sub-menu").slideUp(300);
                $(".menu > li > span, .sub-menu > li > span").removeClass("taptap-submenu-active");
            }
    })

});

It works well on most devices and on most browsers, however, on that device and default android browser, the menu dropsdown and quickly slides up again, and I'm assuming a premature touchcancel event is being fired. I've tried various things, but I can't seem to have all these elements and not have a touchcancel firing up on that device no matter what I try.

Is there anything I can do to get around this issue with the android browser?




Aucun commentaire:

Enregistrer un commentaire