abpetkov / switchery

iOS 7 style switches for your checkboxes
http://abpetkov.github.io/switchery/
2.06k stars 477 forks source link

[Bug] Exception with RequireJS #76

Closed overtrue closed 9 years ago

overtrue commented 9 years ago

Hi, @abpetkov

Thank you for creating such a useful tool.

When I use it with RequireJS, reported the following error:

Uncaught TypeError: fastclick is not a function.

I try to fix it, we found the problem in here: https://github.com/abpetkov/switchery/blob/master/dist/switchery.js#L984

The require method will return module.exports, but module.exports of Fastclick is not registered.

Maybe we need replace following lines:

if (typeof define !== 'undefined' && define.amd) {

    // AMD. Register as an anonymous module.
    define(function() {
        'use strict';
        return FastClick;
    });
} else if (typeof module !== 'undefined' && module.exports) {
    module.exports = FastClick.attach;
    module.exports.FastClick = FastClick;
} else {
    window.FastClick = FastClick;
}

with:

if (typeof define !== 'undefined' && define.amd) {

    // AMD. Register as an anonymous module.
    define(function() {
        'use strict';
        return FastClick;
    });
} else {
    window.FastClick = FastClick;
}

if (typeof module !== 'undefined' && module.exports) {
    module.exports = FastClick.attach;
    module.exports.FastClick = FastClick;
}

sorry my poor english, Thanks. :smile:

abpetkov commented 9 years ago

Hi @overtrue,

Unfortunately, we cannot just replace those lines, because Fastclick is a third-party component we use and the code you're showing is their code. Even worse, their repo is not well maintained - I've opened this issue months ago, but I still have no answer.

All in all, unless I find a good replacement for Fastclick with Component support, I think I'm just going to write my own solution to this. For updates on this follow https://github.com/abpetkov/switchery/issues/22.

overtrue commented 9 years ago

@abpetkov OK,Thanks.