@@ -100,7 +100,6 @@ define([
100
100
}
101
101
this . imageMargin = parseInt ( this . imageMargin , 10 ) ;
102
102
this . container = $ ( '[data-id="' + this . containerId + '"]' ) [ 0 ] ;
103
-
104
103
this . setLayoutStyles ( ) ;
105
104
this . setEventListener ( ) ;
106
105
@@ -129,38 +128,47 @@ define([
129
128
/**
130
129
* Set layout styles inside the container
131
130
*/
132
- setLayoutStyles : function ( ) {
133
- var containerWidth = parseInt ( this . container . clientWidth , 10 ) ,
131
+ setLayoutStyles : function ( callback ) {
132
+ var containerWidth , rowImages , ratio , rowHeight , calcHeight , isLastRow , rowNumber ;
133
+
134
+ if ( typeof this . container != 'undefined' ) {
135
+ containerWidth = parseInt ( this . container . clientWidth , 10 ) ,
134
136
rowImages = [ ] ,
135
137
ratio = 0 ,
136
138
rowHeight = 0 ,
137
139
calcHeight = 0 ,
138
140
isLastRow = false ,
139
141
rowNumber = 1 ;
140
142
141
- this . setMinRatio ( ) ;
143
+ this . setMinRatio ( ) ;
142
144
143
- this . rows ( ) . forEach ( function ( image , index ) {
144
- ratio += parseFloat ( ( image . width / image . height ) . toFixed ( 2 ) ) ;
145
- rowImages . push ( image ) ;
145
+ this . rows ( ) . forEach ( function ( image , index ) {
146
+ ratio += parseFloat ( ( image . width / image . height ) . toFixed ( 2 ) ) ;
147
+ rowImages . push ( image ) ;
146
148
147
- if ( ratio < this . minRatio && index + 1 !== this . rows ( ) . length ) {
148
- // Row has more space for images and the image is not the last one - proceed to the next iteration
149
- return ;
150
- }
149
+ if ( ratio < this . minRatio && index + 1 !== this . rows ( ) . length ) {
150
+ /**
151
+ * Row has more space for images and the image is not the last one -
152
+ * Proceed to the next iteration
153
+ */
154
+ return ;
155
+ }
151
156
152
- ratio = Math . max ( ratio , this . minRatio ) ;
153
- calcHeight = ( containerWidth - this . imageMargin * rowImages . length ) / ratio ;
154
- rowHeight = calcHeight < this . maxImageHeight ? calcHeight : this . maxImageHeight ;
155
- isLastRow = index + 1 === this . rows ( ) . length ;
157
+ ratio = Math . max ( ratio , this . minRatio ) ;
158
+ calcHeight = ( containerWidth - this . imageMargin * rowImages . length ) / ratio ;
159
+ rowHeight = calcHeight < this . maxImageHeight ? calcHeight : this . maxImageHeight ;
160
+ isLastRow = index + 1 === this . rows ( ) . length ;
156
161
157
- this . assignImagesToRow ( rowImages , rowNumber , rowHeight , isLastRow ) ;
162
+ this . assignImagesToRow ( rowImages , rowNumber , rowHeight , isLastRow ) ;
158
163
159
- rowImages = [ ] ;
160
- ratio = 0 ;
161
- rowNumber ++ ;
164
+ rowImages = [ ] ;
165
+ ratio = 0 ;
166
+ rowNumber ++ ;
162
167
163
- } . bind ( this ) ) ;
168
+ } . bind ( this ) ) ;
169
+ } else {
170
+ setTimeout ( callback , 0 ) ;
171
+ }
164
172
} ,
165
173
166
174
/**
0 commit comments