From 95688d6aa5c7150c3e46f1feac9cbc5f15ac7201 Mon Sep 17 00:00:00 2001 From: perry Date: Mon, 30 Mar 2015 15:50:43 -0500 Subject: [PATCH] fix(slidebox): `show-pager` defaults to true --- js/angular/directive/slideBox.js | 8 ++++- test/unit/angular/directive/slideBox.unit.js | 37 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/js/angular/directive/slideBox.js b/js/angular/directive/slideBox.js index 12ee6d40c35..10f302f06ac 100644 --- a/js/angular/directive/slideBox.js +++ b/js/angular/directive/slideBox.js @@ -30,7 +30,7 @@ * @param {boolean=} does-continue Whether the slide box should loop. * @param {boolean=} auto-play Whether the slide box should automatically slide. Default true if does-continue is true. * @param {number=} slide-interval How many milliseconds to wait to change slides (if does-continue is true). Defaults to 4000. - * @param {boolean=} show-pager Whether a pager should be shown for this slide box. Accepts expressions via `show-pager="{{shouldShow()}}"`. + * @param {boolean=} show-pager Whether a pager should be shown for this slide box. Accepts expressions via `show-pager="{{shouldShow()}}"`. Defaults to true. * @param {expression=} pager-click Expression to call when a pager is clicked (if show-pager is true). Is passed the 'index' variable. * @param {expression=} on-slide-changed Expression called whenever the slide is changed. Is passed an '$index' variable. * @param {expression=} active-slide Model to bind the current slide to. @@ -133,6 +133,12 @@ function($timeout, $compile, $ionicSlideBoxDelegate, $ionicHistory) { '', link: function($scope, $element, $attr, slideBoxCtrl) { + // if showPager is undefined, show the pager + if (!isDefined($attr.showPager)) { + $scope.showPager = true; + getPager().toggleClass('hide', !true); + } + $attr.$observe('showPager', function(show) { show = $scope.$eval(show); getPager().toggleClass('hide', !show); diff --git a/test/unit/angular/directive/slideBox.unit.js b/test/unit/angular/directive/slideBox.unit.js index 8eb84731295..779d24775e6 100644 --- a/test/unit/angular/directive/slideBox.unit.js +++ b/test/unit/angular/directive/slideBox.unit.js @@ -70,4 +70,41 @@ describe('ionSlideBox with active slide', function() { scope.$apply(); expect($ionicSlideBoxDelegate.currentIndex()).toBe(2); })); + it('Should create and show pager unless told not to', inject(function($rootScope, $compile, $timeout) { + el = $compile('' + + '' + + '
' + + '

BLUE {{slideBox.slideIndex}}

' + + '
' + + '
' + + '' + + '
' + + '

YELLOW {{slideBox.slideIndex}}

' + + '
' + + '
' + + '
')($rootScope.$new()); + + var scope = el.scope(); + scope.$apply(); + expect(el.find('.slider-pager').length).toBe(1); + expect(el.find('.slider-pager.hide').length).toBe(0); + })); + it('Should create and show pager unless told not to', inject(function($rootScope, $compile, $timeout) { + el = $compile('' + + '' + + '
' + + '

BLUE {{slideBox.slideIndex}}

' + + '
' + + '
' + + '' + + '
' + + '

YELLOW {{slideBox.slideIndex}}

' + + '
' + + '
' + + '
')($rootScope.$new()); + + var scope = el.scope(); + scope.$apply(); + expect(el.find('.slider-pager.hide').length).toBe(1); + })); });