Skip to content

Commit e10489e

Browse files
author
Pablo Roizo
committed
[FIX]Strict injection, and other small fixes
1 parent 1dd16ef commit e10489e

File tree

3 files changed

+74
-64
lines changed

3 files changed

+74
-64
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,10 @@ angular.module('swiperApp')
161161

162162
});
163163
```
164+
165+
166+
## CHANGELOG
167+
# 2016-May-04 (PRDeving)
168+
* explicit injection
169+
* argument 'window.angular' instead 'angular'
170+
* removed argument 'undefined' -WTF??-

dist/angular-swiper.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-swiper.js

+66-63
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function(window, angular, undefined) {
1+
(function(window, angular) {
22

33
'use strict';
44

@@ -21,6 +21,69 @@
2121
return uuid;
2222
}
2323

24+
function swiperController($scope, $element, $timeout) {
25+
var uuid = createUUID();
26+
27+
$scope.swiper_uuid = uuid;
28+
29+
// directive defaults
30+
var params = {
31+
slidesPerView: $scope.slidesPerView || 1,
32+
slidesPerColumn: $scope.slidesPerColumn || 1,
33+
spaceBetween: $scope.spaceBetween || 0,
34+
direction: $scope.direction || 'horizontal',
35+
loop: $scope.loop || false,
36+
initialSlide: $scope.initialSlide || 0,
37+
showNavButtons: false
38+
};
39+
40+
if (!angular.isUndefined($scope.autoplay) && typeof $scope.autoplay === 'number') {
41+
params = angular.extend({}, params, {
42+
autoplay: $scope.autoplay
43+
});
44+
}
45+
46+
if ($scope.paginationIsActive === true) {
47+
params = angular.extend({}, params, {
48+
paginationClickable: $scope.paginationClickable || true,
49+
pagination: '#paginator-' + $scope.swiper_uuid
50+
});
51+
}
52+
53+
if ($scope.showNavButtons === true) {
54+
params.nextButton = '#nextButton-' + $scope.swiper_uuid;
55+
params.prevButton = '#prevButton-' + $scope.swiper_uuid;
56+
}
57+
58+
if ($scope.showScrollBar === true) {
59+
params.scrollbar = '#scrollBar-' + $scope.swiper_uuid;
60+
}
61+
62+
if ($scope.overrideParameters) {
63+
params = angular.extend({}, params, $scope.overrideParameters);
64+
}
65+
66+
$timeout(function() {
67+
var swiper = null;
68+
69+
if (angular.isObject($scope.swiper)) {
70+
$scope.swiper = new Swiper($element[0].firstChild, params);
71+
swiper = $scope.swiper;
72+
} else {
73+
swiper = new Swiper($element[0].firstChild, params);
74+
}
75+
76+
//If specified, calls this function when the swiper object is available
77+
if (!angular.isUndefined($scope.onReady)) {
78+
$scope.onReady({
79+
swiper: swiper
80+
});
81+
}
82+
});
83+
}
84+
angularSwiperController.$inject = ["$scope", "$element", "$timeout"];
85+
86+
2487
/* @ngInject */
2588
function SwiperContainer() {
2689
return {
@@ -48,67 +111,7 @@
48111
swiper: '=',
49112
overrideParameters: '='
50113
},
51-
controller: function($scope, $element, $timeout) {
52-
var uuid = createUUID();
53-
54-
$scope.swiper_uuid = uuid;
55-
56-
// directive defaults
57-
var params = {
58-
slidesPerView: $scope.slidesPerView || 1,
59-
slidesPerColumn: $scope.slidesPerColumn || 1,
60-
spaceBetween: $scope.spaceBetween || 0,
61-
direction: $scope.direction || 'horizontal',
62-
loop: $scope.loop || false,
63-
initialSlide: $scope.initialSlide || 0,
64-
showNavButtons: false
65-
};
66-
67-
if (!angular.isUndefined($scope.autoplay) && typeof $scope.autoplay === 'number') {
68-
params = angular.extend({}, params, {
69-
autoplay: $scope.autoplay
70-
});
71-
}
72-
73-
if ($scope.paginationIsActive === true) {
74-
params = angular.extend({}, params, {
75-
paginationClickable: $scope.paginationClickable || true,
76-
pagination: '#paginator-' + $scope.swiper_uuid
77-
});
78-
}
79-
80-
if ($scope.showNavButtons === true) {
81-
params.nextButton = '#nextButton-' + $scope.swiper_uuid;
82-
params.prevButton = '#prevButton-' + $scope.swiper_uuid;
83-
}
84-
85-
if ($scope.showScrollBar === true) {
86-
params.scrollbar = '#scrollBar-' + $scope.swiper_uuid;
87-
}
88-
89-
if ($scope.overrideParameters) {
90-
params = angular.extend({}, params, $scope.overrideParameters);
91-
}
92-
93-
$timeout(function() {
94-
var swiper = null;
95-
96-
if (angular.isObject($scope.swiper)) {
97-
$scope.swiper = new Swiper($element[0].firstChild, params);
98-
swiper = $scope.swiper;
99-
} else {
100-
swiper = new Swiper($element[0].firstChild, params);
101-
}
102-
103-
//If specified, calls this function when the swiper object is available
104-
if (!angular.isUndefined($scope.onReady)) {
105-
$scope.onReady({
106-
swiper: swiper
107-
});
108-
}
109-
});
110-
},
111-
114+
controller: swiperController,
112115
link: function(scope, element) {
113116

114117
var uuid = scope.swiper_uuid;
@@ -155,4 +158,4 @@
155158
};
156159
}
157160

158-
})(window, angular, undefined);
161+
})(window, window.angular);

0 commit comments

Comments
 (0)