2
2
* Copyright 2013 Drifty Co.
3
3
* http://drifty.com/
4
4
*
5
- * Ionic, v0.9.14
5
+ * Ionic, v0.9.17
6
6
* A powerful HTML5 mobile app framework.
7
7
* http://ionicframework.com/
8
8
*
@@ -1811,41 +1811,48 @@ angular.module('ionic.ui.slideBox', [])
1811
1811
* some side menu stuff on the current scope.
1812
1812
*/
1813
1813
1814
- . directive ( 'slideBox' , [ '$compile' , function ( $compile ) {
1814
+ . directive ( 'slideBox' , [ '$timeout' , '$ compile', function ( $timeout , $compile ) {
1815
1815
return {
1816
1816
restrict : 'E' ,
1817
1817
replace : true ,
1818
1818
transclude : true ,
1819
1819
scope : { } ,
1820
1820
controller : [ '$scope' , '$element' , function ( $scope , $element ) {
1821
- $scope . slides = [ ] ;
1822
- this . slideAdded = function ( ) {
1823
- $scope . slides . push ( { } ) ;
1824
- } ;
1825
-
1826
- angular . extend ( this , ionic . views . SlideBox . prototype ) ;
1821
+ var _this = this ;
1827
1822
1828
- ionic . views . SlideBox . call ( this , {
1823
+ var slider = new ionic . views . Slider ( {
1829
1824
el : $element [ 0 ] ,
1830
- slideChanged : function ( slideIndex ) {
1825
+ slidesChanged : function ( ) {
1826
+ $scope . currentSlide = slider . getPos ( ) ;
1827
+ $timeout ( function ( ) { } ) ;
1828
+ } ,
1829
+ callback : function ( slideIndex ) {
1830
+ $scope . currentSlide = slideIndex ;
1831
1831
$scope . $parent . $broadcast ( 'slideBox.slideChanged' , slideIndex ) ;
1832
1832
$scope . $apply ( ) ;
1833
1833
}
1834
1834
} ) ;
1835
1835
1836
- $scope . $parent . slideBox = this ;
1836
+ slider . load ( ) ;
1837
+
1838
+ $scope . slider = slider ;
1839
+
1840
+ $timeout ( function ( ) {
1841
+ $scope . slider . setup ( ) ;
1842
+ } ) ;
1837
1843
} ] ,
1838
- template : '<div class="slide-box ">\
1839
- <div class="slide-box -slides" ng-transclude>\
1844
+ template : '<div class="slider ">\
1845
+ <div class="slider -slides" ng-transclude>\
1840
1846
</div>\
1841
1847
</div>' ,
1842
1848
1843
1849
link : function ( $scope , $element , $attr , slideBoxCtrl ) {
1844
1850
// If the pager should show, append it to the slide box
1845
1851
if ( $attr . showPager !== "false" ) {
1846
1852
var childScope = $scope . $new ( ) ;
1847
- var pager = $compile ( '<pager></pager>' ) ( childScope ) ;
1853
+ var pager = angular . element ( '<pager></pager>' ) ;
1848
1854
$element . append ( pager ) ;
1855
+ $compile ( pager ) ( childScope ) ;
1849
1856
}
1850
1857
}
1851
1858
} ;
@@ -1857,10 +1864,9 @@ angular.module('ionic.ui.slideBox', [])
1857
1864
replace : true ,
1858
1865
require : '^slideBox' ,
1859
1866
transclude : true ,
1860
- template : '<div class="slide-box -slide" ng-transclude></div>' ,
1867
+ template : '<div class="slider -slide" ng-transclude></div>' ,
1861
1868
compile : function ( element , attr , transclude ) {
1862
1869
return function ( $scope , $element , $attr , slideBoxCtrl ) {
1863
- slideBoxCtrl . slideAdded ( ) ;
1864
1870
} ;
1865
1871
}
1866
1872
} ;
@@ -1871,7 +1877,29 @@ angular.module('ionic.ui.slideBox', [])
1871
1877
restrict : 'E' ,
1872
1878
replace : true ,
1873
1879
require : '^slideBox' ,
1874
- template : '<div class="slide-box-pager"><span ng-repeat="slide in slides"><i class="icon ion-record"></i></span></div>'
1880
+ 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>' ,
1881
+ link : function ( $scope , $element , $attr , slideBox ) {
1882
+ var selectPage = function ( index ) {
1883
+ var children = $element [ 0 ] . children ;
1884
+ var length = children . length ;
1885
+ for ( var i = 0 ; i < length ; i ++ ) {
1886
+ if ( i == index ) {
1887
+ children [ i ] . classList . add ( 'active' ) ;
1888
+ } else {
1889
+ children [ i ] . classList . remove ( 'active' ) ;
1890
+ }
1891
+ }
1892
+ } ;
1893
+
1894
+ $scope . numSlides = function ( ) {
1895
+ return new Array ( $scope . slider . getNumSlides ( ) ) ;
1896
+ } ;
1897
+
1898
+ $scope . $watch ( 'currentSlide' , function ( v ) {
1899
+ console . log ( 'Current slide' , v ) ;
1900
+ selectPage ( v ) ;
1901
+ } ) ;
1902
+ }
1875
1903
} ;
1876
1904
1877
1905
} ) ;
0 commit comments