@@ -14,21 +14,15 @@ function(scope, element, $log, $document, $$q, $timeout, $interval, $$ionicAttac
1414 var SLIDE_TRANSITION_DURATION = 250 ;
1515 var SLIDE_SUCCESS_VELOCITY = ( 1 / 4 ) ; // pixels / ms
1616
17- var container = angular . element ( element [ 0 ] . querySelector ( '.slider-slides' ) ) ;
18- var containerId = 'slides_' + ionic . Utils . nextUid ( ) ;
19- container . attr ( 'id' , containerId ) ;
17+ var container = jqLite ( element [ 0 ] . querySelector ( '.slider-slides' ) ) ;
2018
2119 // Live-updated list of slides
2220 var slideNodes = container [ 0 ] . getElementsByTagName ( 'ion-slide' ) ;
2321
24- // Used in setDisplayedSlides() below
25- var styleElement = angular . element ( '<style>' ) ;
26- $document [ 0 ] . body . appendChild ( styleElement [ 0 ] ) ;
27- scope . $on ( '$destroy' , function ( ) { styleElement . remove ( ) ; } ) ;
28-
2922 // If we're already sliding and a new selection is triggered, add it to the queue,
3023 // to be taken off once the current slide animation is done
3124 var slideQueue = [ ] ;
25+
3226 // Whether we're currently sliding through the slideQueue
3327 var isSliding = false ;
3428
@@ -132,27 +126,13 @@ function(scope, element, $log, $document, $$q, $timeout, $interval, $$ionicAttac
132126 index = arguments . length ? index : selectedIndex ;
133127 var nextIndex = index + 1 ;
134128 if ( nextIndex >= self . count ( ) ) {
135- // We can't have a next if there's only one item...
129+ // We can only have a next if there's more than one item
136130 if ( isLoop && self . count ( ) > 1 ) return 0 ;
137131 return - 1 ;
138132 }
139133 return nextIndex ;
140134 }
141135
142-
143- // If slides are added or removed, we only want to re-set the selected index
144- // once per digest.
145- function enqueueSelect ( index ) {
146- enqueueSelect . index = index ;
147- if ( ! enqueueSelect . queued ) {
148- enqueueSelect . queued = true ;
149- scope . $$postDigest ( function ( ) {
150- enqueueSelect . queued = false ;
151- select ( enqueueSelect . index ) ;
152- } ) ;
153- }
154- }
155-
156136 // Called by ionSlide directive
157137 function onAddSlide ( ) {
158138 slideCount ++ ;
@@ -198,16 +178,11 @@ function(scope, element, $log, $document, $$q, $timeout, $interval, $$ionicAttac
198178 // adds data to the queue for selection.
199179 // Index can be either a number or a getter (to be called when starting the slide)
200180 function select ( newIndex , transitionDuration , isDrag ) {
201- // Don't add selection to queue if the last selection in the list is already
202- // the same index
203- if ( ( slideQueue [ 0 ] || { } ) . index === newIndex ) return ;
204-
205181 slideQueue . unshift ( [
206182 angular . isFunction ( newIndex ) ? newIndex : function ( ) { return newIndex ; } ,
207183 transitionDuration || SLIDE_TRANSITION_DURATION ,
208184 ! ! isDrag
209185 ] ) ;
210-
211186 if ( ! isSliding ) {
212187 runSelectQueue ( ) ;
213188 }
@@ -221,23 +196,17 @@ function(scope, element, $log, $document, $$q, $timeout, $interval, $$ionicAttac
221196 * Private Methods
222197 ***************************/
223198
224- function getDelta ( fromIndex , toIndex ) {
225- var difference = toIndex - fromIndex ;
226- if ( ! isLoop ) return difference ;
227-
228- // If looping is on, check for the looped difference.
229- // For example, going from the first item to the last item
230- // is actually a change of -1.
231- var loopedDifference = 0 ;
232- if ( toIndex > fromIndex ) {
233- loopedDifference = toIndex - fromIndex - self . count ( ) ;
234- } else {
235- loopedDifference = self . count ( ) - fromIndex + toIndex ;
236- }
237- if ( Math . abs ( loopedDifference ) < Math . abs ( difference ) ) {
238- return loopedDifference ;
199+ // If slides are added or removed, we only want to re-set the selected index
200+ // once per digest.
201+ function enqueueSelect ( index ) {
202+ enqueueSelect . index = index ;
203+ if ( ! enqueueSelect . queued ) {
204+ enqueueSelect . queued = true ;
205+ scope . $$postDigest ( function ( ) {
206+ enqueueSelect . queued = false ;
207+ select ( enqueueSelect . index ) ;
208+ } ) ;
239209 }
240- return difference ;
241210 }
242211
243212 // Recursively takes an item off slideQueue array, selects it,
@@ -360,6 +329,25 @@ function(scope, element, $log, $document, $$q, $timeout, $interval, $$ionicAttac
360329 currentDisplayed = newDisplayed ;
361330 }
362331
332+ function getDelta ( fromIndex , toIndex ) {
333+ var difference = toIndex - fromIndex ;
334+ if ( ! isLoop ) return difference ;
335+
336+ // If looping is on, check for the looped difference.
337+ // For example, going from the first item to the last item
338+ // is actually a change of -1.
339+ var loopedDifference = 0 ;
340+ if ( toIndex > fromIndex ) {
341+ loopedDifference = toIndex - fromIndex - self . count ( ) ;
342+ } else {
343+ loopedDifference = self . count ( ) - fromIndex + toIndex ;
344+ }
345+ if ( Math . abs ( loopedDifference ) < Math . abs ( difference ) ) {
346+ return loopedDifference ;
347+ }
348+ return difference ;
349+ }
350+
363351
364352 /********** DRAGGING **********/
365353 var dragWidth ;
0 commit comments