-
Notifications
You must be signed in to change notification settings - Fork 218
/
tablecollapse.js
42 lines (34 loc) · 1.24 KB
/
tablecollapse.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
//Wrap the whole mess in the following function to make it work in Drupal
(function ($) {
$(document).ready(function () {
// Original tablecollapse.js functionality
// Initialize table to fadeOut
$('.toggle-table').fadeIn();
//Bind Expand-button method
$('.collapse-table-button').click(
function () {
$('.toggle-table').fadeOut();
}
);
//Bind the toggle button method
$('.toggle-button').click(
function () {
$(this).parent().find("table").fadeToggle("2000", "linear");
});
// New code-collapse functionality
var kCollapseThresholdBytes = 1024;
$(".highlight-json").each(function (index, elem) {
// Per Jen's request, here we look into the content to see how big it is,
// and if it's small, we auto-expanded the div. All .highlight-json divs
// still have the expand/collapse functionality - we just pre-expand the
// small ones.
var $elem = $(elem);
if ($elem.text().length < kCollapseThresholdBytes)
$elem.addClass("expanded");
// Attach the click handler
$elem.on("click", function (evt) {
$(evt.target).closest(".highlight-json").toggleClass("expanded");
});
});
});
})(jQuery);