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