@@ -63,10 +63,19 @@ define([
63
63
64
64
this . _bind ( ) ;
65
65
66
+ this . _isInitializingItems = true ;
67
+ this . _initializedItemCount = 0 ;
68
+ this . _lastInitializedElement = null ;
69
+
66
70
$ . each ( this . options . images , $ . proxy ( function ( index , imageData ) {
67
71
this . element . trigger ( 'addItem' , imageData ) ;
68
72
} , this ) ) ;
69
73
74
+
75
+ this . _updateImagesRoles ( ) ;
76
+ this . _contentUpdated ( ) ;
77
+
78
+ this . _isInitializingItems = false ;
70
79
this . options . initialized = true ;
71
80
} ,
72
81
@@ -186,13 +195,23 @@ define([
186
195
* @private
187
196
*/
188
197
_addItem : function ( event , imageData ) {
189
- var count = this . element . find ( this . options . imageSelector ) . length ,
190
- element ,
198
+ var element ,
191
199
imgElement ,
192
- position = count + 1 ,
200
+ lastElement ,
201
+ count ,
202
+ position ;
203
+
204
+ if ( this . _isInitializingItems ) {
205
+ count = this . _initializedItemCount ++ ;
206
+ lastElement = this . _lastInitializedElement ;
207
+ } else {
208
+ count = this . element . find ( this . options . imageSelector ) . length ;
193
209
lastElement = this . element . find ( this . options . imageSelector + ':last' ) ;
210
+ }
211
+
212
+ position = count + 1 ;
194
213
195
- if ( lastElement . length === 1 ) {
214
+ if ( lastElement && ( lastElement . length === 1 ) ) {
196
215
position = parseInt ( lastElement . data ( 'imageData' ) . position || count , 10 ) + 1 ;
197
216
}
198
217
imageData = $ . extend ( {
@@ -214,6 +233,8 @@ define([
214
233
element . insertAfter ( lastElement ) ;
215
234
}
216
235
236
+ this . _lastInitializedElement = element ;
237
+
217
238
if ( ! this . options . initialized &&
218
239
this . options . images . length === 0 ||
219
240
this . options . initialized &&
@@ -235,8 +256,10 @@ define([
235
256
}
236
257
} , this ) ) ;
237
258
238
- this . _updateImagesRoles ( ) ;
239
- this . _contentUpdated ( ) ;
259
+ if ( ! this . _isInitializingItems ) {
260
+ this . _updateImagesRoles ( ) ;
261
+ this . _contentUpdated ( ) ;
262
+ }
240
263
} ,
241
264
242
265
/**
0 commit comments