-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
123 lines (96 loc) · 3.69 KB
/
scripts.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
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
// Jump out of scope on clicking outside (pri kliknuti mimo dropper je okno s dropdown-content zavreno)
$(document).ready(function(){
// Sets class 'active' to href attribute of dropper element (dropdown-content)
$('.dropper').click(function() {
$(this.hash).toggleClass('active').focus();
console.log("Clicked on dropper.");
});
// On focus-out, removes the 'active' class from dropdown-content AND on focus-in, stops the removal of 'active'
// Na focus-out se odstrani trida 'active' z dropdown-content, ale na focus-in se odstraneni prerusi (tzn. pri focusu-in nechci, aby se hned dropdown-content zavrel, ale chci, aby slo kliknout na link uvnitr dropdown-contentu)
$('.dropdown-content').on({
focusin: function() {
clearTimeout($(this).data("timer"));
console.log("Focused in dropdown-content");
},
focusout: function() {
$(this).data("timer", setTimeout(function() {
$(this).removeClass('active');
console.log("Focused out of dropdown-content");
}.bind(this),0));
}
});
// On focus-out of dropper, stop timer in dropdown-content (to not double-toggle it), focus-out is probably for tab users???
// na focus-in se vypne timer, aby nedoslo k togglovani dropdown-contentu 2x - ve funkci vyse a pri kliknuti na dropper
$('.dropper').on({
focusout: function() {
$(this.hash).data("timer", function(){
$(this.hash).removeClass('active');
console.log("Out of dropper");
}.bind(this), 0);
},
focusin: function() {
clearTimeout($(this.hash).data("timer"));
console.log("focused in dropper");
}
});
// On resize change the dimensions of articles
window.addEventListener('resize', function() {
countArticleDimensions();
})
});
// Calculates the dimensions of article height and image width
function countArticleDimensions() {
// Calculates the height of articles and width of images in articles (pocita velikost jednotlivych clanku a obrazku, zachovava aspect ratio OBRAZOVKY - ne obrazku!)
// Initialize variables w - width, and h - height
var w = $(window).width();
var h = $(window).height();
// Recursive function to find the biggest divider (hleda nejvetsiho spolecneho jmenovatele dvou cisel)
function gcd(a,b) {
if (b == 0) {return a;}
return gcd(b, a%b);
}
// Initializing variables and setting min and max values
var aMinHeight = 70;
var aMaxHeight = 300;
var aHeight = h/8;
var aHeightReal;
// Sets the height depending on min and max values
if (aHeight > aMinHeight) {
if (aHeight < aMaxHeight) {
aHeightReal = aHeight;
} else {
aHeightReal = aMaxHeight;
}
} else {
aHeightReal = aMinHeight;
}
// Calculates aspect ratio and image width depending on article height
var x = gcd(w,h);
console.log("Width: "+ w);
console.log("Height: " + h);
var aR = [w/x, h/x];
var maxAr = Math.max.apply(Math, aR);
var minAr = Math.min.apply(Math, aR);
var aImageWidth = aHeightReal/minAr*maxAr;
// Sets the height of article
$('.article').css('height', aHeightReal);
// Sets the width of image in article
$('.aImage').css('width', aImageWidth);
var p = 25;
$('.aImage').css('max-width', p+'%');
if ((w > h) && (w>800)) {
p = 10;
$('.aImage').css('max-width', p+'%');
} else if ((w > h) && (w<800)){
p = 12.5;
$('.aImage').css('max-width', p+'%');
}
var aImageWidthReal = Math.min((w/100*p), aImageWidth);
console.log(p);
// Sets the width of text in article
var aTextWidth = w - aImageWidthReal - w/100*15;
$('.aText').css('width', aTextWidth);
console.log("Article height: " + aHeightReal);
console.log("Image Width: " + aImageWidth);
console.log("Text Width: " + aTextWidth);
}