stuyam / pressure

:point_down::boom: JavaScript library for handling Force Touch, 3D Touch, and Pointer Pressure.
https://pressurejs.com
MIT License
2.91k stars 98 forks source link

How to detect if pressure.js is already binded to an element? #73

Closed MickL closed 6 years ago

MickL commented 6 years ago

I want to prevent binding pressure.js to an element that already has pressure.js. How may i detect that?

Something like:

if(!$(someElement).pressure) {
   $(someElement).pressure();
}
stuyam commented 6 years ago

Hi @MickL, There currently isn't a way I can think of to test if an element is bound to pressure. It seems like it would make sense to do so.

For now you could so something like add a property on any element that has been bound to pressure that you can check later. For example:

$(someElement).pressure();
$(someElement).data('pressure-bound', true);
...
...
if( !$(someElement).data('pressure-bound') ){
  // do something
}

But I will look into how we could provide this as a feature. If anyone has any ideas I'm all ears.

MickL commented 6 years ago

Yes thanks i did it by adding a class. Feature would be nice but it is not a major issue.