Skip to content
This repository has been archived by the owner on Aug 1, 2020. It is now read-only.

IE event fix #394

Closed
wants to merge 2 commits into from
Closed

IE event fix #394

wants to merge 2 commits into from

Conversation

fizk
Copy link

@fizk fizk commented Jul 20, 2015

For what ever reason, IE=<10 did not provide it's events with pageX and pageY values. 'Cause of this. This plugin did not work in IE=<10.

This PR fixes this. It will first try to use event.originalEvent, but fall back on event if required.

This is what I did to come to this conclusion:

I found a real computer with real IE10.

I ran your demo (http://fengyuanchen.github.io/cropper/). It did not work.

Then I cloned your repo, created an index.html page and added this:

<!doctype html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
        <link  href="/dist/cropper.css" rel="stylesheet">
        <script src="/dist/cropper.js"></script>
    </head>
    <body>

        <div class="container">
            <img src="/picture.png">
        </div>

        <script type="text/javascript">

            $('.container > img').cropper({
              aspectRatio: 16 / 9,
              crop: function(data) {
                // Output the result data for cropping image.
              }
            });

        </script>
    </body>
</html>

Next I tried it with jQuery v1.9.1, v1.11.3 and v2.1.4. It did not work.

Then I hopped into the debugger to see what was going on.

This is the stack for onDragStart. As you can see, startX and startY is undefined, 'cause e has no pageX and pageY.

before

Next I changed e.pageX to originalEvent.pageX and e.pageY to originalEvent.pageY and added a breakpoint on the same line.

Now everything worked. this has its startX and startY values set.

after

I don't know why this happens and why e does not have it's pageXand pageY properties set.

I was wondering if IE is using its global event object and not the argument passed to the function here:

dragmove: function (event) {
      var options = this.options,
          originalEvent = event.originalEvent,
          touches = originalEvent && originalEvent.touches,
          e = event, //< ---- here
          dragType = this.dragType,
          dragMoveEvent,
          touchesLength;

anyways... by using the original event, I can get this to work.

@arthens
Copy link

arthens commented Jul 28, 2015

I'm having this problem too... any update?

@dlin-me
Copy link

dlin-me commented Jul 28, 2015

Same here. Would love to have this fixed. Thanks

@fengyuanchen
Copy link
Owner

@fizk Any files in the dist directory should not be changed until release a new version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants