|
1832 | 1832 | return GridsterResizable; |
1833 | 1833 | }]) |
1834 | 1834 |
|
| 1835 | + .factory('gridsterDebounce', function () { |
| 1836 | + return function gridsterDebounce(func, wait, immediate) { |
| 1837 | + var timeout; |
| 1838 | + return function() { |
| 1839 | + var context = this, args = arguments; |
| 1840 | + var later = function() { |
| 1841 | + timeout = null; |
| 1842 | + if (!immediate) func.apply(context, args); |
| 1843 | + }; |
| 1844 | + var callNow = immediate && !timeout; |
| 1845 | + clearTimeout(timeout); |
| 1846 | + timeout = setTimeout(later, wait); |
| 1847 | + if (callNow) func.apply(context, args); |
| 1848 | + }; |
| 1849 | + }; |
| 1850 | + }) |
| 1851 | + |
1835 | 1852 | /** |
1836 | 1853 | * GridsterItem directive |
1837 | 1854 | * @param $parse |
1838 | 1855 | * @param GridsterDraggable |
1839 | 1856 | * @param GridsterResizable |
1840 | 1857 | */ |
1841 | | - .directive('gridsterItem', ['$parse', '$rootScope', 'GridsterDraggable', 'GridsterResizable', |
1842 | | - function($parse, $rootScope, GridsterDraggable, GridsterResizable) { |
| 1858 | + .directive('gridsterItem', ['$parse', '$rootScope', 'GridsterDraggable', 'GridsterResizable', 'gridsterDebounce', |
| 1859 | + function($parse, $rootScope, GridsterDraggable, GridsterResizable, gridsterDebounce) { |
1843 | 1860 | return { |
1844 | 1861 | restrict: 'EA', |
1845 | 1862 | controller: 'GridsterItemCtrl', |
|
1997 | 2014 | } |
1998 | 2015 | } |
1999 | 2016 |
|
2000 | | - $el.on(whichTransitionEvent(), function() { |
| 2017 | + var debouncedTransitionEndPublisher = gridsterDebounce(function() { |
2001 | 2018 | scope.$apply(function() { |
2002 | 2019 | scope.$broadcast('gridster-item-transition-end'); |
2003 | 2020 | }); |
2004 | | - }); |
| 2021 | + }, 10); |
| 2022 | + |
| 2023 | + $el.on(whichTransitionEvent(), debouncedTransitionEndPublisher); |
2005 | 2024 |
|
2006 | 2025 | return scope.$on('$destroy', function() { |
2007 | 2026 | try { |
|
0 commit comments