|
1 | | -/*! gridster.js - v0.3.0 - 2013-11-19 |
| 1 | +/*! gridster.js - v0.4.0 - 2014-02-07 |
2 | 2 | * http://gridster.net/ |
3 | | -* Copyright (c) 2013 ducksboard; Licensed MIT */ |
| 3 | +* Copyright (c) 2014 ducksboard; Licensed MIT */ |
4 | 4 |
|
5 | 5 | ;(function($, window, document, undefined){ |
6 | 6 | /** |
|
324 | 324 | return setTimeout(function(){ return func.apply(null, args); }, wait); |
325 | 325 | }; |
326 | 326 |
|
327 | | - |
328 | | - /* Debounce and throttle functions taken from underscore.js */ |
| 327 | + /* Debounce and throttle functions taken from underscore.js |
| 328 | + * |
| 329 | + * Copyright (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and |
| 330 | + * Investigative Reporters & Editors |
| 331 | + * |
| 332 | + * Permission is hereby granted, free of charge, to any person |
| 333 | + * obtaining a copy of this software and associated documentation |
| 334 | + * files (the "Software"), to deal in the Software without |
| 335 | + * restriction, including without limitation the rights to use, |
| 336 | + * copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 337 | + * copies of the Software, and to permit persons to whom the |
| 338 | + * Software is furnished to do so, subject to the following |
| 339 | + * conditions: |
| 340 | + * |
| 341 | + * The above copyright notice and this permission notice shall be |
| 342 | + * included in all copies or substantial portions of the Software. |
| 343 | + * |
| 344 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 345 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 346 | + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 347 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 348 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 349 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 350 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 351 | + * OTHER DEALINGS IN THE SOFTWARE. |
| 352 | + */ |
| 353 | + |
329 | 354 | window.debounce = function(func, wait, immediate) { |
330 | 355 | var timeout; |
331 | 356 | return function() { |
|
340 | 365 | }; |
341 | 366 | }; |
342 | 367 |
|
343 | | - |
344 | 368 | window.throttle = function(func, wait) { |
345 | 369 | var context, args, timeout, throttling, more, result; |
346 | 370 | var whenDone = debounce( |
|
787 | 811 | }, |
788 | 812 | resize: { |
789 | 813 | enabled: false, |
790 | | - axes: ['x', 'y', 'both'], |
| 814 | + axes: ['both'], |
791 | 815 | handle_append_to: '', |
792 | 816 | handle_class: 'gs-resize-handle', |
793 | 817 | max_size: [Infinity, Infinity] |
|
852 | 876 | * @param {Array} [options.resize.max_size] Limit widget dimensions |
853 | 877 | * when resizing. Array values should be integers: |
854 | 878 | * `[max_cols_occupied, max_rows_occupied]` |
| 879 | + * @param {Array} [options.resize.min_size] Limit widget dimensions |
| 880 | + * when resizing. Array values should be integers: |
| 881 | + * `[min_cols_occupied, min_rows_occupied]` |
855 | 882 | * @param {Function} [options.resize.start] Function executed |
856 | 883 | * when resizing starts. |
857 | 884 | * @param {Function} [otions.resize.resize] Function executed |
|
862 | 889 | * @constructor |
863 | 890 | */ |
864 | 891 | function Gridster(el, options) { |
865 | | - this.options = $.extend(true, defaults, options); |
| 892 | + this.options = $.extend(true, {}, defaults, options); |
866 | 893 | this.$el = $(el); |
867 | 894 | this.$wrapper = this.$el.parent(); |
868 | 895 | this.$widgets = this.$el.children( |
|
962 | 989 | * @param {Number} [col] The column the widget should start in. |
963 | 990 | * @param {Number} [row] The row the widget should start in. |
964 | 991 | * @param {Array} [max_size] max_size Maximun size (in units) for width and height. |
| 992 | + * @param {Array} [min_size] min_size Minimum size (in units) for width and height. |
965 | 993 | * @return {HTMLElement} Returns the jQuery wrapped HTMLElement representing. |
966 | 994 | * the widget that was just created. |
967 | 995 | */ |
968 | | - fn.add_widget = function(html, size_x, size_y, col, row, max_size) { |
| 996 | + fn.add_widget = function(html, size_x, size_y, col, row, max_size, min_size) { |
969 | 997 | var pos; |
970 | 998 | size_x || (size_x = 1); |
971 | 999 | size_y || (size_y = 1); |
|
999 | 1027 | this.set_widget_max_size($w, max_size); |
1000 | 1028 | } |
1001 | 1029 |
|
| 1030 | + if (min_size) { |
| 1031 | + this.set_widget_min_size($w, min_size); |
| 1032 | + } |
| 1033 | + |
1002 | 1034 | this.set_dom_grid_height(); |
1003 | 1035 |
|
1004 | 1036 | return $w.fadeIn(); |
1005 | 1037 | }; |
1006 | 1038 |
|
1007 | 1039 |
|
| 1040 | + /** |
| 1041 | + * Change widget size limits. |
| 1042 | + * |
| 1043 | + * @method set_widget_min_size |
| 1044 | + * @param {HTMLElement|Number} $widget The jQuery wrapped HTMLElement |
| 1045 | + * representing the widget or an index representing the desired widget. |
| 1046 | + * @param {Array} min_size Minimum size (in units) for width and height. |
| 1047 | + * @return {HTMLElement} Returns instance of gridster Class. |
| 1048 | + */ |
| 1049 | + fn.set_widget_min_size = function($widget, min_size) { |
| 1050 | + $widget = typeof $widget === 'number' ? |
| 1051 | + this.$widgets.eq($widget) : $widget; |
| 1052 | + |
| 1053 | + if (!$widget.length) { return this; } |
| 1054 | + |
| 1055 | + var wgd = $widget.data('coords').grid; |
| 1056 | + wgd.min_size_x = min_size[0]; |
| 1057 | + wgd.min_size_y = min_size[1]; |
| 1058 | + |
| 1059 | + return this; |
| 1060 | + }; |
| 1061 | + |
| 1062 | + |
1008 | 1063 | /** |
1009 | 1064 | * Change widget size limits. |
1010 | 1065 | * |
|
1432 | 1487 | 'size_y': parseInt($el.attr('data-sizey'), 10), |
1433 | 1488 | 'max_size_x': parseInt($el.attr('data-max-sizex'), 10) || false, |
1434 | 1489 | 'max_size_y': parseInt($el.attr('data-max-sizey'), 10) || false, |
| 1490 | + 'min_size_x': parseInt($el.attr('data-min-sizex'), 10) || false, |
| 1491 | + 'min_size_y': parseInt($el.attr('data-min-sizey'), 10) || false, |
1435 | 1492 | 'el': $el |
1436 | 1493 | }; |
1437 | 1494 |
|
|
1812 | 1869 | this.options.max_cols - this.resize_initial_col + 1); |
1813 | 1870 | this.resize_max_size_y = this.resize_wgd.max_size_y || |
1814 | 1871 | this.options.resize.max_size[1]; |
| 1872 | + |
| 1873 | + this.resize_min_size_x = (this.resize_wgd.min_size_x || |
| 1874 | + this.options.resize.min_size[0] || 1); |
| 1875 | + this.resize_min_size_y = (this.resize_wgd.min_size_y || |
| 1876 | + this.options.resize.min_size[1] || 1); |
| 1877 | + |
1815 | 1878 | this.resize_initial_last_col = this.get_highest_occupied_cell().col; |
1816 | 1879 |
|
1817 | 1880 | this.resize_dir = { |
|
1904 | 1967 | var size_x = Math.max(1, this.resize_initial_sizex + inc_units_x); |
1905 | 1968 | var size_y = Math.max(1, this.resize_initial_sizey + inc_units_y); |
1906 | 1969 |
|
1907 | | - size_x = Math.min(size_x, this.resize_max_size_x); |
| 1970 | + size_x = Math.max(Math.min(size_x, this.resize_max_size_x), this.resize_min_size_x); |
1908 | 1971 | max_width = (this.resize_max_size_x * wbd_x) + |
1909 | 1972 | ((size_x - 1) * this.options.widget_margins[0] * 2); |
| 1973 | + min_width = (this.resize_min_size_x * wbd_x) + |
| 1974 | + ((size_x - 1) * this.options.widget_margins[0] * 2); |
1910 | 1975 |
|
1911 | | - size_y = Math.min(size_y, this.resize_max_size_y); |
| 1976 | + size_y = Math.max(Math.min(size_y, this.resize_max_size_y), this.resize_min_size_y); |
1912 | 1977 | max_height = (this.resize_max_size_y * wbd_y) + |
1913 | 1978 | ((size_y - 1) * this.options.widget_margins[1] * 2); |
1914 | | - |
| 1979 | + min_height = (this.resize_min_size_y * wbd_y) + |
| 1980 | + ((size_y - 1) * this.options.widget_margins[1] * 2); |
1915 | 1981 |
|
1916 | 1982 | if (this.resize_dir.right) { |
1917 | 1983 | size_y = this.resize_initial_sizey; |
|
1934 | 2000 |
|
1935 | 2001 |
|
1936 | 2002 | var css_props = {}; |
1937 | | - !this.resize_dir.bottom && (css_props.width = Math.min( |
1938 | | - this.resize_initial_width + rel_x, max_width)); |
1939 | | - !this.resize_dir.right && (css_props.height = Math.min( |
1940 | | - this.resize_initial_height + rel_y, max_height)); |
| 2003 | + !this.resize_dir.bottom && (css_props.width = Math.max(Math.min( |
| 2004 | + this.resize_initial_width + rel_x, max_width), min_width)); |
| 2005 | + !this.resize_dir.right && (css_props.height = Math.max(Math.min( |
| 2006 | + this.resize_initial_height + rel_y, max_height), min_height)); |
1941 | 2007 |
|
1942 | 2008 | this.$resized_widget.css(css_props); |
1943 | 2009 |
|
|
0 commit comments