-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanimation-hooks.js
More file actions
79 lines (57 loc) · 2.18 KB
/
animation-hooks.js
File metadata and controls
79 lines (57 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
Animation-Helper - repackaged from Fabian Vogelsteller's Animation-Helper:
https://github.com/frozeman/meteor-animation-helper
to include SVG element support
@module package animation-hooks
**/
Template['Animate'].rendered = function(){
var animationElements = this.findAll('.animate');
// HACK: initial animation rendered, as insertElement, doesn't seem to fire
_.each(animationElements, function(item){
var $item = $(item);
$item.width(); // force-draw before animation
$item.removeClass('animate');
});
// add the parentNode te the instance, so we can access it in the destroyed function
this._animation_helper_parentNode = this.firstNode.parentNode;
this._animation_helper_parentNode._uihooks = {
insertElement: function (node, next) {
var $node = $(node);
$node.insertBefore(next);
if($node.hasClass('animate')) {
// add to animation elements array
animationElements.push(node);
// animate
$node.width(); // force-draw before animation
Meteor.defer(function(){
$node.removeClass('animate');
});
}
},
removeElement: function (node) {
var $node = $(node),
indexOfElement = _.indexOf(animationElements, node);
if(document.hasFocus() && indexOfElement !== -1) {
// remove from animation elements array
delete animationElements[indexOfElement];
$node.addClass('animate').on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function() {
$node.remove();
$node = null;
});
// otherwise remove immedediately
} else {
$node.remove();
$node = null;
}
}
};
};
/**
The destroyed method, which remove the hooks to make sure, they work again next time.
*/
Template['Animate'].destroyed = function(){
var template = this;
Meteor.defer(function(){
template._animation_helper_parentNode._uihooks = null;
});
};