Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialising fastclick with requirejs

I use requirejs with fastclick. I get the following error:

Uncaught TypeError: Cannot set property 'trackingClick' of undefined 

in Fastclick.js line 30 which does: this.trackingClick = false;

In config.js I run app.js:

require.config({
    paths: {
       fastclick:'fastclick'
    }    
)};
require(['app'], function (App) {
    App.initialize();
});

In my app.js I do:

define(['fastclick'], function(fastclick){
    var app = { 
        initialize: function () {
            var attachFastClick = require('fastclick');
            attachFastClick(document.body);
        }
    }
    return app;
}    

The browser starts fine and in the debugger the fastclick library is properly instantiated and resolved but still this in the Fastclick.js cannot be resolved.

I also tried fastclick(document.body); but it did not seem to have any effect.

Any ideas?

like image 734
Dan Schien Avatar asked Dec 26 '22 23:12

Dan Schien


2 Answers

Looking through the Fastclick code I found the following functions which works: Fastclick.attach

So, instead of calling:

 var attachFastClick = require('fastclick');
        attachFastClick(document.body);

The following works:

 fastclick.attach(document.body);
like image 57
Dan Schien Avatar answered Dec 28 '22 14:12

Dan Schien


In my app, I simply use the code seen below to properly initialize my app with fastclick. I removed all the other irrelevant lines of code to make my solution more clear

define([
    'fastclick',
], function(FastClick){
    var initialize = function(){
        new FastClick(document.body);
    }
    return {
        initialize: initialize
    };
});
like image 31
njtman Avatar answered Dec 28 '22 12:12

njtman