Skip to content

Commit

Permalink
Temporary fix for using Switchery as a RequireJS module
Browse files Browse the repository at this point in the history
Switchery uses ComponentJS as its dependency and build mechanism.
There's a compatability issue when a module built with ComponentJS is loaded with dependencies by RequireJS.
The fix changes the standalone dist/switchery.js file directly, which is a bad idea.

We need to find a better solution for this issue.

See componentjs/component#627
  • Loading branch information
Bar Ziony committed Mar 12, 2015
1 parent b042a1b commit 384ab3b
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions dist/switchery.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ require.helper.semVerSort = function(a, b) {

/**
* Find and require a module which name starts with the provided name.
* If multiple modules exists, the highest semver is used.
* If multiple modules exists, the highest semver is used.
* This function can only be used for remote dependencies.
* @param {String} name - module name: `user~repo`
* @param {Boolean} returnPath - returns the canonical require path if true,
* @param {Boolean} returnPath - returns the canonical require path if true,
* otherwise it returns the epxorted module
*/
require.latest = function (name, returnPath) {
Expand All @@ -83,7 +83,7 @@ require.latest = function (name, returnPath) {
semVerCandidates.push({version: version, name: moduleName});
} else {
otherCandidates.push({version: version, name: moduleName});
}
}
}
}
if (semVerCandidates.concat(otherCandidates).length === 0) {
Expand Down Expand Up @@ -2659,9 +2659,12 @@ extend(Hammer, {
});

if (typeof define == TYPE_FUNCTION && define.amd) {
define(function() {
return Hammer;
});
// Temp fix for RequireJS
module.exports = Hammer;

// define(function() {
// return Hammer;
// });
} else if (typeof module != 'undefined' && module.exports) {
module.exports = Hammer;
} else {
Expand Down Expand Up @@ -3410,7 +3413,7 @@ FastClick.notNeeded = function(layer) {

if (FastClick.prototype.deviceIsAndroid) {
metaViewport = document.querySelector('meta[name=viewport]');

if (metaViewport) {
// Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89)
if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
Expand Down Expand Up @@ -3449,12 +3452,15 @@ FastClick.attach = function(layer) {


if (typeof define !== 'undefined' && define.amd) {
// Temp fix for RequireJS.
module.exports = FastClick.attach;
module.exports.FastClick = FastClick;

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

0 comments on commit 384ab3b

Please sign in to comment.