Skip to content

Commit fef1bb7

Browse files
committed
Merge branch 'master' of github.com:ManifestWebDesign/angular-gridster
2 parents 3f2eaf3 + 0b3c7ed commit fef1bb7

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
@@ -1842,14 +1842,31 @@
18421842
return GridsterResizable;
18431843
}])
18441844

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+
18451862
/**
18461863
* GridsterItem directive
18471864
* @param $parse
18481865
* @param GridsterDraggable
18491866
* @param GridsterResizable
18501867
*/
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) {
18531870
return {
18541871
restrict: 'EA',
18551872
controller: 'GridsterItemCtrl',
@@ -2007,11 +2024,13 @@
20072024
}
20082025
}
20092026

2010-
$el.on(whichTransitionEvent(), function() {
2027+
var debouncedTransitionEndPublisher = gridsterDebounce(function() {
20112028
scope.$apply(function() {
20122029
scope.$broadcast('gridster-item-transition-end', item);
20132030
});
2014-
});
2031+
}, 10);
2032+
2033+
$el.on(whichTransitionEvent(), debouncedTransitionEndPublisher);
20152034

20162035
return scope.$on('$destroy', function() {
20172036
try {

0 commit comments

Comments
 (0)