|
153 | 153 | this.originalLayout = this.layout; |
154 | 154 | const self = this; |
155 | 155 | this.$nextTick(function() { |
156 | | - if (self.width === null) { |
157 | | - self.onWindowResize(); |
| 156 | + self.onWindowResize(); |
158 | 157 |
|
159 | | - self.initResponsiveFeatures(); |
| 158 | + self.initResponsiveFeatures(); |
| 159 | +
|
| 160 | + //self.width = self.$el.offsetWidth; |
| 161 | + addWindowEventListener('resize', self.onWindowResize); |
160 | 162 |
|
161 | | - //self.width = self.$el.offsetWidth; |
162 | | - addWindowEventListener('resize', self.onWindowResize); |
163 | | - } |
164 | 163 | compact(self.layout, self.verticalCompact); |
165 | 164 |
|
166 | 165 | self.updateHeight(); |
167 | 166 | self.$nextTick(function () { |
168 | 167 | this.erd = elementResizeDetectorMaker({ |
169 | | - strategy: "scroll" //<- For ultra performance. |
| 168 | + strategy: "scroll", //<- For ultra performance. |
| 169 | + // See https://github.com/wnr/element-resize-detector/issues/110 about callOnAdd. |
| 170 | + callOnAdd: false, |
170 | 171 | }); |
171 | 172 | this.erd.listenTo(self.$refs.item, function () { |
172 | 173 | self.onWindowResize(); |
173 | 174 | }); |
174 | 175 | }); |
175 | | -
|
176 | | - self.$emit('layout-ready', self.layout); |
177 | 176 | }); |
178 | 177 | }); |
179 | 178 | }, |
180 | 179 | watch: { |
181 | | - width: function () { |
| 180 | + width: function (newval, oldval) { |
182 | 181 | this.$nextTick(function () { |
183 | 182 | //this.$broadcast("updateWidth", this.width); |
184 | 183 | this.eventBus.$emit("updateWidth", this.width); |
| 184 | + if (oldval === null) { |
| 185 | + /* |
| 186 | + If oldval == null is when the width has never been |
| 187 | + set before. That only occurs when mouting is |
| 188 | + finished, and onWindowResize has been called and |
| 189 | + this.width has been changed the first time after it |
| 190 | + got set to null in the constructor. It is now time |
| 191 | + to issue layout-ready events as the GridItems have |
| 192 | + their sizes configured properly. |
| 193 | +
|
| 194 | + The reason for emitting the layout-ready events on |
| 195 | + the next tick is to allow for the newly-emitted |
| 196 | + updateWidth event (above) to have reached the |
| 197 | + children GridItem-s and had their effect, so we're |
| 198 | + sure that they have the final size before we emit |
| 199 | + layout-ready (for this GridLayout) and |
| 200 | + item-layout-ready (for the GridItem-s). |
| 201 | +
|
| 202 | + This way any client event handlers can reliably |
| 203 | + invistigate stable sizes of GridItem-s. |
| 204 | + */ |
| 205 | + this.$nextTick(() => { |
| 206 | + this.$emit('layout-ready', self.layout); |
| 207 | + }); |
| 208 | + } |
185 | 209 | this.updateHeight(); |
186 | 210 | }); |
187 | 211 | }, |
|
0 commit comments