|
212 | 212 | previousH: null, |
213 | 213 | previousX: null, |
214 | 214 | previousY: null, |
| 215 | + innerX: this.x, |
| 216 | + innerY: this.y, |
| 217 | + innerW: this.w, |
| 218 | + innerH: this.h |
215 | 219 | } |
216 | 220 | }, |
217 | 221 | created () { |
|
250 | 254 | this.compact(); |
251 | 255 | }; |
252 | 256 |
|
| 257 | + self.setColNum = (colNum) => { |
| 258 | + self.cols = parseInt(colNum); |
| 259 | + } |
| 260 | +
|
253 | 261 | this.eventBus.$on('updateWidth', self.updateWidthHandler); |
254 | 262 | this.eventBus.$on('compact', self.compactHandler); |
255 | 263 | this.eventBus.$on('setDraggable', self.setDraggableHandler); |
256 | 264 | this.eventBus.$on('setResizable', self.setResizableHandler); |
257 | 265 | this.eventBus.$on('setRowHeight', self.setRowHeightHandler); |
258 | 266 | this.eventBus.$on('directionchange', self.directionchangeHandler); |
| 267 | + this.eventBus.$on('setColNum', self.setColNum) |
259 | 268 |
|
260 | | - /*this.eventBus.$on('setColNum', function(colNum) { |
261 | | - self.cols = colNum; |
262 | | - });*/ |
263 | 269 | var direction = (document.dir !== undefined) ? |
264 | 270 | document.dir : |
265 | 271 | document.getElementsByTagName("html")[0].getAttribute("dir"); |
|
274 | 280 | this.eventBus.$off('setResizable', self.setResizableHandler); |
275 | 281 | this.eventBus.$off('setRowHeight', self.setRowHeightHandler); |
276 | 282 | this.eventBus.$off('directionchange', self.directionchangeHandler); |
| 283 | + this.eventBus.$off('setColNum', self.setColNum); |
277 | 284 | }, |
278 | 285 | mounted: function () { |
279 | 286 | this.cols = this.$parent.colNum; |
|
336 | 343 | edges: {left: false, right: true, bottom: true, top: false}, |
337 | 344 | ignoreFrom: this.resizeIgnoreFrom |
338 | 345 | }; |
339 | | - |
| 346 | +
|
340 | 347 | this.interactObj.resizable(opts); |
341 | 348 | if (!this.resizeEventSet) { |
342 | 349 | this.resizeEventSet = true; |
|
360 | 367 | containerWidth: function () { |
361 | 368 | this.createStyle(); |
362 | 369 | }, |
363 | | - x: function () { |
| 370 | + x: function (newVal) { |
| 371 | + this.innerX = newVal; |
364 | 372 | this.createStyle(); |
365 | 373 | }, |
366 | | - y: function () { |
| 374 | + y: function (newVal) { |
| 375 | + this.innerY = newVal; |
367 | 376 | this.createStyle(); |
368 | 377 | }, |
369 | | - h: function () { |
| 378 | + h: function (newVal) { |
| 379 | + this.innerH = newVal |
370 | 380 | this.createStyle(); |
371 | 381 | }, |
372 | | - w: function () { |
| 382 | + w: function (newVal) { |
| 383 | + this.innerW = newVal; |
373 | 384 | this.createStyle(); |
374 | 385 | }, |
375 | 386 | renderRtl: function () { |
|
391 | 402 | methods: { |
392 | 403 | createStyle: function () { |
393 | 404 | if (this.x + this.w > this.cols) { |
394 | | - this.x = 0; |
395 | | - this.w = this.cols; |
| 405 | + this.innerX = 0; |
| 406 | + this.innerW = (this.w > this.cols) ? this.cols : this.w |
| 407 | + } else { |
| 408 | + this.innerX = this.x; |
| 409 | + this.innerW = this.w; |
396 | 410 | } |
| 411 | + var pos = this.calcPosition(this.innerX, this.innerY, this.innerW, this.innerH); |
397 | 412 |
|
398 | | - var pos = this.calcPosition(this.x, this.y, this.w, this.h); |
399 | 413 |
|
400 | 414 | if (this.isDragging) { |
401 | 415 | pos.top = this.dragging.top; |
|
441 | 455 | const newSize = {width: 0, height: 0}; |
442 | 456 | switch (event.type) { |
443 | 457 | case "resizestart": |
444 | | - this.previousW = this.w; |
445 | | - this.previousH = this.h; |
446 | | - var pos = this.calcPosition(this.x, this.y, this.w, this.h); |
| 458 | + this.previousW = this.innerW; |
| 459 | + this.previousH = this.innerH; |
| 460 | + var pos = this.calcPosition(this.innerX, this.innerY, this.innerW, this.innerH); |
447 | 461 | newSize.width = pos.width; |
448 | 462 | newSize.height = pos.height; |
449 | 463 | this.resizing = newSize; |
|
463 | 477 | this.resizing = newSize; |
464 | 478 | break; |
465 | 479 | case "resizeend": |
466 | | - //console.log("### resize end => x=" +this.x + " y=" + this.y + " w=" + this.w + " h=" + this.h); |
467 | | - var pos = this.calcPosition(this.x, this.y, this.w, this.h); |
| 480 | + //console.log("### resize end => x=" +this.innerX + " y=" + this.innerY + " w=" + this.innerW + " h=" + this.innerH); |
| 481 | + var pos = this.calcPosition(this.innerX, this.innerY, this.innerW, this.innerH); |
468 | 482 | newSize.width = pos.width; |
469 | 483 | newSize.height = pos.height; |
470 | 484 | // console.log("### resize end => " + JSON.stringify(newSize)); |
|
498 | 512 | this.lastW = x; |
499 | 513 | this.lastH = y; |
500 | 514 |
|
501 | | - if (this.w !== pos.w || this.h !== pos.h) { |
| 515 | + if (this.innerW !== pos.w || this.innerH !== pos.h) { |
502 | 516 | this.$emit("resize", this.i, pos.h, pos.w); |
503 | 517 | } |
504 | | - if (event.type === "resizeend" && (this.previousW !== this.w || this.previousH !== this.h)) { |
| 518 | + if (event.type === "resizeend" && (this.previousW !== this.innerW || this.previousH !== this.innerH)) { |
505 | 519 | this.$emit("resized", this.i, pos.h, pos.w, newSize.height, newSize.width); |
506 | 520 | } |
507 | | - this.eventBus.$emit("resizeEvent", event.type, this.i, this.x, this.y, pos.h, pos.w); |
| 521 | + this.eventBus.$emit("resizeEvent", event.type, this.i, this.innerX, this.innerY, pos.h, pos.w); |
508 | 522 | }, |
509 | 523 | handleDrag(event) { |
510 | 524 | if (this.isResizing) return; |
|
519 | 533 | const newPosition = {top: 0, left: 0}; |
520 | 534 | switch (event.type) { |
521 | 535 | case "dragstart": |
522 | | - this.previousX = this.x; |
523 | | - this.previousY = this.y; |
| 536 | + this.previousX = this.innerX; |
| 537 | + this.previousY = this.innerY; |
524 | 538 |
|
525 | 539 | var parentRect = event.target.offsetParent.getBoundingClientRect(); |
526 | 540 | var clientRect = event.target.getBoundingClientRect(); |
|
576 | 590 | this.lastX = x; |
577 | 591 | this.lastY = y; |
578 | 592 |
|
579 | | - if (this.x !== pos.x || this.y !== pos.y) { |
| 593 | + if (this.innerX !== pos.x || this.innerY !== pos.y) { |
580 | 594 | this.$emit("move", this.i, pos.x, pos.y); |
581 | 595 | } |
582 | | - if (event.type === "dragend" && (this.previousX !== this.x || this.previousY !== this.y)) { |
| 596 | + if (event.type === "dragend" && (this.previousX !== this.innerX || this.previousY !== this.innerY)) { |
583 | 597 | this.$emit("moved", this.i, pos.x, pos.y); |
584 | 598 | } |
585 | | - this.eventBus.$emit("dragEvent", event.type, this.i, pos.x, pos.y, this.h, this.w); |
| 599 | + this.eventBus.$emit("dragEvent", event.type, this.i, pos.x, pos.y, this.innerH, this.innerW); |
586 | 600 | }, |
587 | 601 | calcPosition: function (x, y, w, h) { |
588 | 602 | const colWidth = this.calcColWidth(); |
|
633 | 647 | let y = Math.round((top - this.margin[1]) / (this.rowHeight + this.margin[1])); |
634 | 648 |
|
635 | 649 | // Capping |
636 | | - x = Math.max(Math.min(x, this.cols - this.w), 0); |
637 | | - y = Math.max(Math.min(y, this.maxRows - this.h), 0); |
| 650 | + x = Math.max(Math.min(x, this.cols - this.innerW), 0); |
| 651 | + y = Math.max(Math.min(y, this.maxRows - this.innerH), 0); |
638 | 652 |
|
639 | 653 | return {x, y}; |
640 | 654 | }, |
641 | 655 | // Helper for generating column width |
642 | 656 | calcColWidth() { |
643 | 657 | var colWidth = (this.containerWidth - (this.margin[0] * (this.cols + 1))) / this.cols; |
644 | | -// console.log("### COLS=" + this.cols + " COL WIDTH=" + colWidth); |
| 658 | + // console.log("### COLS=" + this.cols + " COL WIDTH=" + colWidth + " MARGIN " + this.margin[0]); |
645 | 659 | return colWidth; |
646 | 660 | }, |
647 | 661 |
|
|
661 | 675 | let h = Math.round((height + this.margin[1]) / (this.rowHeight + this.margin[1])); |
662 | 676 |
|
663 | 677 | // Capping |
664 | | - w = Math.max(Math.min(w, this.cols - this.x), 0); |
665 | | - h = Math.max(Math.min(h, this.maxRows - this.y), 0); |
| 678 | + w = Math.max(Math.min(w, this.cols - this.innerX), 0); |
| 679 | + h = Math.max(Math.min(h, this.maxRows - this.innerY), 0); |
666 | 680 | return {w, h}; |
667 | 681 | }, |
668 | 682 | updateWidth: function (width, colNum) { |
|
0 commit comments