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

jQuery event bindings crash on touch devices (patch) #127

Open
alebedev opened this issue Oct 22, 2013 · 2 comments
Open

jQuery event bindings crash on touch devices (patch) #127

alebedev opened this issue Oct 22, 2013 · 2 comments

Comments

@alebedev
Copy link

Option to bind events via jQuery is great and significantly simplifies customizing iscroll behavior. There's, however, crash bug on touch devices caused by lack of TouchEvent attributes on jQuery events.

I fixed this by making change from patch below. Please consider including it into default implementation.

--- a/client/src/js/libs/jquery.mobile.iscrollview.js   Tue Oct 22 13:52:21 2013 +0400
+++ b/client/src/js/libs/jquery.mobile.iscrollview.js   Tue Oct 22 14:19:14 2013 +0400
@@ -236,6 +236,12 @@
       var jqEvents = this.iscrollview.options.bindIscrollUsingJqueryEvents,
           then;
       then = this.iscrollview._logIscrollEvent("iScroll.handleEvent", e);
+      // Copy touches to jQuery event
+      if (jqEvents) {
+        e.touches = e.originalEvent.touches;
+        e.changedTouches = e.originalEvent.changedTouches;
+        e.targetTouches = e.originalEvent.targetTouches;
+      }
       // If jQuery mouseleave, make iScroll think we are handling a mouseout event
       if (jqEvents && e.type === "mouseleave") {
         e.type = "mouseout";
@alebedev
Copy link
Author

Small fix for attached code, in cases when originalEvent is undefined:

      // Copy touches to jQuery event
      if (jqEvents) {
        if (e.originalEvent) {
          e.touches = e.originalEvent.touches;
          e.changedTouches = e.originalEvent.changedTouches;
          e.targetTouches = e.originalEvent.targetTouches;
        } else {
          e.touches = e.changedTouches = e.targetTouches = [];
        }
      }

@jtara
Copy link
Member

jtara commented Oct 23, 2013

Thank you - jQuery event binding is an experimental feature, and not enabled by default because I know it has bugs. I wanted to leave the code in so that people could experiment and fix the bugs, so it seems that worked. ;)

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

2 participants