Skip to content

Commit 6e62d37

Browse files
committed
Merge pull request #329 from driftyco/328-slide-box
Revamped slide box
2 parents 8683f0d + 89a3b75 commit 6e62d37

File tree

16 files changed

+1539
-472
lines changed

16 files changed

+1539
-472
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function(grunt) {
3030
'js/views/navBarView.js',
3131
'js/views/popupView.js',
3232
'js/views/sideMenuView.js',
33-
'js/views/slideBoxView.js',
33+
'js/views/sliderView.js',
3434
'js/views/tabBarView.js',
3535
'js/views/toggleView.js',
3636

dist/css/ionic.css

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,44 +4404,38 @@ button.item-button-right:after {
44044404
* Slide Box
44054405
* --------------------------------------------------
44064406
*/
4407-
.slide-box {
4407+
.slider {
44084408
position: relative;
44094409
overflow: hidden;
4410-
background-color: #000; }
4411-
4412-
.slide-box-slides {
4413-
position: relative;
4414-
white-space: nowrap;
4415-
font-size: 0;
4416-
-webkit-transition: -webkit-transform 0 ease-in-out;
4417-
-moz-transition: -moz-transform 0 ease-in-out;
4418-
transition: transform 0 ease-in-out; }
4410+
visibility: hidden; }
44194411

4420-
.slide-box-animating {
4421-
-webkit-transition-duration: 0.2s;
4422-
-moz-transition-duration: 0.2s;
4423-
transition-duration: 0.2s; }
4412+
.slider-slides {
4413+
position: relative; }
44244414

4425-
.slide-box-slide {
4426-
display: inline-block;
4415+
.slider-slide {
4416+
display: block;
4417+
position: relative;
44274418
width: 100%;
4428-
height: 100%;
4419+
float: left;
44294420
vertical-align: top; }
4430-
.slide-box-slide img {
4431-
width: 100%; }
44324421

4433-
.slide-box-pager {
4422+
.slider-slide-image > img {
4423+
width: 100%; }
4424+
4425+
.slider-pager {
44344426
position: absolute;
44354427
bottom: 20px;
44364428
width: 100%;
4437-
text-align: center; }
4438-
.slide-box-pager > * {
4429+
text-align: center;
4430+
z-index: 1; }
4431+
.slider-pager .slider-pager-page {
44394432
display: inline-block;
4440-
margin: 0px 5px;
4433+
margin: 0px 3px;
4434+
width: 15px;
44414435
color: #fff;
44424436
text-decoration: none;
44434437
opacity: 0.3; }
4444-
.slide-box-pager > *.active {
4438+
.slider-pager .slider-pager-page.active {
44454439
opacity: 1;
44464440
-webkit-transition: opacity 0.4s ease-in;
44474441
-moz-transition: opacity 0.4s ease-in;
@@ -5706,6 +5700,11 @@ a.button {
57065700
100% {
57075701
transform: rotate(360deg); } }
57085702

5703+
.no-animation > .ng-enter, .no-animation.ng-enter, .no-animation > .ng-leave, .no-animation.ng-leave {
5704+
-webkit-transition: none;
5705+
-moz-transition: none;
5706+
transition: none; }
5707+
57095708
.noop-animation > .ng-enter, .noop-animation.ng-enter, .noop-animation > .ng-leave, .noop-animation.ng-leave {
57105709
-webkit-transition: all cubic-bezier(0.25, 0.46, 0.45, 0.94) 250ms;
57115710
-moz-transition: all cubic-bezier(0.25, 0.46, 0.45, 0.94) 250ms;

dist/js/ionic-angular.js

Lines changed: 90 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,12 @@ angular.module('ionic.ui.header', ['ngAnimate'])
509509
transclude: true,
510510
template: '<header class="bar bar-header">\
511511
<div class="buttons">\
512-
<button ng-repeat="button in leftButtons" class="button" ng-class="button.type" ng-click="button.tap($event, $index)" ng-bind-html="button.content">\
512+
<button ng-repeat="button in leftButtons" class="button no-animation" ng-class="button.type" ng-click="button.tap($event, $index)" ng-bind-html="button.content">\
513513
</button>\
514514
</div>\
515515
<h1 class="title" ng-bind-html="title"></h1>\
516516
<div class="buttons">\
517-
<button ng-repeat="button in rightButtons" class="button" ng-class="button.type" ng-click="button.tap($event, $index)" ng-bind-html="button.content">\
517+
<button ng-repeat="button in rightButtons" class="button no-animation" ng-class="button.type" ng-click="button.tap($event, $index)" ng-bind-html="button.content">\
518518
</button>\
519519
</div>\
520520
</header>',
@@ -543,6 +543,7 @@ angular.module('ionic.ui.header', ['ngAnimate'])
543543
});
544544

545545
$scope.$watch('rightButtons', function(val) {
546+
console.log('Right buttons changed');
546547
// Resize the title since the buttons have changed
547548
hb.align();
548549
});
@@ -1516,6 +1517,7 @@ angular.module('ionic.ui.scroll', [])
15161517
transclude: true,
15171518
scope: {
15181519
direction: '@',
1520+
paging: '@',
15191521
onRefresh: '&',
15201522
onScroll: '&',
15211523
refreshComplete: '=',
@@ -1524,46 +1526,51 @@ angular.module('ionic.ui.scroll', [])
15241526
scrollbarY: '@',
15251527
},
15261528

1529+
controller: function() {},
1530+
15271531
compile: function(element, attr, transclude) {
15281532
return function($scope, $element, $attr) {
15291533
var clone, sv, sc = document.createElement('div');
15301534

1535+
// Create the internal scroll div
15311536
sc.className = 'scroll';
15321537
if(attr.padding == "true") {
1533-
sc.className += ' padding';
1538+
sc.classList.add('padding');
15341539
addedPadding = true;
15351540
}
1541+
if($scope.$eval($scope.paging) === true) {
1542+
sc.classList.add('scroll-paging');
1543+
}
15361544
$element.append(sc);
15371545

15381546
// Pass the parent scope down to the child
15391547
clone = transclude($scope.$parent);
15401548
angular.element($element[0].firstElementChild).append(clone);
15411549

1550+
// Get refresher size
15421551
var refresher = $element[0].querySelector('.scroll-refresher');
15431552
var refresherHeight = refresher && refresher.clientHeight || 0;
15441553

1545-
if(attr.refreshComplete) {
1546-
$scope.refreshComplete = function() {
1547-
if($scope.scrollView) {
1548-
refresher && refresher.classList.remove('active');
1549-
$scope.scrollView.finishPullToRefresh();
1550-
$scope.$parent.$broadcast('scroll.onRefreshComplete');
1551-
}
1552-
};
1553-
}
1554-
1555-
1554+
if(!$scope.direction) { $scope.direction = 'y'; }
15561555
var hasScrollingX = $scope.direction.indexOf('x') >= 0;
15571556
var hasScrollingY = $scope.direction.indexOf('y') >= 0;
15581557

15591558
$timeout(function() {
1560-
sv = new ionic.views.Scroll({
1559+
var options = {
15611560
el: $element[0],
1561+
paging: $scope.$eval($scope.paging) === true,
15621562
scrollbarX: $scope.$eval($scope.scrollbarX) !== false,
15631563
scrollbarY: $scope.$eval($scope.scrollbarY) !== false,
15641564
scrollingX: hasScrollingX,
15651565
scrollingY: hasScrollingY
1566-
});
1566+
};
1567+
1568+
if(options.paging) {
1569+
options.speedMultiplier = 0.8;
1570+
options.bouncing = false;
1571+
}
1572+
1573+
sv = new ionic.views.Scroll(options);
15671574

15681575
// Activate pull-to-refresh
15691576
if(refresher) {
@@ -1807,41 +1814,68 @@ angular.module('ionic.ui.slideBox', [])
18071814
* some side menu stuff on the current scope.
18081815
*/
18091816

1810-
.directive('slideBox', ['$compile', function($compile) {
1817+
.directive('slideBox', ['$timeout', '$compile', function($timeout, $compile) {
18111818
return {
18121819
restrict: 'E',
18131820
replace: true,
18141821
transclude: true,
1815-
scope: {},
1822+
scope: {
1823+
doesContinue: '@',
1824+
showPager: '@',
1825+
onSlideChanged: '&'
1826+
},
18161827
controller: ['$scope', '$element', function($scope, $element) {
1817-
$scope.slides = [];
1818-
this.slideAdded = function() {
1819-
$scope.slides.push({});
1820-
};
1821-
1822-
angular.extend(this, ionic.views.SlideBox.prototype);
1828+
var _this = this;
18231829

1824-
ionic.views.SlideBox.call(this, {
1830+
var slider = new ionic.views.Slider({
18251831
el: $element[0],
1826-
slideChanged: function(slideIndex) {
1832+
continuous: $scope.$eval($scope.doesContinue) === true,
1833+
slidesChanged: function() {
1834+
$scope.currentSlide = slider.getPos();
1835+
1836+
// Try to trigger a digest
1837+
$timeout(function() {});
1838+
},
1839+
callback: function(slideIndex) {
1840+
$scope.currentSlide = slideIndex;
1841+
$scope.onSlideChanged({index:$scope.currentSlide});
18271842
$scope.$parent.$broadcast('slideBox.slideChanged', slideIndex);
1828-
$scope.$apply();
1843+
1844+
// Try to trigger a digest
1845+
$timeout(function() {});
18291846
}
18301847
});
18311848

1832-
$scope.$parent.slideBox = this;
1849+
$scope.$on('slideBox.nextSlide', function() {
1850+
slider.next();
1851+
});
1852+
1853+
$scope.$on('slideBox.prevSlide', function() {
1854+
slider.prev();
1855+
});
1856+
1857+
$scope.$on('slideBox.setSlide', function(e, index) {
1858+
slider.slide(index);
1859+
});
1860+
1861+
$scope.slideBox = slider;
1862+
1863+
$timeout(function() {
1864+
slider.load();
1865+
});
18331866
}],
1834-
template: '<div class="slide-box">\
1835-
<div class="slide-box-slides" ng-transclude>\
1867+
template: '<div class="slider">\
1868+
<div class="slider-slides" ng-transclude>\
18361869
</div>\
18371870
</div>',
18381871

18391872
link: function($scope, $element, $attr, slideBoxCtrl) {
18401873
// If the pager should show, append it to the slide box
1841-
if($attr.showPager !== "false") {
1874+
if($scope.$eval($scope.showPager) !== false) {
18421875
var childScope = $scope.$new();
1843-
var pager = $compile('<pager></pager>')(childScope);
1876+
var pager = angular.element('<pager></pager>');
18441877
$element.append(pager);
1878+
$compile(pager)(childScope);
18451879
}
18461880
}
18471881
};
@@ -1853,10 +1887,9 @@ angular.module('ionic.ui.slideBox', [])
18531887
replace: true,
18541888
require: '^slideBox',
18551889
transclude: true,
1856-
template: '<div class="slide-box-slide" ng-transclude></div>',
1890+
template: '<div class="slider-slide" ng-transclude></div>',
18571891
compile: function(element, attr, transclude) {
18581892
return function($scope, $element, $attr, slideBoxCtrl) {
1859-
slideBoxCtrl.slideAdded();
18601893
};
18611894
}
18621895
};
@@ -1867,7 +1900,29 @@ angular.module('ionic.ui.slideBox', [])
18671900
restrict: 'E',
18681901
replace: true,
18691902
require: '^slideBox',
1870-
template: '<div class="slide-box-pager"><span ng-repeat="slide in slides"><i class="icon ion-record"></i></span></div>'
1903+
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>',
1904+
link: function($scope, $element, $attr, slideBox) {
1905+
var selectPage = function(index) {
1906+
var children = $element[0].children;
1907+
var length = children.length;
1908+
for(var i = 0; i < length; i++) {
1909+
if(i == index) {
1910+
children[i].classList.add('active');
1911+
} else {
1912+
children[i].classList.remove('active');
1913+
}
1914+
}
1915+
};
1916+
1917+
$scope.numSlides = function() {
1918+
return new Array($scope.slideBox.getNumSlides());
1919+
};
1920+
1921+
$scope.$watch('currentSlide', function(v) {
1922+
console.log('Current slide', v);
1923+
selectPage(v);
1924+
});
1925+
}
18711926
};
18721927

18731928
});

0 commit comments

Comments
 (0)