ftlabs / fastclick

Polyfill to remove click delays on browsers with touch UIs
MIT License
18.66k stars 3.23k forks source link

Cannot set property 'trackingClick' of undefined #150

Open ghost opened 11 years ago

ghost commented 11 years ago

Hi there!

I am using the fastclick plugin in my mobile web app project. I am getting the error

Cannot set property 'trackingClick' of undefined

when I try to call the FastClick.attach function. I guess the problem is the lazy loading of require.js. The documentation tells me, that the plugins supports AMD, but it seems that I am doing something wrong.

I tried to call it in different places of the app (it is a Backbone Marionette App). e.g. app initialize, app onStart or even in a onShow-Method of my layout. So I think it couldn't be a document.ready issue.

I used this code to attach fastclick:

var attachFastClick = require(['fastclick']); attachFastClick(document);

Does anybody made fastclick and require.js work together?

Best Christofer

cilogi commented 11 years ago

Instead of attachFastClick(document); try attachFastClick.attach(document.body);.

fenoloco commented 11 years ago

I have the same problem and your suggestion dose not work for me. Any other idea? Thanks

noslouch commented 10 years ago

I just wanted to chime in I was having a similar problem using FC with require, and it was returning a FastClick object, not the attachFastClick function. Changing my code to call the attach method on the returned FactClick object worked just fine for me.

Thanks @cilogi.

elad commented 10 years ago

Same here, please update the documentation.

matthew-andrews commented 10 years ago

Hi @eladxxx @noslouch @cilogi - we actually don't have any docs for AMD/RequireJS - the README (it's a bit unfortunate we've made the API FastClick exposes in CommonJS different from AMD but it's probably too late to fix that now). Would happily accept a pull request from someone using RequireJS to add docs for it as it's not something I've ever used before...

elad commented 10 years ago

You're right - I was looking at the CommonJS section. Here's what works for me in RequireJS:

define([
    "fastclick",
], function(fastclick) {
    fastclick.attach(document.body);
});
matthew-andrews commented 10 years ago

Does the above snippet work for everyone else?

noslouch commented 10 years ago

Yeah that's what I"m using. I can submit a PR to update the docs if you need.

On Mon, Feb 3, 2014 at 8:46 AM, Matt Andrews notifications@github.comwrote:

Does the above snippet work for everyone else?

— Reply to this email directly or view it on GitHubhttps://github.com/ftlabs/fastclick/issues/150#issuecomment-33955156 .

dyf19118 commented 8 years ago

This problem still exists. FastClick constructor is exported instead of FastClick.attach in webpack.

fly39244080 commented 7 years ago

var FastClick = require('fastclick'); FastClick.attach(document.body);

It can work for me, hope to help for you!

marionlxy commented 7 years ago

var FastClick = require('fastclick'); FastClick.attach(document.body);

It can work for me, hope to help for me!