|
| 1 | + |
| 2 | +/** |
| 3 | + * @ngdoc directive |
| 4 | + * @name ionSlides |
| 5 | + * @module ionic |
| 6 | + * @delegate ionic.service:$ionicSlideBoxDelegate |
| 7 | + * @restrict E |
| 8 | + * @description |
| 9 | + * The Slides component is a powerful multi-page container where each page can be swiped or dragged between. |
| 10 | + * |
| 11 | + * Note: this is a new version of the Ionic Slide Box based on the [Swiper](http://www.idangero.us/swiper/#.Vmc1J-ODFBc) widget from |
| 12 | + * [idangerous](http://www.idangero.us/). |
| 13 | + * |
| 14 | + *  |
| 15 | + * |
| 16 | + * @usage |
| 17 | + * ```html |
| 18 | + * <ion-slides on-slide-changed="slideHasChanged($index)"> |
| 19 | + * <ion-slide> |
| 20 | + * <div class="box blue"><h1>BLUE</h1></div> |
| 21 | + * </ion-slide> |
| 22 | + * <ion-slide> |
| 23 | + * <div class="box yellow"><h1>YELLOW</h1></div> |
| 24 | + * </ion-slide> |
| 25 | + * <ion-slide> |
| 26 | + * <div class="box pink"><h1>PINK</h1></div> |
| 27 | + * </ion-slide> |
| 28 | + * </ion-slides> |
| 29 | + * ``` |
| 30 | + * |
| 31 | + * @param {string=} delegate-handle The handle used to identify this slideBox |
| 32 | + * with {@link ionic.service:$ionicSlideBoxDelegate}. |
| 33 | + * @param {object=} options to pass to the widget. See the full ist here: [http://www.idangero.us/swiper/api/](http://www.idangero.us/swiper/api/) |
| 34 | + */ |
| 35 | +IonicModule |
| 36 | +.directive('ionSlides', [ |
| 37 | + '$animate', |
| 38 | + '$timeout', |
| 39 | +function($animate, $timeout) { |
| 40 | + return { |
| 41 | + restrict: 'E', |
| 42 | + transclude: true, |
| 43 | + scope: { |
| 44 | + options: '=' |
| 45 | + }, |
| 46 | + template: '<div class="swiper-container">' + |
| 47 | + '<div class="swiper-wrapper" ng-transclude>' + |
| 48 | + '</div>' + |
| 49 | + '<div ng-hide="!showPager" class="swiper-pagination"></div>' + |
| 50 | + '</div>', |
| 51 | + controller: ['$scope', '$element', function($scope, $element) { |
| 52 | + var _this = this; |
| 53 | + |
| 54 | + this.update = function() { |
| 55 | + $timeout(function() { |
| 56 | + _this.__slider.update(); |
| 57 | + |
| 58 | + // Don't allow pager to show with > 10 slides |
| 59 | + if (_this.__slider.slides.length > 10) { |
| 60 | + $scope.showPager = false; |
| 61 | + } |
| 62 | + }); |
| 63 | + }; |
| 64 | + |
| 65 | + var options = $scope.options || {}; |
| 66 | + |
| 67 | + var newOptions = angular.extend({ |
| 68 | + pagination: '.swiper-pagination', |
| 69 | + paginationClickable: true, |
| 70 | + lazyLoading: true, |
| 71 | + preloadImages: false |
| 72 | + }, options); |
| 73 | + |
| 74 | + $timeout(function() { |
| 75 | + var slider = new ionic.views.Swiper($element.children()[0], newOptions); |
| 76 | + |
| 77 | + _this.__slider = slider; |
| 78 | + |
| 79 | + $scope.$on('$destroy', function() { |
| 80 | + slider.destroy(); |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | + }], |
| 85 | + |
| 86 | + |
| 87 | + link: function($scope, $element) { |
| 88 | + $scope.showPager = true; |
| 89 | + // Disable ngAnimate for slidebox and its children |
| 90 | + $animate.enabled(false, $element); |
| 91 | + } |
| 92 | + }; |
| 93 | +}]) |
| 94 | +.directive('ionSlidePage', [function() { |
| 95 | + return { |
| 96 | + restrict: 'E', |
| 97 | + require: '?^ionSlides', |
| 98 | + transclude: true, |
| 99 | + replace: true, |
| 100 | + template: '<div class="swiper-slide" ng-transclude></div>' |
| 101 | + }; |
| 102 | +}]); |
0 commit comments