Skip to content

Commit 979101f

Browse files
committed
code cleanup, changed var to let or const
1 parent 78de439 commit 979101f

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/App.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
import {getDocumentDir, setDocumentDir} from "./DOM";
9898
//var eventBus = require('./eventBus');
9999
100-
var testLayout = [
100+
let testLayout = [
101101
{"x":0,"y":0,"w":2,"h":2,"i":"0", resizable: true, draggable: true},
102102
{"x":2,"y":0,"w":2,"h":4,"i":"1", resizable: null, draggable: null},
103103
{"x":4,"y":0,"w":2,"h":5,"i":"2", resizable: false, draggable: false},
@@ -188,7 +188,7 @@
188188
changeDirection() {
189189
let documentDirection = getDocumentDir();
190190
let toggle = "";
191-
if (documentDirection == "rtl") {
191+
if (documentDirection === "rtl") {
192192
toggle = "ltr"
193193
} else {
194194
toggle = "rtl"

src/GridItem.vue

+21-15
Original file line numberDiff line numberDiff line change
@@ -306,15 +306,15 @@
306306
this.draggable = this.isDraggable;
307307
},
308308
draggable: function () {
309-
var self = this;
309+
const self = this;
310310
if (this.interactObj === null || this.interactObj === undefined) {
311311
this.interactObj = interact(this.$refs.item);
312312
}
313313
if (this.draggable) {
314-
var opts = {
314+
const opts = {
315315
ignoreFrom: this.dragIgnoreFrom,
316316
allowFrom: this.dragAllowFrom
317-
}
317+
};
318318
this.interactObj.draggable(opts);
319319
/*this.interactObj.draggable({allowFrom: '.vue-draggable-handle'});*/
320320
if (!this.dragEventSet) {
@@ -363,6 +363,8 @@
363363
this.createStyle();
364364
},
365365
renderRtl: function () {
366+
console.log("### renderRtl");
367+
this.tryMakeResizable();
366368
this.createStyle();
367369
}
368370
},
@@ -508,15 +510,15 @@
508510
if (position === null) return; // not possible but satisfies flow
509511
const {x, y} = position;
510512
511-
var shouldUpdate = false;
513+
let shouldUpdate = false;
512514
const newPosition = {top: 0, left: 0};
513515
switch (event.type) {
514516
case "dragstart":
515517
this.previousX = this.innerX;
516518
this.previousY = this.innerY;
517519
518-
var parentRect = event.target.offsetParent.getBoundingClientRect();
519-
var clientRect = event.target.getBoundingClientRect();
520+
let parentRect = event.target.offsetParent.getBoundingClientRect();
521+
let clientRect = event.target.getBoundingClientRect();
520522
if (this.renderRtl) {
521523
newPosition.left = (clientRect.right - parentRect.right) * -1;
522524
} else {
@@ -560,10 +562,11 @@
560562
}
561563
562564
// Get new XY
565+
let pos;
563566
if (this.renderRtl) {
564-
var pos = this.calcXY(newPosition.top, newPosition.left);
567+
pos = this.calcXY(newPosition.top, newPosition.left);
565568
} else {
566-
var pos = this.calcXY(newPosition.top, newPosition.left);
569+
pos = this.calcXY(newPosition.top, newPosition.left);
567570
}
568571
569572
this.lastX = x;
@@ -580,8 +583,9 @@
580583
calcPosition: function (x, y, w, h) {
581584
const colWidth = this.calcColWidth();
582585
// add rtl support
586+
let out;
583587
if (this.renderRtl) {
584-
var out = {
588+
out = {
585589
right: Math.round(colWidth * x + (x + 1) * this.margin[0]),
586590
top: Math.round(this.rowHeight * y + (y + 1) * this.margin[1]),
587591
// 0 * Infinity === NaN, which causes problems with resize constriants;
@@ -591,7 +595,7 @@
591595
height: h === Infinity ? h : Math.round(this.rowHeight * h + Math.max(0, h - 1) * this.margin[1])
592596
};
593597
} else {
594-
var out = {
598+
out = {
595599
left: Math.round(colWidth * x + (x + 1) * this.margin[0]),
596600
top: Math.round(this.rowHeight * y + (y + 1) * this.margin[1]),
597601
// 0 * Infinity === NaN, which causes problems with resize constriants;
@@ -633,7 +637,7 @@
633637
},
634638
// Helper for generating column width
635639
calcColWidth() {
636-
var colWidth = (this.containerWidth - (this.margin[0] * (this.cols + 1))) / this.cols;
640+
const colWidth = (this.containerWidth - (this.margin[0] * (this.cols + 1))) / this.cols;
637641
// console.log("### COLS=" + this.cols + " COL WIDTH=" + colWidth + " MARGIN " + this.margin[0]);
638642
return colWidth;
639643
},
@@ -668,15 +672,18 @@
668672
this.createStyle();
669673
},
670674
tryMakeResizable: function(){
671-
var self = this;
675+
const self = this;
672676
if (this.interactObj === null || this.interactObj === undefined) {
673677
this.interactObj = interact(this.$refs.item);
674678
}
675679
if (this.resizable) {
676680
let maximum = this.calcPosition(0,0,this.maxW, this.maxH);
677681
let minimum = this.calcPosition(0,0, this.minW, this.minH);
678682
679-
var opts = {
683+
// console.log("### MAX " + JSON.stringify(maximum));
684+
// console.log("### MIN " + JSON.stringify(minimum));
685+
686+
const opts = {
680687
preserveAspectRatio: false,
681688
edges: {
682689
left: false,
@@ -711,8 +718,7 @@
711718
});
712719
}
713720
},
714-
autoSize: function()
715-
{
721+
autoSize: function() {
716722
// ok here we want to calculate if a resize is needed
717723
this.previousW = this.innerW;
718724
this.previousH = this.innerH;

0 commit comments

Comments
 (0)