Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.1.1 Perfect. 1.2.1 Broken in android #144

Closed
kiddac opened this issue Feb 28, 2014 · 6 comments
Closed

1.1.1 Perfect. 1.2.1 Broken in android #144

kiddac opened this issue Feb 28, 2014 · 6 comments

Comments

@kiddac
Copy link

kiddac commented Feb 28, 2014

Having used sidr(1.1.1) on a previous project and working fine on all devices tested, IE, Chrome, firefox, safai, opera, io6, iphone 4, android 2.3, android 4.2 I came across problems when I tried to use it for a second project.

The newest version 1.2.1 and also the sidr-master files just didn't work like the old one. Fine on the desktop, unusable on my Android (4.2.2).

The problem is the side menu is used to link to anchor tags in my one page website. I therefore have the following code to close the sidr menu on a click.

$(window).resize(function(){
$.sidr('close', 'sidr-main');
});

$(document).click(function () {
$.sidr('close', 'sidr-main');
});

Now the problem I was having is if I click on the menu icon, the sidr menu opens and then closes straight away. For some reason it is registering a click on the top item of my list.

i.e if my top item is "about" it is closing the menu and jumping straight to the about section with out me clicking on anything.

After pulling my hair out for hours changing my code, disabling all other script calls etc etc, I decided to try the old version 1.1.1. And all is working perfectly again.

Therefore, is this something that has been modified in version 1.2.1 or is it an android bug that is auto selecting this top item.

@chennecke
Copy link

I can confirm this problem. In my case also the second menu item can be "auto-selected" since the menu item height is smaller than the height of the menu button.

@wolf128058
Copy link

I can confirm this problem, too.
Feels strange, because in the moment I click the menu-toggle the link cannot be reached (is disabled by "display: none")

@godsdog
Copy link

godsdog commented May 13, 2014

Have the same problem! On iOS it is working fine on Android the bug occurs! Hope there is coming a fix... Maybe it has something to do with: ontouchstart ?!

// Edit
This code is wrong for android:

if('ontouchstart' in document.documentElement) {
$this.bind('touchstart', function(e) {
var theEvent = e.originalEvent.touches[0];
this.touched = e.timeStamp;
});
$this.bind('touchend', function(e) {
var delta = Math.abs(e.timeStamp - this.touched);
if(delta < 200) {
e.preventDefault();
methods.toggle(name);
}
});

FIX:
I inserted the following (no touch event support anymore):

if('ontouchstart' in document.documentElement) {

     $this.click(function(e) {
            e.preventDefault();
            methods.toggle(name);
          });
        }
        else {
          $this.click(function(e) {
            e.preventDefault();
            methods.toggle(name);
          });

It is also possible to drop the hole if statement. Should be fixed in a better way. But this is now working in Android and iOS.

@adamobrien1882
Copy link

This issue was causing me some grief also, I fixed it by using the callbacks to hide and show the menu

$('#responsive-menu-button').sidr({
    name: 'sidr-main',
    source: '.menu',
    onOpen: function() {
        // Enable menu after 0.5secs
        $('#sidr-main .sidr-inner').delay(500).show('fast');
    },
    onClose: function() {
        // disable menu
        $('#sidr-main .sidr-inner').hide();
    }
});

and hiding the menu in the css to start with

#sidr .sidr-inner {
    display: none;
}

@raphael-m
Copy link

I can confirm that removing the condition checking for ontouchstart solves the problem in Android. I did not see any side effects.

Instead of

if('ontouchstart' in document.documentElement) {
    $this.bind('touchstart', function(e) {
        var theEvent = e.originalEvent.touches[0];
        this.touched = e.timeStamp;
    });
    $this.bind('touchend', function(e) {
        var delta = Math.abs(e.timeStamp - this.touched);
        if(delta < 200) {
            e.preventDefault();
            methods.toggle(name);
        }
    });
}
else {
    $this.click(function(e) {
        e.preventDefault();
        methods.toggle(name);
    });
}

Use

$this.click(function(e) {
    e.preventDefault();
    methods.toggle(name);
});

What is the purpose of this condition?

raphael-m added a commit to raphael-m/sidr that referenced this issue Jan 20, 2015
The sidr menu does not work correctly on Android standard browser (4.2.x). We removed the `ontouchstart` condition, which delays the menu a bit, but should work as expected in all browsers.
More: artberri#144
artberri added a commit that referenced this issue Jan 9, 2016
…ixes #179 and fixes #266 and fixes #246 and fixes #245 and fixes #211 and fixes #178 and fixes #118 and fixes #98  and fixes #214 and fixes #117 and fixes #130 and fixes #144 and fixes #146 and fixes #165 and fixes #189 and fixes #193 and fixes #203 and fixes #213 and fixes #218 and fixes #240 and fixes #249
@artberri
Copy link
Owner

artberri commented Jan 9, 2016

Preparing a new version with a fix for this https://github.com/artberri/sidr/tree/reborn

@artberri artberri closed this as completed Jan 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants