-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathng-slide-down.js
111 lines (111 loc) · 3.62 KB
/
ng-slide-down.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
(function () {
'use strict';
angular.module('ng-slide-down', []).directive('ngSlideDown', [
'$timeout',
function ($timeout) {
var getTemplate, link;
getTemplate = function (tElement, tAttrs) {
if (tAttrs.lazyRender !== void 0) {
return '<div ng-if=\'lazyRender\' ng-transclude></div>';
} else {
return '<div ng-transclude></div>';
}
};
link = function (scope, element, attrs, ctrl, transclude) {
var closePromise, duration, elementScope, emitOnClose, getHeight, hide, lazyRender, onClose, openPromise, show, timingFunction;
duration = attrs.duration || 1;
timingFunction = attrs.timingFunction || 'ease-in-out';
elementScope = element.scope();
emitOnClose = attrs.emitOnClose;
onClose = attrs.onClose;
lazyRender = attrs.lazyRender !== void 0;
closePromise = null;
openPromise = null;
getHeight = function (passedScope) {
var c, children, height, _i, _len;
height = 0;
children = element.children();
for (_i = 0, _len = children.length; _i < _len; _i++) {
c = children[_i];
height += c.clientHeight;
}
return '' + height + 'px';
};
show = function () {
if (closePromise) {
$timeout.cancel(closePromise);
}
if (lazyRender) {
scope.lazyRender = true;
}
return $timeout(function () {
if (openPromise) {
$timeout.cancel(openPromise);
}
element.css({ height: getHeight() });
return $timeout(function () {
element.css({
overflow: 'hidden',
transitionProperty: 'height',
transitionDuration: '' + duration + 's',
transitionTimingFunction: timingFunction
});
return openPromise = $timeout(function () {
return element.css({
overflow: 'visible',
transition: 'none',
height: 'auto'
});
}, duration * 1000, false);
}, 0, false);
}, 0, false);
};
hide = function () {
if (openPromise) {
$timeout.cancel(openPromise);
}
element.css({
overflow: 'hidden',
transitionProperty: 'height',
transitionDuration: '' + duration + 's',
transitionTimingFunction: timingFunction,
height: '0px'
});
if (emitOnClose || onClose || lazyRender) {
return closePromise = $timeout(function () {
if (emitOnClose) {
scope.$emit(emitOnClose, {});
}
if (onClose) {
elementScope.$eval(onClose);
}
if (lazyRender) {
return scope.lazyRender = false;
}
}, duration * 1000);
}
};
return scope.$watch('expanded', function (value, oldValue) {
if (value) {
return $timeout(show);
} else {
if (value != null) {
element.css({ height: getHeight() });
element[0].clientHeight;
}
return $timeout(hide, 0, false);
}
});
};
return {
restrict: 'A',
scope: { expanded: '=ngSlideDown' },
transclude: true,
link: link,
template: function (tElement, tAttrs) {
return getTemplate(tElement, tAttrs);
}
};
}
]);
}.call(this));