|
216 | 216 | previousH: null, |
217 | 217 | previousX: null, |
218 | 218 | previousY: null, |
| 219 | + innerX: this.x, |
| 220 | + innerY: this.y, |
| 221 | + innerW: this.w, |
| 222 | + innerH: this.h |
219 | 223 | } |
220 | 224 | }, |
221 | 225 | created () { |
|
254 | 258 | this.compact(); |
255 | 259 | }; |
256 | 260 |
|
| 261 | + self.setColNum = (colNum) => { |
| 262 | + self.cols = parseInt(colNum); |
| 263 | + } |
| 264 | +
|
257 | 265 | this.eventBus.$on('updateWidth', self.updateWidthHandler); |
258 | 266 | this.eventBus.$on('compact', self.compactHandler); |
259 | 267 | this.eventBus.$on('setDraggable', self.setDraggableHandler); |
260 | 268 | this.eventBus.$on('setResizable', self.setResizableHandler); |
261 | 269 | this.eventBus.$on('setRowHeight', self.setRowHeightHandler); |
262 | 270 | this.eventBus.$on('directionchange', self.directionchangeHandler); |
| 271 | + this.eventBus.$on('setColNum', self.setColNum) |
263 | 272 |
|
264 | | - /*this.eventBus.$on('setColNum', function(colNum) { |
265 | | - self.cols = colNum; |
266 | | - });*/ |
267 | 273 | var direction = (document.dir !== undefined) ? |
268 | 274 | document.dir : |
269 | 275 | document.getElementsByTagName("html")[0].getAttribute("dir"); |
|
278 | 284 | this.eventBus.$off('setResizable', self.setResizableHandler); |
279 | 285 | this.eventBus.$off('setRowHeight', self.setRowHeightHandler); |
280 | 286 | this.eventBus.$off('directionchange', self.directionchangeHandler); |
| 287 | + this.eventBus.$off('setColNum', self.setColNum); |
281 | 288 | }, |
282 | 289 | mounted: function () { |
283 | 290 | this.cols = this.$parent.colNum; |
|
345 | 352 | }, |
346 | 353 | ignoreFrom: this.resizeIgnoreFrom |
347 | 354 | }; |
348 | | - |
| 355 | +
|
349 | 356 | this.interactObj.resizable(opts); |
350 | 357 | if (!this.resizeEventSet) { |
351 | 358 | this.resizeEventSet = true; |
|
369 | 376 | containerWidth: function () { |
370 | 377 | this.createStyle(); |
371 | 378 | }, |
372 | | - x: function () { |
| 379 | + x: function (newVal) { |
| 380 | + this.innerX = newVal; |
373 | 381 | this.createStyle(); |
374 | 382 | }, |
375 | | - y: function () { |
| 383 | + y: function (newVal) { |
| 384 | + this.innerY = newVal; |
376 | 385 | this.createStyle(); |
377 | 386 | }, |
378 | | - h: function () { |
| 387 | + h: function (newVal) { |
| 388 | + this.innerH = newVal |
379 | 389 | this.createStyle(); |
380 | 390 | }, |
381 | | - w: function () { |
| 391 | + w: function (newVal) { |
| 392 | + this.innerW = newVal; |
382 | 393 | this.createStyle(); |
383 | 394 | }, |
384 | 395 | renderRtl: function () { |
|
400 | 411 | methods: { |
401 | 412 | createStyle: function () { |
402 | 413 | if (this.x + this.w > this.cols) { |
403 | | - this.x = 0; |
404 | | - this.w = this.cols; |
| 414 | + this.innerX = 0; |
| 415 | + this.innerW = (this.w > this.cols) ? this.cols : this.w |
| 416 | + } else { |
| 417 | + this.innerX = this.x; |
| 418 | + this.innerW = this.w; |
405 | 419 | } |
| 420 | + var pos = this.calcPosition(this.innerX, this.innerY, this.innerW, this.innerH); |
406 | 421 |
|
407 | | - var pos = this.calcPosition(this.x, this.y, this.w, this.h); |
408 | 422 |
|
409 | 423 | if (this.isDragging) { |
410 | 424 | pos.top = this.dragging.top; |
|
450 | 464 | const newSize = {width: 0, height: 0}; |
451 | 465 | switch (event.type) { |
452 | 466 | case "resizestart": |
453 | | - this.previousW = this.w; |
454 | | - this.previousH = this.h; |
455 | | - var pos = this.calcPosition(this.x, this.y, this.w, this.h); |
| 467 | + this.previousW = this.innerW; |
| 468 | + this.previousH = this.innerH; |
| 469 | + var pos = this.calcPosition(this.innerX, this.innerY, this.innerW, this.innerH); |
456 | 470 | newSize.width = pos.width; |
457 | 471 | newSize.height = pos.height; |
458 | 472 | this.resizing = newSize; |
|
472 | 486 | this.resizing = newSize; |
473 | 487 | break; |
474 | 488 | case "resizeend": |
475 | | - //console.log("### resize end => x=" +this.x + " y=" + this.y + " w=" + this.w + " h=" + this.h); |
476 | | - var pos = this.calcPosition(this.x, this.y, this.w, this.h); |
| 489 | + //console.log("### resize end => x=" +this.innerX + " y=" + this.innerY + " w=" + this.innerW + " h=" + this.innerH); |
| 490 | + var pos = this.calcPosition(this.innerX, this.innerY, this.innerW, this.innerH); |
477 | 491 | newSize.width = pos.width; |
478 | 492 | newSize.height = pos.height; |
479 | 493 | // console.log("### resize end => " + JSON.stringify(newSize)); |
|
507 | 521 | this.lastW = x; |
508 | 522 | this.lastH = y; |
509 | 523 |
|
510 | | - if (this.w !== pos.w || this.h !== pos.h) { |
| 524 | + if (this.innerW !== pos.w || this.innerH !== pos.h) { |
511 | 525 | this.$emit("resize", this.i, pos.h, pos.w); |
512 | 526 | } |
513 | | - if (event.type === "resizeend" && (this.previousW !== this.w || this.previousH !== this.h)) { |
| 527 | + if (event.type === "resizeend" && (this.previousW !== this.innerW || this.previousH !== this.innerH)) { |
514 | 528 | this.$emit("resized", this.i, pos.h, pos.w, newSize.height, newSize.width); |
515 | 529 | } |
516 | | - this.eventBus.$emit("resizeEvent", event.type, this.i, this.x, this.y, pos.h, pos.w); |
| 530 | + this.eventBus.$emit("resizeEvent", event.type, this.i, this.innerX, this.innerY, pos.h, pos.w); |
517 | 531 | }, |
518 | 532 | handleDrag(event) { |
519 | 533 | if (this.isResizing) return; |
|
528 | 542 | const newPosition = {top: 0, left: 0}; |
529 | 543 | switch (event.type) { |
530 | 544 | case "dragstart": |
531 | | - this.previousX = this.x; |
532 | | - this.previousY = this.y; |
| 545 | + this.previousX = this.innerX; |
| 546 | + this.previousY = this.innerY; |
533 | 547 |
|
534 | 548 | var parentRect = event.target.offsetParent.getBoundingClientRect(); |
535 | 549 | var clientRect = event.target.getBoundingClientRect(); |
|
585 | 599 | this.lastX = x; |
586 | 600 | this.lastY = y; |
587 | 601 |
|
588 | | - if (this.x !== pos.x || this.y !== pos.y) { |
| 602 | + if (this.innerX !== pos.x || this.innerY !== pos.y) { |
589 | 603 | this.$emit("move", this.i, pos.x, pos.y); |
590 | 604 | } |
591 | | - if (event.type === "dragend" && (this.previousX !== this.x || this.previousY !== this.y)) { |
| 605 | + if (event.type === "dragend" && (this.previousX !== this.innerX || this.previousY !== this.innerY)) { |
592 | 606 | this.$emit("moved", this.i, pos.x, pos.y); |
593 | 607 | } |
594 | | - this.eventBus.$emit("dragEvent", event.type, this.i, pos.x, pos.y, this.h, this.w); |
| 608 | + this.eventBus.$emit("dragEvent", event.type, this.i, pos.x, pos.y, this.innerH, this.innerW); |
595 | 609 | }, |
596 | 610 | calcPosition: function (x, y, w, h) { |
597 | 611 | const colWidth = this.calcColWidth(); |
|
642 | 656 | let y = Math.round((top - this.margin[1]) / (this.rowHeight + this.margin[1])); |
643 | 657 |
|
644 | 658 | // Capping |
645 | | - x = Math.max(Math.min(x, this.cols - this.w), 0); |
646 | | - y = Math.max(Math.min(y, this.maxRows - this.h), 0); |
| 659 | + x = Math.max(Math.min(x, this.cols - this.innerW), 0); |
| 660 | + y = Math.max(Math.min(y, this.maxRows - this.innerH), 0); |
647 | 661 |
|
648 | 662 | return {x, y}; |
649 | 663 | }, |
650 | 664 | // Helper for generating column width |
651 | 665 | calcColWidth() { |
652 | 666 | var colWidth = (this.containerWidth - (this.margin[0] * (this.cols + 1))) / this.cols; |
653 | | -// console.log("### COLS=" + this.cols + " COL WIDTH=" + colWidth); |
| 667 | + // console.log("### COLS=" + this.cols + " COL WIDTH=" + colWidth + " MARGIN " + this.margin[0]); |
654 | 668 | return colWidth; |
655 | 669 | }, |
656 | 670 |
|
|
670 | 684 | let h = Math.round((height + this.margin[1]) / (this.rowHeight + this.margin[1])); |
671 | 685 |
|
672 | 686 | // Capping |
673 | | - w = Math.max(Math.min(w, this.cols - this.x), 0); |
674 | | - h = Math.max(Math.min(h, this.maxRows - this.y), 0); |
| 687 | + w = Math.max(Math.min(w, this.cols - this.innerX), 0); |
| 688 | + h = Math.max(Math.min(h, this.maxRows - this.innerY), 0); |
675 | 689 | return {w, h}; |
676 | 690 | }, |
677 | 691 | updateWidth: function (width, colNum) { |
|
0 commit comments