noUiSlider: Conflict Prototype.js and noUiSlider : can drag handles on mobile devices
Hi,
I’m facing an issue already reported : #908 #902 The error occurred on mobile device on chrome, we can’t drag handles.
Uncaught TypeError: this.each is not a function
at TouchList.findAll (prototype.js:883)
at G (nouislider.min.js:3)
at HTMLDivElement.f (nouislider.min.js:3)
Uncaught TypeError: this.each is not a function
at TouchList.findAll (prototype.js:883)
at fixEvent (nouislider.js:1473)
at HTMLDivElement.method (nouislider.js:1387)
Can you have a look on this ?
Thanks.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
I simply added:
TouchList.prototype.each = Array.prototype.each; TouchList.prototype._each = Array.prototype._each;
to noUislider.min.js at beginning and seems to have fixed my issue(s).
In interest to retain the Magento 1.x defaults, as resetting the native Array prototype may conflict with Magento requirements/code, I simply added:
if(typeof TouchList === "function"){ //check if it exists cause Edge/IE it doesn't and will throw errors
TouchList.prototype.each = Array.prototype.each;
TouchList.prototype._each = Array.prototype._each;
}
to noUislider.min.js at beginning and seems to have fixed my issue(s). The issue seems to stem from around line 721 where filter/find is overwritten by prototype.js, it doesn’t hang up for me here… but on the prototype extended method of filter/find calling this.each/this._each on the passed ‘l’ var.
if ("touchstart" === t.type) { var u = Array.prototype.filter.call(t.touches, l); if (1 < u.length) return !1; n = u[0].pageX, i = u[0].pageY } else { var c = Array.prototype.find.call(t.changedTouches, l);
As a workaround, restore the original array find after including prototype.js: