Skip to content

Commit 0b3c7ed

Browse files
committed
Merge pull request #251 from huston007/master
Fixes #250
2 parents f25090f + 1ee3045 commit 0b3c7ed

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/angular-gridster.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,14 +1832,31 @@
18321832
return GridsterResizable;
18331833
}])
18341834

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+
18351852
/**
18361853
* GridsterItem directive
18371854
* @param $parse
18381855
* @param GridsterDraggable
18391856
* @param GridsterResizable
18401857
*/
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) {
18431860
return {
18441861
restrict: 'EA',
18451862
controller: 'GridsterItemCtrl',
@@ -1997,11 +2014,13 @@
19972014
}
19982015
}
19992016

2000-
$el.on(whichTransitionEvent(), function() {
2017+
var debouncedTransitionEndPublisher = gridsterDebounce(function() {
20012018
scope.$apply(function() {
20022019
scope.$broadcast('gridster-item-transition-end');
20032020
});
2004-
});
2021+
}, 10);
2022+
2023+
$el.on(whichTransitionEvent(), debouncedTransitionEndPublisher);
20052024

20062025
return scope.$on('$destroy', function() {
20072026
try {

0 commit comments

Comments
 (0)