Skip to content

Commit 415aa09

Browse files
committed
fix errors(revolunet#254, revolunet#270) with require.js in shifty.js
1 parent 20ec5a2 commit 415aa09

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"angular-touch": ">=1.2.10"
2121
},
2222
"devDependencies": {
23-
"angular-mocks": ">=1.2.10"
23+
"angular-mocks": ">=1.2.10",
24+
"requirejs": ">=2.1.0"
2425
}
2526
}

src/directives/shifty.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,9 @@ angular.module('angular-carousel.shifty', [])
482482
// CommonJS
483483
module.exports = Tweenable;
484484
} else if (typeof define === 'function' && define.amd) {
485-
// AMD
486-
define(function () {return Tweenable;});
485+
// AMD: define it as a named module to avoid the mismatched error(http://requirejs.org/docs/errors.html#mismatch)
486+
define('shifty', [], function () {return Tweenable;});
487+
root.Tweenable = Tweenable;
487488
} else if (typeof root.Tweenable === 'undefined') {
488489
// Browser: Make `Tweenable` globally accessible.
489490
root.Tweenable = Tweenable;

test/karma.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = function ( karma ) {
1313
'bower_components/angular/angular.js',
1414
'bower_components/angular-touch/angular-touch.js',
1515
'bower_components/angular-mocks/angular-mocks.js',
16+
'bower_components/requirejs/require.js',
1617
'dist/angular-carousel.js',
1718
'test/unit/*.js'
1819
],

test/unit/angular-carousel.shifty.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*global waits, runs, iit, browserTrigger, beforeEach, afterEach, describe, it, inject, expect, module, angular, $*/
2+
3+
describe('angular-carousel.shifty', function () {
4+
'use strict';
5+
6+
describe("compatibility with requirejs", function(){
7+
var loadShifty = function() {
8+
module('angular-carousel.shifty');
9+
};
10+
it("should not throw an exception when load the shifty within requirejs environment", function(){
11+
expect(loadShifty).not.toThrow();
12+
});
13+
14+
it("should not throw an exception when inject `Tweenable` within requirejs environment", function(){
15+
loadShifty();
16+
expect(function() {inject(function(Tweenable){});}).not.toThrow();
17+
});
18+
});
19+
20+
});

0 commit comments

Comments
 (0)