Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Strict injection and other fixes #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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](http://www.github.com/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
});
}
});
}
swiperController.$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);