|
1842 | 1842 | return GridsterResizable; |
1843 | 1843 | }]) |
1844 | 1844 |
|
| 1845 | + .factory('gridsterDebounce', function () { |
| 1846 | + return function gridsterDebounce(func, wait, immediate) { |
| 1847 | + var timeout; |
| 1848 | + return function() { |
| 1849 | + var context = this, args = arguments; |
| 1850 | + var later = function() { |
| 1851 | + timeout = null; |
| 1852 | + if (!immediate) func.apply(context, args); |
| 1853 | + }; |
| 1854 | + var callNow = immediate && !timeout; |
| 1855 | + clearTimeout(timeout); |
| 1856 | + timeout = setTimeout(later, wait); |
| 1857 | + if (callNow) func.apply(context, args); |
| 1858 | + }; |
| 1859 | + }; |
| 1860 | + }) |
| 1861 | + |
1845 | 1862 | /** |
1846 | 1863 | * GridsterItem directive |
1847 | 1864 | * @param $parse |
1848 | 1865 | * @param GridsterDraggable |
1849 | 1866 | * @param GridsterResizable |
1850 | 1867 | */ |
1851 | | - .directive('gridsterItem', ['$parse', '$rootScope', 'GridsterDraggable', 'GridsterResizable', |
1852 | | - function($parse, $rootScope, GridsterDraggable, GridsterResizable) { |
| 1868 | + .directive('gridsterItem', ['$parse', '$rootScope', 'GridsterDraggable', 'GridsterResizable', 'gridsterDebounce', |
| 1869 | + function($parse, $rootScope, GridsterDraggable, GridsterResizable, gridsterDebounce) { |
1853 | 1870 | return { |
1854 | 1871 | restrict: 'EA', |
1855 | 1872 | controller: 'GridsterItemCtrl', |
|
2007 | 2024 | } |
2008 | 2025 | } |
2009 | 2026 |
|
2010 | | - $el.on(whichTransitionEvent(), function() { |
| 2027 | + var debouncedTransitionEndPublisher = gridsterDebounce(function() { |
2011 | 2028 | scope.$apply(function() { |
2012 | 2029 | scope.$broadcast('gridster-item-transition-end', item); |
2013 | 2030 | }); |
2014 | | - }); |
| 2031 | + }, 10); |
| 2032 | + |
| 2033 | + $el.on(whichTransitionEvent(), debouncedTransitionEndPublisher); |
2015 | 2034 |
|
2016 | 2035 | return scope.$on('$destroy', function() { |
2017 | 2036 | try { |
|
0 commit comments