Skip to content

Commit 8886f3a

Browse files
committed
Emit @Resized whenever pixel width/height changes
Until now, @Resized was only emitted when the user resized the grid items. Not if e.g. the user widens the window, which causes w and h to stay the same, but width grows. With this commit, all changes to GridItem-s that cause width and height to change cause @Resized to be emitted.
1 parent 9e13ea9 commit 8886f3a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/components/GridItem.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,17 @@
325325
},
326326
rowHeight: function () {
327327
this.createStyle();
328+
this.emitResized();
328329
},
329330
cols: function () {
330331
this.tryMakeResizable();
331332
this.createStyle();
333+
this.emitResized();
332334
},
333335
containerWidth: function () {
334336
this.tryMakeResizable();
335337
this.createStyle();
338+
this.emitResized();
336339
},
337340
x: function (newVal) {
338341
this.innerX = newVal;
@@ -345,10 +348,12 @@
345348
h: function (newVal) {
346349
this.innerH = newVal
347350
this.createStyle();
351+
this.emitResized();
348352
},
349353
w: function (newVal) {
350354
this.innerW = newVal;
351355
this.createStyle();
356+
this.emitResized();
352357
},
353358
renderRtl: function () {
354359
// console.log("### renderRtl");
@@ -419,7 +424,19 @@
419424
}
420425
}
421426
this.style = style;
422-
427+
},
428+
emitResized() {
429+
// this.style has width and height with trailing 'px'. The
430+
// resized event is without them
431+
let styleProps = {};
432+
for (let prop of ['width', 'height']) {
433+
let val = this.style[prop];
434+
let matches = val.match(/^(\d+)px$/);
435+
if (! matches)
436+
return;
437+
styleProps[prop] = matches[1];
438+
}
439+
this.$emit("resized", this.i, this.h, this.w, styleProps.height, styleProps.width);
423440
},
424441
handleResize: function (event) {
425442
if (this.static) return;

0 commit comments

Comments
 (0)