custom-javascript.js
3.38 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Add your custom JS here.
import jquery from 'jquery';
import LazyLoad from "vanilla-lazyload";
import DataTable from 'datatables.net-dt';
import "./_menu_mobile";
import "./_search";
import "./_header_menu";
import "./_side_menu";
import "./_image_captionation";
import "./_carousels";
var myLazyLoad = new LazyLoad();
window.tz_checkVisible = function(elm, evalType , offset, heightBuffer) {
evalType = evalType || "visible";
var vpH = jQuery(window).height(), // Viewport Height
st = jQuery(window).scrollTop(), // Scroll Top
y = jQuery(elm).offset().top + offset,
elementHeight = jQuery(elm).height();
if (heightBuffer) {
elementHeight += heightBuffer;
}
if (evalType === "visible") return ((y < (vpH + st)) && (y > (st - elementHeight)));
if (evalType === "above") return ((y < (vpH + st)));
};
jQuery(document).ready(function($) {
var itemToWatch = document.querySelector('.gt_options');
onClassChange(itemToWatch, (node) => {
node.classList.contains('gt-open')
? $('#pojo-a11y-toolbar').removeClass('pojo-a11y-toolbar-open')
: console.log('class removed');
});
trim_text();
$('#relevant-resources').dataTable( {
info: false,
ordering: false,
paging: true,
bLengthChange: false,
bFilter: false,
pagingType: "numbers",
pageLength: 10
} );
$('#relevant-resources').on( 'page.dt', function () {
$('html, body, #page').animate({
scrollTop: $("#relevant-resources").offset().top - 250
}, 100);
});
function trim_text(){
if ($(window).width() < 960) {
$( ".search-result .entry-summary, .content p" ).each(function() {
var yourString = $(this).text();
var maxLength = 160;
if (yourString.length > maxLength) {
var trimmedString = yourString.substr(0, maxLength);
trimmedString = trimmedString.substr(0, Math.min(trimmedString.length, trimmedString.lastIndexOf(" ")));
$(this).text(trimmedString + "...");
}
});
}
}
(function() {
var origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url) {
this.addEventListener('load', function() {
if(url.includes('search')){
setTimeout(function(){
$('html, body, #page').animate({
scrollTop: $("#search-wrapper").offset().top - 250
}, 100);
myLazyLoad.update();
trim_text();
}, 100);
}
});
this.addEventListener('error', function() {
});
origOpen.apply(this, arguments);
};
})();
});
document.addEventListener( 'wpcf7mailsent', function( event ) {
jQuery('.appArea.responsive').hide();
}, true );
function onClassChange(element, callback) {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (
mutation.type === 'attributes' &&
mutation.attributeName === 'class'
) {
callback(mutation.target);
}
});
});
observer.observe(element, { attributes: true });
return observer.disconnect;
}