bitovi / jquerypp

jQuery's missing utils and special events
http://jquerypp.com
MIT License
1.21k stars 160 forks source link

Fastfix: Original can be undefined #45

Closed jbrumwell closed 12 years ago

jbrumwell commented 12 years ago

Fixes pageX, pageY and which for when the original event does not exist and the original value is undefined.

I was working with a jquery plugin that invokes mousemove like so

/trigger mousemove to move the knob to the current position
            $(document).on({
                mousemove: $.proxy(this.mousemove, this),
                mouseup: $.proxy(this.mouseup, this)
}).trigger('mousemove');

Since the mousemove handler handles actually mouse movements and this custom event, when calling:

var something = e.pageX || someothervalue;

It causes and error "original is undefined" I have not needed the which event but it most likely suffers from the same issue.

daffl commented 12 years ago

Good point. It seems as if every special mapping should have a

if(!original) {
    return;
}

As relatedTarget already does.

daffl commented 12 years ago

I fixed it with the snippet I mentioned. Let me know if there are any problems with that.