watusi / jquery-mobile-iscrollview

JQuery Mobile widget plug-in for easy use of the iScroll javascript scroller.
407 stars 183 forks source link

Android: click event issue #96

Open ehretf opened 11 years ago

ehretf commented 11 years ago

Hello,

Thanks a lot for this widget it is very usefull and working great, except for one thing. I'm using it on Android (official relaese on Google Nexus 4).

The issue concern the click event which is fired twice when javascript scripts related to the widget are loaded (no issue when I remove them).

I have made a little change to the exemple html file you provide with your library:

<!DOCTYPE html>

iscrollview Demo ```

List

TOTO

  • Item 1
  • Item 1
  • Item 1
  • Item 1
  • Item 1
  • ```

    When using this file with phonegap on Android, cliking on the collapsible listview rise two event and make the listview expands and collapses immediatly.

    This list act normally when removing iscroll related javascript.

    My tests revealed that using bind() cause two click event to be fired while jquery.on() give a normal single/unique click event. Jquery docs warn that bind() is deprecated since Jquery 1.7. Hope this give help on the present bug.

    Thanks a lot for your help

    Florent

    ehretf commented 11 years ago

    In addition, when including iscroll.js only, click event are working normally, the issue come when including jquery.mobile.iscrollview.js.

    Also, setting bindIscrollUsingJqueryEvents to true solve the issue but the scrolling is not working (I saw in the doc that this setting is experimental ...)

    jtara commented 11 years ago

    Hmm, don't know why there would be a difference between .bind() and .on().

    The reason I don't use .on() is that I mean to keep this compatible with jQuery Mobile from version 1.0. And JQM 1.0 is usable with jQuery 1.6.4, which doesn't have .on() at all.

    In jQuery 1.9.1, .live() is removed, but I don't use '.live() anywhere.

    "Deprecated" means it will be removed in some future version. So, when '.bind() is actually removed, I will have to face that issue, I suppose with some conditional code that tests the jQuery version.

    I do intend to add a PhoneGap (as well as Rhodes) demo in the near future. At that time, I'll take a look at this.

    ehretf commented 11 years ago

    Hi,

    Thank you for your response. Yo uare right there is not difference from bind to on. I have worked to fix this issue (sorry I didn't take the time to update this case).

    This issue is in fact due to the Android's default browser which is used by Phonegap. Chrome in Android acts normally (I didn't test in other browser).

    This issue is related to iscroll.js and I have raised an issue and also propose a workaround.

    It make iscroll depending of jquery which is not acceptable for iscroll team (I totally agree) but can be interesting intersting in your case (as you script target jquery mobile + iscroll user) or for other users:

    https://github.com/cubiq/iscroll/issues/361#issuecomment-17652950

    Thanks a lot

    Best Regards

    Florent

    davidpfahler commented 11 years ago

    Has anyone tried v5 and looked if the issue is fixed there? Thanks for your contributions.

    Hexodus commented 11 years ago

    UPDATE Warning! This doubleclick fix stopped to work on android 6+ and newer browsers. It prevents all click no matter if double or single clicks. Didn't figured out yet why.

    I'm using this fix to avoid the double click behavior on android. Should be loaded before iscroll.js

    //-------------------------------------------------------------------------------------------------------------- // // Doubleclick fix for Androids 4.2x where a single tap results // in a double tap | click // Solution found here: // http://stackoverflow.com/questions/14982864/phonegap-2-4-0-with-android-4-2-strange-double-click-behaviour // //--------------------------------------------------------------------------------------------------------------

    last_click_time = new Date().getTime(); document.addEventListener('click', function (e) { click_time = e['timeStamp']; if (click_time && (click_time - last_click_time) < 500) { e.stopImmediatePropagation(); e.preventDefault(); return false; } last_click_time = click_time; }, true);

    tripexito commented 10 years ago

    @Hexodus thanks for the code, it works like a charm! ;) I'm using JQM v1.4.0, iScroll v4.2 and Phonegap v3.4.0 Greetings!

    Hexodus commented 8 years ago

    @tripexito Please read my up update and the warning about this fix which started to cause much trouble in newer browsers.