|
140 | 140 | return this;
|
141 | 141 | };
|
142 | 142 |
|
| 143 | + GridStackDragDropPlugin.prototype.droppable = function(el, opts) { |
| 144 | + return this; |
| 145 | + }; |
| 146 | + |
| 147 | + GridStackDragDropPlugin.prototype.isDroppable = function(el) { |
| 148 | + return false; |
| 149 | + }; |
| 150 | + |
| 151 | + GridStackDragDropPlugin.prototype.on = function(el, eventName, callback) { |
| 152 | + return this; |
| 153 | + }; |
| 154 | + |
143 | 155 | /**
|
144 | 156 | * @class JQueryUIGridStackDragDropPlugin
|
145 | 157 | * jQuery UI implementation of drag'n'drop gridstack plugin.
|
|
152 | 164 | JQueryUIGridStackDragDropPlugin.prototype.constructor = JQueryUIGridStackDragDropPlugin;
|
153 | 165 |
|
154 | 166 | JQueryUIGridStackDragDropPlugin.prototype.resizable = function(el, opts) {
|
| 167 | + el = $(el); |
155 | 168 | if (opts === 'disable' || opts === 'enable') {
|
156 | 169 | el.resizable(opts);
|
157 | 170 | } else {
|
|
165 | 178 | };
|
166 | 179 |
|
167 | 180 | JQueryUIGridStackDragDropPlugin.prototype.draggable = function(el, opts) {
|
| 181 | + el = $(el); |
168 | 182 | if (opts === 'disable' || opts === 'enable') {
|
169 | 183 | el.draggable(opts);
|
170 | 184 | } else {
|
|
178 | 192 | return this;
|
179 | 193 | };
|
180 | 194 |
|
| 195 | + JQueryUIGridStackDragDropPlugin.prototype.droppable = function(el, opts) { |
| 196 | + el = $(el); |
| 197 | + if (opts === 'disable' || opts === 'enable') { |
| 198 | + el.droppable(opts); |
| 199 | + } else { |
| 200 | + el.droppable({ |
| 201 | + accept: opts.accept |
| 202 | + }); |
| 203 | + } |
| 204 | + return this; |
| 205 | + }; |
| 206 | + |
| 207 | + JQueryUIGridStackDragDropPlugin.prototype.isDroppable = function(el, opts) { |
| 208 | + el = $(el); |
| 209 | + return Boolean(el.data('droppable')); |
| 210 | + }; |
| 211 | + |
| 212 | + JQueryUIGridStackDragDropPlugin.prototype.on = function(el, eventName, callback) { |
| 213 | + $(el).on(eventName, callback); |
| 214 | + return this; |
| 215 | + }; |
| 216 | + |
181 | 217 | var idSeq = 0;
|
182 | 218 |
|
183 | 219 | var GridStackEngine = function(width, onchange, floatMode, height, items) {
|
|
765 | 801 |
|
766 | 802 | if (!self.opts.staticGrid && typeof self.opts.removable === 'string') {
|
767 | 803 | var trashZone = $(self.opts.removable);
|
768 |
| - if (!trashZone.data('droppable')) { |
769 |
| - trashZone.droppable({ |
| 804 | + if (!this.dd.isDroppable(trashZone)) { |
| 805 | + this.dd.droppable(trashZone, { |
770 | 806 | accept: '.' + self.opts.itemClass
|
771 | 807 | });
|
772 | 808 | }
|
773 |
| - trashZone |
774 |
| - .on('dropover', function(event, ui) { |
| 809 | + this.dd |
| 810 | + .on(trashZone, 'dropover', function(event, ui) { |
775 | 811 | var el = $(ui.draggable);
|
776 | 812 | var node = el.data('_gridstack_node');
|
777 | 813 | if (node._grid !== self) {
|
778 | 814 | return;
|
779 | 815 | }
|
780 | 816 | self._setupRemovingTimeout(el);
|
781 | 817 | })
|
782 |
| - .on('dropout', function(event, ui) { |
| 818 | + .on(trashZone, 'dropout', function(event, ui) { |
783 | 819 | var el = $(ui.draggable);
|
784 | 820 | var node = el.data('_gridstack_node');
|
785 | 821 | if (node._grid !== self) {
|
|
829 | 865 | }
|
830 | 866 | };
|
831 | 867 |
|
832 |
| - $(self.container).droppable({ |
833 |
| - accept: function(el) { |
834 |
| - el = $(el); |
835 |
| - var node = el.data('_gridstack_node'); |
836 |
| - if (node && node._grid === self) { |
837 |
| - return false; |
| 868 | + this.dd |
| 869 | + .droppable(self.container, { |
| 870 | + accept: function(el) { |
| 871 | + el = $(el); |
| 872 | + var node = el.data('_gridstack_node'); |
| 873 | + if (node && node._grid === self) { |
| 874 | + return false; |
| 875 | + } |
| 876 | + return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets); |
838 | 877 | }
|
839 |
| - return el.is(self.opts.acceptWidgets === true ? '.grid-stack-item' : self.opts.acceptWidgets); |
840 |
| - }, |
841 |
| - over: function(event, ui) { |
| 878 | + }) |
| 879 | + .on(self.container, 'dropover', function(event, ui) { |
842 | 880 | var offset = self.container.offset();
|
843 | 881 | var el = $(ui.draggable);
|
844 | 882 | var cellWidth = self.cellWidth();
|
|
855 | 893 | el.data('_gridstack_node_orig', origNode);
|
856 | 894 |
|
857 | 895 | el.on('drag', onDrag);
|
858 |
| - }, |
859 |
| - out: function(event, ui) { |
| 896 | + }) |
| 897 | + .on(self.container, 'dropout', function(event, ui) { |
860 | 898 | var el = $(ui.draggable);
|
861 | 899 | el.unbind('drag', onDrag);
|
862 | 900 | var node = el.data('_gridstack_node');
|
|
865 | 903 | self.placeholder.detach();
|
866 | 904 | self._updateContainerHeight();
|
867 | 905 | el.data('_gridstack_node', el.data('_gridstack_node_orig'));
|
868 |
| - }, |
869 |
| - drop: function(event, ui) { |
| 906 | + }) |
| 907 | + .on(self.container, 'drop', function(event, ui) { |
870 | 908 | self.placeholder.detach();
|
871 | 909 |
|
872 | 910 | var node = $(ui.draggable).data('_gridstack_node');
|
|
893 | 931 | self._triggerChangeEvent();
|
894 | 932 |
|
895 | 933 | self.grid.endUpdate();
|
896 |
| - } |
897 |
| - }); |
| 934 | + }); |
898 | 935 | }
|
899 | 936 | };
|
900 | 937 |
|
|
0 commit comments