This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweglot-front.js
48 lines (41 loc) · 1.72 KB
/
weglot-front.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
/**
* @file
* Weglot switcher
*/
(function() {
document.addEventListener('DOMContentLoaded', function(){
var weglotSelector = document.querySelector("#weglot-selector")
if(weglotSelector){
weglotSelector.addEventListener("click", function(e) {
this.className = this.className.indexOf("country-selector closed") < 0 ? this.className.replace("country-selector", "country-selector closed") : this.className.replace("country-selector closed", "country-selector");
var body = document.body,
html = document.documentElement;
var page_height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
var h = get_offset(this).top;
var position = window
.getComputedStyle(this)
.getPropertyValue("position");
var bottom = window
.getComputedStyle(this)
.getPropertyValue("bottom");
var top = window
.getComputedStyle(this)
.getPropertyValue("top");
if ((position != "fixed" && h > page_height / 2) || (position == "fixed" && h > 100)) {
this.className += " weg-openup";
}
return false;
});
}
function get_offset(element) {
var top = 0,
left = 0;
do {
top += element.offsetTop || 0;
left += element.offsetLeft || 0;
element = element.offsetParent;
} while (element);
return { top: top, left: left };
}
})
})()