-
Notifications
You must be signed in to change notification settings - Fork 0
/
expanding_formatter.js
90 lines (86 loc) · 2.71 KB
/
expanding_formatter.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
(function ($) {
/**
* Logic for expanding/collapsing fields that configured with a toggle.
*/
Backdrop.behaviors.expandingFormatter = {
attach: function (context) {
$('.expanding-formatter:has("> .expanding-formatter-summary")').once('expanding-formatter', function () {
var $formatter = $(this).removeClass('expanded collapsed');
var $content = $formatter.find('.expanding-formatter-content');
var $trigger = $formatter.find('.expanding-formatter-trigger a');
var data = $formatter.data();
if (!data.effect) {
data.effect = 'normal';
}
$content.hide();
$formatter.addClass('collapsed');
data = $.extend({}, data, {
$formatter: $formatter,
$content: $content,
$trigger: $trigger
});
$trigger.on('click', function (event) {
event.preventDefault();
data.expanded = $formatter.hasClass('expanded');
// CSS effects.
Backdrop.behaviors.expandingFormatter.expandingFormatterEffects(data);
});
});
},
expandingFormatterEffects: function (data) {
const effect = data.effect;
const action = data.expanded ? 'collapse' : 'expand';
switch (effect) {
case 'fade':
data.$formatter.addClass('fading');
setTimeout(function () {
data.$formatter.removeClass('fading');
}, 250);
break;
case 'slide':
// Add/remove animation classes to assist with styles.
data.$formatter.addClass('sliding');
setTimeout(function () {
data.$formatter.removeClass('sliding');
}, 250);
break;
default:
if (data.expanded) {
data.$formatter
.removeClass('expanded')
.addClass('collapsed');
//data.$content.hide();
}
else {
data.$formatter
.removeClass('collapsed')
.addClass('expanded');
//data.$content.show();
}
break;
}
switch (action) {
case 'collapse':
data.$formatter
.removeClass('expanded')
.addClass('collapsed')
.trigger('collapsed', [data]);
data.$trigger.text(data.expandedLabel);
data.$content.hide();
break;
case 'expand':
data.$formatter
.removeClass('collapsed')
.addClass('expanded');
data.$content.show();
if (data.collapsedLabel) {
data.$trigger.text(data.collapsedLabel);
}
else {
data.$trigger.hide();
}
break;
}
},
};
})(jQuery);