Skip to content

Commit 3f2eaf3

Browse files
committed
normalize item and gridster events
1 parent f25090f commit 3f2eaf3

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

src/angular-gridster.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
this.grid.length = 0;
8080
this.grid = null;
8181
}
82+
this.$element = null;
8283
};
8384

8485
/**
@@ -557,6 +558,7 @@
557558

558559
return function(scope, $elem, attrs, gridster) {
559560
gridster.loaded = false;
561+
gridster.$element = $elem;
560562

561563
scope.gridsterClass = function() {
562564
return {
@@ -641,24 +643,32 @@
641643
scope.$watch(function() {
642644
return gridster.isMobile;
643645
}, function() {
644-
$rootScope.$broadcast('gridster-mobile-changed');
646+
$rootScope.$broadcast('gridster-mobile-changed', gridster);
645647
});
646648

647-
scope.$watch('config.draggable', function() {
648-
$rootScope.$broadcast('gridster-draggable-changed');
649+
scope.$watch(function() {
650+
return gridster.draggable;
651+
}, function() {
652+
$rootScope.$broadcast('gridster-draggable-changed', gridster);
649653
}, true);
650654

651-
scope.$watch('config.resizable', function() {
652-
$rootScope.$broadcast('gridster-resizable-changed');
655+
scope.$watch(function() {
656+
return gridster.resizable;
657+
}, function(resizable) {
658+
$rootScope.$broadcast('gridster-resizable-changed', gridster);
653659
}, true);
654660

655661
var updateHeight = function() {
656662
$elem.css('height', (gridster.gridHeight * gridster.curRowHeight) + (gridster.outerMargin ? gridster.margins[0] : -gridster.margins[0]) + 'px');
657663
};
658664

659-
scope.$watch('gridster.gridHeight', updateHeight);
665+
scope.$watch(function() {
666+
return gridster.gridHeight;
667+
}, updateHeight);
660668

661-
scope.$watch('gridster.movingItem', function() {
669+
scope.$watch(function() {
670+
return gridster.movingItem;
671+
}, function() {
662672
gridster.updateHeight(gridster.movingItem ? gridster.movingItem.sizeY : 0);
663673
});
664674

@@ -682,7 +692,7 @@
682692
$elem.addClass('gridster-loaded');
683693
}
684694

685-
scope.$parent.$broadcast('gridster-resized', [width, $elem[0].offsetHeight]);
695+
$rootScope.$broadcast('gridster-resized', [width, $elem[0].offsetHeight], gridster);
686696
}
687697

688698
// track element width changes any way we can
@@ -1562,7 +1572,7 @@
15621572
savedDraggable = gridster.draggable.enabled;
15631573
if (savedDraggable) {
15641574
gridster.draggable.enabled = false;
1565-
scope.$broadcast('gridster-draggable-changed');
1575+
scope.$broadcast('gridster-draggable-changed', gridster);
15661576
}
15671577

15681578
// Get the current mouse position.
@@ -1681,7 +1691,7 @@
16811691
// restore draggable setting to its original state
16821692
if (gridster.draggable.enabled !== savedDraggable) {
16831693
gridster.draggable.enabled = savedDraggable;
1684-
scope.$broadcast('gridster-draggable-changed');
1694+
scope.$broadcast('gridster-draggable-changed', gridster);
16851695
}
16861696

16871697
mOffX = mOffY = 0;
@@ -1926,7 +1936,7 @@
19261936
}
19271937
});
19281938

1929-
scope.$broadcast('gridster-item-initialized', [item.sizeY, item.sizeX, item.getElementSizeY(), item.getElementSizeX()]);
1939+
scope.$broadcast('gridster-item-initialized', item);
19301940

19311941
function positionChanged() {
19321942
// call setPosition so the element and gridster controller are updated
@@ -1957,10 +1967,10 @@
19571967
if (changedX || changedY) {
19581968
item.gridster.moveOverlappingItems(item);
19591969
gridster.layoutChanged();
1970+
$rootScope.$broadcast('gridster-item-resized', item);
19601971
}
1961-
1962-
$rootScope.$broadcast('gridster-item-size-changed', item.sizeX, item.sizeY);
19631972
}
1973+
19641974
scope.$watch(function() {
19651975
return item.sizeY + ',' + item.sizeX + ',' + item.minSizeX + ',' + item.maxSizeX + ',' + item.minSizeY + ',' + item.maxSizeY;
19661976
}, sizeChanged);
@@ -1999,7 +2009,7 @@
19992009

20002010
$el.on(whichTransitionEvent(), function() {
20012011
scope.$apply(function() {
2002-
scope.$broadcast('gridster-item-transition-end');
2012+
scope.$broadcast('gridster-item-transition-end', item);
20032013
});
20042014
});
20052015

0 commit comments

Comments
 (0)