forked from EricWVGG/AngularSlideables
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslideToggleContentControl.js
More file actions
72 lines (64 loc) · 2.59 KB
/
slideToggleContentControl.js
File metadata and controls
72 lines (64 loc) · 2.59 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
angular.module('slideToggleContentControl', [])
.directive('slideToggleContent', function () {
return {
restrict:'A',
compile: function (element, attr) {
// wrap tag
var contents = element.html();
element.html('<div class="slideable_content" style="margin:0 !important; padding:0 !important" >' + contents + '</div>');
return function postLink(scope, element, attrs) {
// default properties
attrs.duration = (!attrs.duration) ? '0.5s' : attrs.duration;
attrs.easing = (!attrs.easing) ? 'ease-in-out' : attrs.easing;
element.css({
'overflow': 'hidden',
'height': '0px',
'transitionProperty': 'height',
'transitionDuration': attrs.duration,
'transitionTimingFunction': attrs.easing
});
};
}
};
})
.directive('slideToggleControl', function($timeout) {
return {
restrict: 'A',
scope: {'toggled': '=?'},
link: function(scope, element, attrs) {
var target, content;
// scoped boolean variable for when the slide is toggled
scope.toggled = scope.toggled || false;
// slides the slide based on the value of toggle
function slide(toggled)
{
if (!target) target = document.querySelector(attrs.slideToggleControl);
if (!content) content = target.querySelector('.slideable_content');
if(toggled) {
content.style.border = '1px solid rgba(0,0,0,0)';
content.style.border = 0;
target.style.height = content.clientHeight + 'px';
} else {
target.style.height = '0px';
}
}
// toggles the slide
function toggle()
{
// toggle boolean first
scope.toggled = !scope.toggled;
// call the slide method
slide(scope.toggled);
}
// handle when the control is clicked
element.bind('click keypress', function() {
toggle();
});
// initialize the slide after the directive has compiled
$timeout(function(){
// slide content in or out based on scope.toggled
slide(scope.toggled)
}, 1);
}
}
});