energize.js icon indicating copy to clipboard operation
energize.js copied to clipboard

'Ghost clicks' on iOS when elements are created dynamically

Open bredfield opened this issue 13 years ago • 11 comments

Whenever I programmatically create a node and bind a 'click' event, I get 'ghost clicks' on iOS - the bound event gets fired twice. This doesn't happen on elements that exist on page load. Any ideas?

bredfield avatar May 28 '12 21:05 bredfield

Is this ever going to get fixed?

thaoms avatar Dec 20 '12 14:12 thaoms

I got this fixed by adding e.preventDefault(); in the touchstart function

var touchstart = function(e) { // setup the initial values // TODO: touch and hold e.preventDefault(); this.startXY = [e.touches[0].clientX, e.touches[0].clientY]; this.threshold = false; };

thaoms avatar Dec 20 '12 16:12 thaoms

@thomasvankerckvoorde I believe your best bet is to take the initiative and make the change yourself + open a pull request.

thurloat avatar Jan 04 '13 14:01 thurloat

are there any implications to calling e.preventDefault()?

garrettlangley avatar Jan 04 '13 14:01 garrettlangley

Without testing the code, I think it could break things like scrolling, dragging, etc. anything custom that a JS app is listening for touchstart events.

thurloat avatar Jan 04 '13 14:01 thurloat

In my project it did, when I used another prevent default to avoid links opening a new tab. (Commented the build-in standalone code, because that one didn't work for me). My project is a standalone slideshow app. So apart from some buttons and flex slider it didn't need that much custom functionality. You should try it in your code locally, see if it works out for you.

On Friday 4 January 2013 at 15:56, Adam Thurlow wrote:

Without testing the code, I think it could break things like scrolling, dragging, etc. anything custom that a JS app is listening for touchstart events.

— Reply to this email directly or view it on GitHub (https://github.com/davidcalhoun/energize.js/issues/10#issuecomment-11885281).

thaoms avatar Jan 04 '13 14:01 thaoms

thanks @thurloat and @thomasvankerckvoorde

garrettlangley avatar Jan 04 '13 15:01 garrettlangley

Temporary I'm using this lib, https://github.com/ftlabs/fastclick. Until this one get fixed.

thaoms avatar Jan 04 '13 15:01 thaoms

@thomasvankerckvoorde i was able to drive a preventDefault off of class/id of the target.

  if (e.target.className == "button") {
    e.preventDefault();
  }

garrettlangley avatar Jan 04 '13 17:01 garrettlangley

I ran into a similar problem with energize.js interacting with dynamically generated elements at the position of the target element in a slow-loading environment.

A button triggers an angular.js route change and the view with the source button is removed and replaced by a second view which has a new button at the same place. The new button is then triggered after route change. That behaviour is just madness.

tarcon avatar Jan 16 '13 13:01 tarcon

I've only seen tarcon's issue, which I can reproduce on my end. Can't seem to get a use case working that demonstrates the original issue described, although enough folks seem to have it.

Any additional info or code would help!

(sorry for the delay - have been on a LONG sabbatical)

davidcalhoun avatar Jun 11 '13 15:06 davidcalhoun