|
664 | 664 |
|
665 | 665 | $(window).resize(this.onResizeHandler); |
666 | 666 | this.onResizeHandler(); |
| 667 | + |
| 668 | + if (typeof self.opts.removable === 'string') { |
| 669 | + var trashZone = $(self.opts.removable); |
| 670 | + if (!trashZone.data('droppable')) { |
| 671 | + trashZone.droppable({}); |
| 672 | + } |
| 673 | + trashZone |
| 674 | + .on('dropover', function(event, ui) { |
| 675 | + var el = $(ui.draggable); |
| 676 | + var node = el.data('_gridstack_node'); |
| 677 | + if (node._grid !== self) { |
| 678 | + return; |
| 679 | + } |
| 680 | + self._setupRemovingTimeout(el); |
| 681 | + }) |
| 682 | + .on('dropout', function(event, ui) { |
| 683 | + var el = $(ui.draggable); |
| 684 | + var node = el.data('_gridstack_node'); |
| 685 | + if (node._grid !== self) { |
| 686 | + return; |
| 687 | + } |
| 688 | + self._clearRemovingTimeout(el); |
| 689 | + }); |
| 690 | + } |
667 | 691 | }; |
668 | 692 |
|
669 | 693 | GridStack.prototype._triggerChangeEvent = function(forceTrigger) { |
|
799 | 823 | this.opts.minWidth; |
800 | 824 | }; |
801 | 825 |
|
| 826 | + GridStack.prototype._setupRemovingTimeout = function(el) { |
| 827 | + var self = this; |
| 828 | + var node = $(el).data('_gridstack_node'); |
| 829 | + |
| 830 | + if (node._removeTimeout || !self.opts.removable) { |
| 831 | + return; |
| 832 | + } |
| 833 | + node._removeTimeout = setTimeout(function() { |
| 834 | + el.addClass('grid-stack-item-removing'); |
| 835 | + node._isAboutToRemove = true; |
| 836 | + }, self.opts.removeTimeout); |
| 837 | + }; |
| 838 | + |
| 839 | + GridStack.prototype._clearRemovingTimeout = function(el) { |
| 840 | + var self = this; |
| 841 | + var node = $(el).data('_gridstack_node'); |
| 842 | + |
| 843 | + if (!node._removeTimeout) { |
| 844 | + return; |
| 845 | + } |
| 846 | + clearTimeout(node._removeTimeout); |
| 847 | + node._removeTimeout = null; |
| 848 | + el.removeClass('grid-stack-item-removing'); |
| 849 | + node._isAboutToRemove = false; |
| 850 | + }; |
| 851 | + |
802 | 852 | GridStack.prototype._prepareElement = function(el, triggerAddEvent) { |
803 | 853 | triggerAddEvent = typeof triggerAddEvent != 'undefined' ? triggerAddEvent : false; |
804 | 854 | var self = this; |
|
819 | 869 | noMove: Utils.toBool(el.attr('data-gs-no-move')), |
820 | 870 | locked: Utils.toBool(el.attr('data-gs-locked')), |
821 | 871 | el: el, |
822 | | - id: el.attr('data-gs-id') |
| 872 | + id: el.attr('data-gs-id'), |
| 873 | + _grid: self |
823 | 874 | }, triggerAddEvent); |
824 | 875 | el.data('_gridstack_node', node); |
825 | 876 |
|
826 | 877 | var cellWidth; |
827 | 878 | var cellHeight; |
828 | | - var removeTimeout; |
829 | | - |
830 | | - var setupRemovingTimeout = function() { |
831 | | - if (removeTimeout || !self.opts.removable) { |
832 | | - return; |
833 | | - } |
834 | | - removeTimeout = setTimeout(function() { |
835 | | - el.addClass('grid-stack-item-removing'); |
836 | | - node._isAboutToRemove = true; |
837 | | - }, self.opts.removeTimeout); |
838 | | - }; |
839 | | - var clearRemovingTimeout = function() { |
840 | | - if (!removeTimeout) { |
841 | | - return; |
842 | | - } |
843 | | - clearTimeout(removeTimeout); |
844 | | - removeTimeout = null; |
845 | | - el.removeClass('grid-stack-item-removing'); |
846 | | - node._isAboutToRemove = false; |
847 | | - }; |
848 | 879 |
|
849 | 880 | var dragOrResize = function(event, ui) { |
850 | 881 | var x = Math.round(ui.position.left / cellWidth); |
|
859 | 890 |
|
860 | 891 | if (event.type == 'drag') { |
861 | 892 | if (x < 0 || x >= self.grid.width || y < 0) { |
862 | | - setupRemovingTimeout(); |
| 893 | + if (self.opts.removable === true) { |
| 894 | + self._setupRemovingTimeout(el); |
| 895 | + } |
863 | 896 |
|
864 | 897 | x = node._beforeDragX; |
865 | 898 | y = node._beforeDragY; |
|
871 | 904 |
|
872 | 905 | node._temporaryRemoved = true; |
873 | 906 | } else { |
874 | | - clearRemovingTimeout(); |
| 907 | + self._clearRemovingTimeout(el); |
875 | 908 |
|
876 | 909 | if (node._temporaryRemoved) { |
877 | 910 | self.grid.addNode(node); |
|
937 | 970 | el.removeData('_gridstack_node'); |
938 | 971 | el.remove(); |
939 | 972 | } else { |
940 | | - clearRemovingTimeout(); |
| 973 | + self._clearRemovingTimeout(el); |
941 | 974 | if (!node._temporaryRemoved) { |
942 | 975 | o |
943 | 976 | .attr('data-gs-x', node.x) |
|
0 commit comments