Skip to content

Commit

Permalink
[FIX]Strict injection, and other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Roizo committed May 4, 2016
1 parent 1dd16ef commit e10489e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 64 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,10 @@ angular.module('swiperApp')

});
```


## CHANGELOG
# 2016-May-04 (PRDeving)
* explicit injection
* argument 'window.angular' instead 'angular'
* removed argument 'undefined' -WTF??-
2 changes: 1 addition & 1 deletion dist/angular-swiper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 66 additions & 63 deletions src/angular-swiper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function(window, angular, undefined) {
(function(window, angular) {

'use strict';

Expand All @@ -21,6 +21,69 @@
return uuid;
}

function swiperController($scope, $element, $timeout) {
var uuid = createUUID();

$scope.swiper_uuid = uuid;

// directive defaults
var params = {
slidesPerView: $scope.slidesPerView || 1,
slidesPerColumn: $scope.slidesPerColumn || 1,
spaceBetween: $scope.spaceBetween || 0,
direction: $scope.direction || 'horizontal',
loop: $scope.loop || false,
initialSlide: $scope.initialSlide || 0,
showNavButtons: false
};

if (!angular.isUndefined($scope.autoplay) && typeof $scope.autoplay === 'number') {
params = angular.extend({}, params, {
autoplay: $scope.autoplay
});
}

if ($scope.paginationIsActive === true) {
params = angular.extend({}, params, {
paginationClickable: $scope.paginationClickable || true,
pagination: '#paginator-' + $scope.swiper_uuid
});
}

if ($scope.showNavButtons === true) {
params.nextButton = '#nextButton-' + $scope.swiper_uuid;
params.prevButton = '#prevButton-' + $scope.swiper_uuid;
}

if ($scope.showScrollBar === true) {
params.scrollbar = '#scrollBar-' + $scope.swiper_uuid;
}

if ($scope.overrideParameters) {
params = angular.extend({}, params, $scope.overrideParameters);
}

$timeout(function() {
var swiper = null;

if (angular.isObject($scope.swiper)) {
$scope.swiper = new Swiper($element[0].firstChild, params);
swiper = $scope.swiper;
} else {
swiper = new Swiper($element[0].firstChild, params);
}

//If specified, calls this function when the swiper object is available
if (!angular.isUndefined($scope.onReady)) {
$scope.onReady({
swiper: swiper
});
}
});
}
angularSwiperController.$inject = ["$scope", "$element", "$timeout"];


/* @ngInject */
function SwiperContainer() {
return {
Expand Down Expand Up @@ -48,67 +111,7 @@
swiper: '=',
overrideParameters: '='
},
controller: function($scope, $element, $timeout) {
var uuid = createUUID();

$scope.swiper_uuid = uuid;

// directive defaults
var params = {
slidesPerView: $scope.slidesPerView || 1,
slidesPerColumn: $scope.slidesPerColumn || 1,
spaceBetween: $scope.spaceBetween || 0,
direction: $scope.direction || 'horizontal',
loop: $scope.loop || false,
initialSlide: $scope.initialSlide || 0,
showNavButtons: false
};

if (!angular.isUndefined($scope.autoplay) && typeof $scope.autoplay === 'number') {
params = angular.extend({}, params, {
autoplay: $scope.autoplay
});
}

if ($scope.paginationIsActive === true) {
params = angular.extend({}, params, {
paginationClickable: $scope.paginationClickable || true,
pagination: '#paginator-' + $scope.swiper_uuid
});
}

if ($scope.showNavButtons === true) {
params.nextButton = '#nextButton-' + $scope.swiper_uuid;
params.prevButton = '#prevButton-' + $scope.swiper_uuid;
}

if ($scope.showScrollBar === true) {
params.scrollbar = '#scrollBar-' + $scope.swiper_uuid;
}

if ($scope.overrideParameters) {
params = angular.extend({}, params, $scope.overrideParameters);
}

$timeout(function() {
var swiper = null;

if (angular.isObject($scope.swiper)) {
$scope.swiper = new Swiper($element[0].firstChild, params);
swiper = $scope.swiper;
} else {
swiper = new Swiper($element[0].firstChild, params);
}

//If specified, calls this function when the swiper object is available
if (!angular.isUndefined($scope.onReady)) {
$scope.onReady({
swiper: swiper
});
}
});
},

controller: swiperController,
link: function(scope, element) {

var uuid = scope.swiper_uuid;
Expand Down Expand Up @@ -155,4 +158,4 @@
};
}

})(window, angular, undefined);
})(window, window.angular);

0 comments on commit e10489e

Please sign in to comment.