Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.event.props is undefined

I'm using jquery.event.move to create move events on touch devices. The script is throwing an error on line 580.

570 // Make jQuery copy touch event properties over to the jQuery event
571 // object, if they are not already listed. But only do the ones we
572 // really need. IE7/8 do not have Array#indexOf(), but nor do they
573 // have touch events, so let's assume we can ignore them.
574 if (typeof Array.prototype.indexOf === 'function') {
575     (function(jQuery, undefined){
576         var props = ["changedTouches", "targetTouches"],
577             l = props.length;
578         
579         while (l--) {
580             if (jQuery.event.props.indexOf(props[l]) === -1) {
581                 jQuery.event.props.push(props[l]);
582             }
583         }
584     })(jQuery);
585 };

When it gets to line 580 it throws Uncaught TypeError: Cannot read property 'indexOf' of undefined The way I understand it is that jQuery.event.props is undefined? Shouldn't this array be present by default in jquery? I've "installed" jQuery in my rails app as a gem (jquery-rails 4.1.1) Any idea what I could do?

like image 938
sjbuysse Avatar asked Jul 31 '16 08:07

sjbuysse


2 Answers

There is an issue with jquery version 3 or above as mentioned in the jquery.event.move github issue page:

jQuery 3.0.0 breaks jQuery.event.props usage

This happened since in jQuery 3.0.0 upgrade jQuery.event.props and jQuery.event.fixHooks are removed. More details here:

Breaking change: jQuery.event.props and jQuery.event.fixHooks removed

jQuery's event handling performance increased thanks to a reorganization of event property management. The main improvement is that jQuery now only calculates or copies a property on the first access, rather than calculating and copying them up front. This is a really big win with properties that may force layout that the event handler may not even need. The most common use we know of was to add properties for pointer events, which is no longer necessary because those events are supported already in jQuery 3.0. The jQuery Migrate plugin provides support for these properties if you still need them. The related but undocumented mouseHooks and keyHooks lists were removed as well. The team is interested in understanding other use cases before defining new APIs, so feel free to open a ticket.

The github issue is still open and no solution has been provided yet as of 08.01.2016. As an alternative fix you can either:-

  • Use the jQuery Migrate plugin, which provides support for these properties.
  • Or, use any jQuery version below 3.0.0
like image 141
palaѕн Avatar answered Nov 07 '22 12:11

palaѕн


Version 2.0 of jQuery Events Move now supports jQuery 3.x

http://stephen.band/jquery.event.move/

UPDATE 2.0.0: move events are now compatible with jQuery 3.x. In addition, the underlying implementation is rewritten using vanilla DOM (where before it was jQuery special events only) – jQuery is no longer a requirement.

like image 24
Edgar Ortega Avatar answered Nov 07 '22 12:11

Edgar Ortega