1
1
( function ( ) {
2
2
'use strict' ;
3
3
4
- angular . module ( 'ionic.ui.content' , [ 'ionic.ui.service' ] )
4
+ angular . module ( 'ionic.ui.content' , [ 'ionic.ui.service' , 'ionic.ui.scroll' ] )
5
5
6
6
/**
7
7
* Panel is a simple 100% width and height, fixed panel. It's meant for content to be
@@ -18,7 +18,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
18
18
19
19
// The content directive is a core scrollable content area
20
20
// that is part of many View hierarchies
21
- . directive ( 'content' , [ '$parse' , '$timeout' , '$ionicScrollDelegate' , function ( $parse , $timeout , $ionicScrollDelegate ) {
21
+ . directive ( 'content' , [ '$parse' , '$timeout' , '$ionicScrollDelegate' , '$controller' , function ( $parse , $timeout , $ionicScrollDelegate , $controller ) {
22
22
return {
23
23
restrict : 'E' ,
24
24
replace : true ,
@@ -52,46 +52,33 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
52
52
if ( attr . hasTabs == "true" ) { element . addClass ( 'has-tabs' ) ; }
53
53
if ( attr . padding == "true" ) { element . find ( 'div' ) . addClass ( 'padding' ) ; }
54
54
55
- return function link ( $scope , $element , $attr , navViewCtrl ) {
56
- var clone , sc , sv ,
55
+ return {
56
+ //Prelink <content> so it can compile before other directives compile.
57
+ //Then other directives can require ionicScrollCtrl
58
+ pre : prelink
59
+ } ;
60
+
61
+ function prelink ( $scope , $element , $attr , navViewCtrl ) {
62
+ var clone , sc , scrollView , scrollCtrl ,
57
63
c = angular . element ( $element . children ( ) [ 0 ] ) ;
58
64
59
65
if ( $scope . scroll === "false" ) {
60
66
// No scrolling
61
67
return ;
62
- }
63
-
64
- if ( navViewCtrl ) {
65
- // If we do have a parent navView, wait for them to give us $viewContentLoaded event
66
- // before we fully initialize
67
- $scope . $on ( '$viewContentLoaded' , function ( e , viewHistoryData ) {
68
- initScroll ( viewHistoryData ) ;
69
- } ) ;
70
- } else {
71
- // If we are standalone view, just initialize immediately.
72
- initScroll ( ) ;
73
68
}
74
69
75
- function initScroll ( viewHistoryData ) {
76
- viewHistoryData || ( viewHistoryData = { } ) ;
77
- var savedScroll = viewHistoryData . scrollValues || { } ;
78
-
79
- // If they want plain overflow scrolling, add that as a class
80
- if ( attr . overflowScroll === "true" ) {
81
- $element . addClass ( 'overflow-scroll' ) ;
82
- return ;
83
- }
70
+ if ( attr . overflowScroll === "true" ) {
71
+ $element . addClass ( 'overflow-scroll' ) ;
72
+ return ;
73
+ }
84
74
85
- // Otherwise, use our scroll system
86
- var hasBouncing = $scope . $eval ( $scope . hasBouncing ) ;
87
- var enableBouncing = ( ! ionic . Platform . isAndroid ( ) && hasBouncing !== false ) || hasBouncing === true ;
88
- // No bouncing by default for Android users, lest they take up pitchforks
89
- // to our bouncing goodness
90
- sv = new ionic . views . Scroll ( {
75
+ scrollCtrl = $controller ( '$ionicScroll' , {
76
+ $scope : $scope ,
77
+ scrollViewOptions : {
91
78
el : $element [ 0 ] ,
92
- bouncing : enableBouncing ,
93
- startX : $scope . $eval ( $scope . startX ) || savedScroll . left || 0 ,
94
- startY : $scope . $eval ( $scope . startY ) || savedScroll . top || 0 ,
79
+ bouncing : $scope . $eval ( $scope . hasBouncing ) ,
80
+ startX : $scope . $eval ( $scope . startX ) || 0 ,
81
+ startY : $scope . $eval ( $scope . startY ) || 0 ,
95
82
scrollbarX : $scope . $eval ( $scope . scrollbarX ) !== false ,
96
83
scrollbarY : $scope . $eval ( $scope . scrollbarY ) !== false ,
97
84
scrollingX : $scope . $eval ( $scope . hasScrollX ) === true ,
@@ -103,54 +90,36 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
103
90
scrollLeft : this . __scrollLeft
104
91
} ) ;
105
92
}
106
- } ) ;
107
-
108
- //Save scroll onto viewHistoryData when scope is destroyed
109
- $scope . $on ( '$destroy' , function ( ) {
110
- viewHistoryData . scrollValues = sv . getValues ( ) ;
111
- } ) ;
112
-
113
- var refresher = $element [ 0 ] . querySelector ( '.scroll-refresher' ) ;
114
- var refresherHeight = refresher && refresher . clientHeight || 0 ;
115
-
116
- if ( attr . refreshComplete ) {
117
- $scope . refreshComplete = function ( ) {
118
- if ( $scope . scrollView ) {
119
- refresher && refresher . classList . remove ( 'active' ) ;
120
- $scope . scrollView . finishPullToRefresh ( ) ;
121
- $scope . $parent . $broadcast ( 'scroll.onRefreshComplete' ) ;
122
- }
123
- } ;
124
93
}
94
+ } ) ;
95
+ //Publish scrollView to parent so children can access it
96
+ scrollView = $scope . $parent . scrollView = scrollCtrl . scrollView ;
125
97
126
- // Activate pull-to-refresh
127
- if ( refresher ) {
128
- sv . activatePullToRefresh ( 50 , function ( ) {
129
- refresher . classList . add ( 'active' ) ;
130
- } , function ( ) {
131
- refresher . classList . remove ( 'refreshing' ) ;
132
- refresher . classList . remove ( 'active' ) ;
133
- } , function ( ) {
134
- refresher . classList . add ( 'refreshing' ) ;
135
- $scope . onRefresh ( ) ;
136
- $scope . $parent . $broadcast ( 'scroll.onRefresh' ) ;
137
- } ) ;
98
+ $scope . $on ( '$viewContentLoaded' , function ( e , viewHistoryData ) {
99
+ viewHistoryData || ( viewHistoryData = { } ) ;
100
+ if ( viewHistoryData . scrollValues ) {
101
+ scrollView . scrollTo ( viewHistoryData . scrollValues ) ;
138
102
}
139
103
140
- // Register for scroll delegate event handling
141
- $ionicScrollDelegate . register ( $scope , $element ) ;
142
-
143
- // Let child scopes access this
144
- $scope . $parent . scrollView = sv ;
145
-
146
- $timeout ( function ( ) {
147
- // Give child containers a chance to build and size themselves
148
- sv . run ( ) ;
104
+ //Save scroll onto viewHistoryData when scope is destroyed
105
+ $scope . $on ( '$destroy' , function ( ) {
106
+ viewHistoryData . scrollValues = scrollView . getValues ( ) ;
149
107
} ) ;
150
-
151
- return sv ;
108
+ } ) ;
109
+
110
+ if ( attr . refreshComplete ) {
111
+ $scope . refreshComplete = function ( ) {
112
+ if ( $scope . scrollView ) {
113
+ scrollCtrl . refresher && scrollCtrl . refresher . classList . remove ( 'active' ) ;
114
+ scrollView . finishPullToRefresh ( ) ;
115
+ $scope . $parent . $broadcast ( 'scroll.onRefreshComplete' ) ;
116
+ }
117
+ } ;
152
118
}
153
119
120
+ // Register for scroll delegate event handling
121
+ $ionicScrollDelegate . register ( $scope , $element ) ;
122
+
154
123
// Check if this supports infinite scrolling and listen for scroll events
155
124
// to trigger the infinite scrolling
156
125
// TODO(ajoslin): move functionality out of this function and make testable
@@ -163,20 +132,20 @@ angular.module('ionic.ui.content', ['ionic.ui.service'])
163
132
if ( distance . indexOf ( '%' ) ) {
164
133
// It's a multiplier
165
134
maxScroll = function ( ) {
166
- return sv . getScrollMax ( ) . top * ( 1 - parseInt ( distance , 10 ) / 100 ) ;
135
+ return scrollView . getScrollMax ( ) . top * ( 1 - parseInt ( distance , 10 ) / 100 ) ;
167
136
} ;
168
137
} else {
169
138
// It's a pixel value
170
139
maxScroll = function ( ) {
171
- return sv . getScrollMax ( ) . top - parseInt ( distance , 10 ) ;
140
+ return scrollView . getScrollMax ( ) . top - parseInt ( distance , 10 ) ;
172
141
} ;
173
142
}
174
143
$element . bind ( 'scroll' , function ( e ) {
175
- if ( sv && ! infiniteStarted && ( sv . getValues ( ) . top > maxScroll ( ) ) ) {
144
+ if ( scrollView && ! infiniteStarted && ( scrollView . getValues ( ) . top > maxScroll ( ) ) ) {
176
145
infiniteStarted = true ;
177
146
infiniteScroll . addClass ( 'active' ) ;
178
147
var cb = function ( ) {
179
- sv . resize ( ) ;
148
+ scrollView . resize ( ) ;
180
149
infiniteStarted = false ;
181
150
infiniteScroll . removeClass ( 'active' ) ;
182
151
} ;
0 commit comments