Skip to content

Commit

Permalink
feat(ionSlideBox): add pager-click attribute
Browse files Browse the repository at this point in the history
Fixes #785
  • Loading branch information
ajoslin committed Apr 7, 2014
1 parent 79f6b25 commit d6c960c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
19 changes: 15 additions & 4 deletions js/ext/angular/src/directive/ionicSlideBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ angular.module('ionic.ui.slideBox', [])
* @param {boolean=} does-continue Whether the slide box should automatically slide.
* @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.
* @param {expression=} pager-click Expression to call when a pager is clicked (if show-pager is true). Is passed the 'index' variable.
* @param {boolean=} disable-scroll Whether to disallow scrolling/dragging of the slide-box content.
* @param {expression=} on-slide-changed Expression called whenever the slide is changed.
* @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.
*/
.directive('ionSlideBox', [
Expand All @@ -151,6 +152,7 @@ function($timeout, $compile, $ionicSlideBoxDelegate) {
doesContinue: '@',
slideInterval: '@',
showPager: '@',
pagerClick: '&',
disableScroll: '@',
onSlideChanged: '&',
activeSlide: '=?'
Expand Down Expand Up @@ -205,13 +207,17 @@ function($timeout, $compile, $ionicSlideBoxDelegate) {
this.__slider = slider;

var deregisterInstance = $ionicSlideBoxDelegate._registerInstance(slider, $attrs.delegateHandle);

$scope.$on('$destroy', deregisterInstance);

this.slidesCount = function() {
return slider.slidesCount();
};

this.onPagerClick = function(index) {
console.log('pagerClick', index);
$scope.pagerClick({index: index});
};

$timeout(function() {
slider.load();
});
Expand Down Expand Up @@ -239,7 +245,8 @@ function($timeout, $compile, $ionicSlideBoxDelegate) {
require: '^ionSlideBox',
compile: function(element, attr) {
element.addClass('slider-slide');
return function($scope, $element, $attr) {};
return function($scope, $element, $attr) {
};
},
};
})
Expand All @@ -249,7 +256,7 @@ function($timeout, $compile, $ionicSlideBoxDelegate) {
restrict: 'E',
replace: true,
require: '^ionSlideBox',
template: '<div class="slider-pager"><span class="slider-pager-page" ng-repeat="slide in numSlides() track by $index" ng-class="{active: $index == currentSlide}"><i class="icon ion-record"></i></span></div>',
template: '<div class="slider-pager"><span class="slider-pager-page" ng-repeat="slide in numSlides() track by $index" ng-class="{active: $index == currentSlide}" ng-click="pagerClick($index)"><i class="icon ion-record"></i></span></div>',
link: function($scope, $element, $attr, slideBox) {
var selectPage = function(index) {
var children = $element[0].children;
Expand All @@ -263,6 +270,10 @@ function($timeout, $compile, $ionicSlideBoxDelegate) {
}
};

$scope.pagerClick = function(index) {
slideBox.onPagerClick(index);
};

$scope.numSlides = function() {
return new Array(slideBox.slidesCount());
};
Expand Down
5 changes: 4 additions & 1 deletion js/ext/angular/test/slideBox.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<ion-side-menus>
<ion-side-menu-content>
<ion-header-bar left-buttons="leftButtons" right-buttons="rightButtons" title=""></ion-header-bar>
<ion-slide-box on-slide-changed="slideChanged(index)">
<ion-slide-box on-slide-changed="slideChanged(index)" show-pager="true" pager-click="pagerClick(index)">
<ion-slide ng-controller="FirstSlideCtrl">
<h3>Thank you for choosing the Awesome App!</h3>
<div id="logo">
Expand Down Expand Up @@ -133,6 +133,9 @@ <h1 class="title">Right</h1>
$scope.leftButtons = leftButtons;
$scope.rightButtons = rightButtons;

$scope.pagerClick = function(index) {
alert('pagerClick ' + index);
};

$scope.slideChanged = function(index) {
console.log('Slide changed', index);
Expand Down

0 comments on commit d6c960c

Please sign in to comment.