|
39 | 39 | document.getElementsByTagName('head')[0].appendChild(style); |
40 | 40 | return style.sheet; |
41 | 41 | }, |
42 | | - |
| 42 | + remove_stylesheet: function(id) { |
| 43 | + $("STYLE[data-gs-id=" + id +"]").remove(); |
| 44 | + }, |
43 | 45 | insert_css_rule: function(sheet, selector, rules, index) { |
44 | 46 | if (typeof sheet.insertRule === 'function') { |
45 | 47 | sheet.insertRule(selector + '{' + rules + '}', index); |
|
463 | 465 | this.grid.get_grid_height() * (this.opts.cell_height + this.opts.vertical_margin) - |
464 | 466 | this.opts.vertical_margin); |
465 | 467 |
|
466 | | - var on_resize_handler = function() { |
| 468 | + this.on_resize_handler = function() { |
467 | 469 | if (self._is_one_column_mode()) { |
468 | 470 | if (one_column_mode) |
469 | 471 | return; |
|
506 | 508 | } |
507 | 509 | }; |
508 | 510 |
|
509 | | - $(window).resize(on_resize_handler); |
510 | | - on_resize_handler(); |
| 511 | + $(window).resize(this.on_resize_handler); |
| 512 | + this.on_resize_handler(); |
| 513 | + }; |
| 514 | + |
| 515 | + GridStack.prototype._trigger_change_event = function(forceTrigger) { |
| 516 | + var elements = this.grid.get_dirty_nodes(); |
| 517 | + var hasChanges = false; |
| 518 | + |
| 519 | + var eventParams = []; |
| 520 | + if (elements && elements.length) { |
| 521 | + eventParams.push(elements); |
| 522 | + hasChanges = true; |
| 523 | + } |
| 524 | + |
| 525 | + if (hasChanges || forceTrigger === true) { |
| 526 | + this.container.trigger('change', eventParams); |
| 527 | + } |
511 | 528 | }; |
512 | 529 |
|
513 | 530 | GridStack.prototype._init_styles = function() { |
|
638 | 655 | .attr('data-gs-height', node.height) |
639 | 656 | .removeAttr('style'); |
640 | 657 | self._update_container_height(); |
641 | | - var elements = self.grid.get_dirty_nodes(); |
642 | | - if (elements && elements.length) |
643 | | - self.container.trigger('change', [elements]); |
| 658 | + self._trigger_change_event(); |
644 | 659 |
|
645 | 660 | self.grid.end_update(); |
646 | 661 | }; |
|
704 | 719 | this.container.append(el); |
705 | 720 | this._prepare_element(el); |
706 | 721 | this._update_container_height(); |
| 722 | + this._trigger_change_event(true); |
707 | 723 |
|
708 | 724 | return el; |
709 | 725 | }; |
|
722 | 738 | this._update_container_height(); |
723 | 739 | if (detach_node) |
724 | 740 | el.remove(); |
| 741 | + this._trigger_change_event(true); |
725 | 742 | }; |
726 | 743 |
|
727 | 744 | GridStack.prototype.remove_all = function(detach_node) { |
|
732 | 749 | this._update_container_height(); |
733 | 750 | }; |
734 | 751 |
|
| 752 | + GridStack.prototype.destroy = function() { |
| 753 | + $(window).off("resize", this.on_resize_handler); |
| 754 | + this.disable(); |
| 755 | + this.container.remove(); |
| 756 | + Utils.remove_stylesheet(this._styles_id); |
| 757 | + if (this.grid) |
| 758 | + this.grid = null; |
| 759 | + }; |
| 760 | + |
735 | 761 | GridStack.prototype.resizable = function(el, val) { |
736 | 762 | el = $(el); |
737 | 763 | el.each(function(index, el) { |
|
797 | 823 | return this; |
798 | 824 | }; |
799 | 825 |
|
| 826 | + GridStack.prototype.min_height = function (el, val) { |
| 827 | + el = $(el); |
| 828 | + el.each(function (index, el) { |
| 829 | + el = $(el); |
| 830 | + var node = el.data('_gridstack_node'); |
| 831 | + if (typeof node == 'undefined' || node == null) { |
| 832 | + return; |
| 833 | + } |
| 834 | + |
| 835 | + if(!isNaN(val)){ |
| 836 | + node.min_height = (val || false); |
| 837 | + el.attr('data-gs-min-height', val); |
| 838 | + } |
| 839 | + }); |
| 840 | + return this; |
| 841 | + }; |
| 842 | + |
| 843 | + GridStack.prototype.min_width = function (el, val) { |
| 844 | + el = $(el); |
| 845 | + el.each(function (index, el) { |
| 846 | + el = $(el); |
| 847 | + var node = el.data('_gridstack_node'); |
| 848 | + if (typeof node == 'undefined' || node == null) { |
| 849 | + return; |
| 850 | + } |
| 851 | + |
| 852 | + if(!isNaN(val)){ |
| 853 | + node.min_width = (val || false); |
| 854 | + el.attr('data-gs-min-width', val); |
| 855 | + } |
| 856 | + }); |
| 857 | + return this; |
| 858 | + }; |
| 859 | + |
800 | 860 | GridStack.prototype._update_element = function(el, callback) { |
801 | 861 | el = $(el).first(); |
802 | 862 | var node = el.data('_gridstack_node'); |
|
812 | 872 | callback.call(this, el, node); |
813 | 873 |
|
814 | 874 | self._update_container_height(); |
815 | | - var elements = self.grid.get_dirty_nodes(); |
816 | | - if (elements && elements.length) |
817 | | - self.container.trigger('change', [elements]); |
| 875 | + self._trigger_change_event(); |
818 | 876 |
|
819 | 877 | self.grid.end_update(); |
820 | 878 | }; |
|
0 commit comments