Skip to content

Commit 730b179

Browse files
authored
Remove the need to use $scope.$apply in event functions
1 parent 6c82de4 commit 730b179

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

angular-sticky-kit.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,40 @@ angular.module("angular-sticky-kit", [])
2727
}
2828
stickyElement = element.stick_in_parent(options);
2929
if (typeof options.stick !== "undefined" && options.stick !== null) {
30-
element.on("sticky_kit:stick", options.stick);
30+
element.on("sticky_kit:stick", function(event) {
31+
var localScope = $(event.target).scope()
32+
localScope.$apply(options.stick)
33+
});
3134
}
3235
if (typeof options.unstick !== "undefined" && options.unstick !== null) {
33-
element.on("sticky_kit:unstick", options.unstick);
36+
element.on("sticky_kit:unstick", function(event) {
37+
var localScope = $(event.target).scope()
38+
localScope.$apply(options.unstick)
39+
});
3440
}
3541
if (typeof options.bottom !== "undefined" && options.bottom !== null) {
36-
element.on("sticky_kit:bottom", options.bottom);
42+
element.on("sticky_kit:bottom", function(event) {
43+
var localScope = $(event.target).scope()
44+
localScope.$apply(options.bottom)
45+
});
3746
}
3847
if (typeof options.unbottom !== "undefined" && options.unbottom !== null) {
39-
element.on("sticky_kit:unbottom", options.unbottom);
48+
element.on("sticky_kit:unbottom", function(event) {
49+
var localScope = $(event.target).scope()
50+
localScope.$apply(options.unbottom)
51+
});
4052
}
4153
if (typeof options.recalc !== "undefined" && options.recalc !== null) {
42-
element.on("sticky_kit:recalc", options.recalc);
54+
element.on("sticky_kit:recalc", function(event) {
55+
var localScope = $(event.target).scope()
56+
localScope.$apply(options.recalc)
57+
});
4358
}
4459
if (typeof options.detach !== "undefined" && options.detach !== null) {
45-
return element.on("sticky_kit:detach", options.detach);
60+
element.on("sticky_kit:detach", function(event) {
61+
var localScope = $(event.target).scope()
62+
localScope.$apply(options.detach)
63+
});
4664
}
4765
}
4866
};

0 commit comments

Comments
 (0)