|
635 | 635 |
|
636 | 636 | var cell_width, cell_height; |
637 | 637 |
|
| 638 | + var drag_or_resize = function(event, ui) { |
| 639 | + var x = Math.round(ui.position.left / cell_width), |
| 640 | + y = Math.floor((ui.position.top + cell_height / 2) / cell_height), |
| 641 | + width, height; |
| 642 | + if (event.type != "drag") { |
| 643 | + width = Math.round(ui.size.width / cell_width); |
| 644 | + height = Math.round(ui.size.height / cell_height); |
| 645 | + } |
| 646 | + |
| 647 | + if (!self.grid.can_move_node(node, x, y, width, height)) { |
| 648 | + return; |
| 649 | + } |
| 650 | + self.grid.move_node(node, x, y, width, height); |
| 651 | + self._update_container_height(); |
| 652 | + }; |
| 653 | + |
638 | 654 | var on_start_moving = function(event, ui) { |
639 | 655 | self.container.append(self.placeholder); |
640 | 656 | var o = $(this); |
|
652 | 668 |
|
653 | 669 | el.resizable('option', 'minWidth', Math.round(cell_width * (node.min_width || 1))); |
654 | 670 | el.resizable('option', 'minHeight', self.opts.cell_height * (node.min_height || 1)); |
| 671 | + |
| 672 | + if (event.type == 'resizestart') { |
| 673 | + o.find('.grid-stack-item').trigger('resizestart'); |
| 674 | + } |
655 | 675 | }; |
656 | 676 |
|
657 | 677 | var on_end_moving = function(event, ui) { |
|
669 | 689 | self._trigger_change_event(); |
670 | 690 |
|
671 | 691 | self.grid.end_update(); |
672 | | - }; |
673 | 692 |
|
674 | | - el.draggable(_.extend(this.opts.draggable, { |
675 | | - start: on_start_moving, |
676 | | - stop: on_end_moving, |
677 | | - drag: function(event, ui) { |
678 | | - var x = Math.round(ui.position.left / cell_width), |
679 | | - y = Math.floor((ui.position.top + cell_height / 2) / cell_height); |
680 | | - if (!self.grid.can_move_node(node, x, y, node.width, node.height)) { |
681 | | - return; |
682 | | - } |
683 | | - self.grid.move_node(node, x, y); |
684 | | - self._update_container_height(); |
685 | | - }, |
686 | | - containment: this.opts.is_nested ? this.container.parent() : null |
687 | | - })).resizable(_.extend(this.opts.resizable, { |
688 | | - start: on_start_moving, |
689 | | - stop: on_end_moving, |
690 | | - resize: function(event, ui) { |
691 | | - var x = Math.round(ui.position.left / cell_width), |
692 | | - y = Math.floor((ui.position.top + cell_height / 2) / cell_height), |
693 | | - width = Math.round(ui.size.width / cell_width), |
694 | | - height = Math.round(ui.size.height / cell_height); |
695 | | - if (!self.grid.can_move_node(node, x, y, width, height)) { |
696 | | - return; |
697 | | - } |
698 | | - self.grid.move_node(node, x, y, width, height); |
699 | | - self._update_container_height(); |
| 693 | + var nested_grids = o.find('.grid-stack'); |
| 694 | + if (nested_grids.length && event.type == 'resizestop') { |
| 695 | + nested_grids.each(function(index, el) { |
| 696 | + $(el).data('gridstack').on_resize_handler(); |
| 697 | + }); |
| 698 | + o.find('.grid-stack-item').trigger('resizestop'); |
700 | 699 | } |
701 | | - })); |
| 700 | + }; |
| 701 | + |
| 702 | + el |
| 703 | + .draggable(_.extend(this.opts.draggable, { |
| 704 | + containment: this.opts.is_nested ? this.container.parent() : null |
| 705 | + })) |
| 706 | + .on('dragstart', on_start_moving) |
| 707 | + .on('dragstop', on_end_moving) |
| 708 | + .on('drag', drag_or_resize) |
| 709 | + .resizable(_.extend(this.opts.resizable, {})) |
| 710 | + .on('resizestart', on_start_moving) |
| 711 | + .on('resizestop', on_end_moving) |
| 712 | + .on('resize', drag_or_resize); |
702 | 713 |
|
703 | 714 | if (node.no_move || this._is_one_column_mode()) { |
704 | 715 | el.draggable('disable'); |
|
980 | 991 |
|
981 | 992 | scope.GridStackUI.Utils = Utils; |
982 | 993 |
|
| 994 | + function event_stop_propagate(event) { |
| 995 | + event.stopPropagation(); |
| 996 | + } |
983 | 997 | $.fn.gridstack = function(opts) { |
984 | 998 | return this.each(function() { |
985 | | - if (!$(this).data('gridstack')) { |
986 | | - $(this).data('gridstack', new GridStack(this, opts)); |
| 999 | + var o = $(this); |
| 1000 | + if (!o.data('gridstack')) { |
| 1001 | + o |
| 1002 | + .data('gridstack', new GridStack(this, opts)) |
| 1003 | + .on('dragstart', event_stop_propagate) |
| 1004 | + .on('dragstop', event_stop_propagate) |
| 1005 | + .on('drag', event_stop_propagate) |
| 1006 | + .on('resizestart', event_stop_propagate) |
| 1007 | + .on('resizestop', event_stop_propagate) |
| 1008 | + .on('resize', event_stop_propagate) |
| 1009 | + .on('change', event_stop_propagate); |
987 | 1010 | } |
988 | 1011 | }); |
989 | 1012 | }; |
|
0 commit comments