custom-javascript.js
5.44 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Add your custom JS here.
//In order to do that we have to flex:1 each item.. see flexMatrix
function correctDropdownMenuItemGaps() {
var drop_index = 0;
jQuery('#main-menu > li').each(function () {
var dropdown = jQuery(this).find('.dropdown-menu');
consecutive_normals = 0;
if (dropdown.length > 0) {
var items = jQuery(dropdown).find('li'),
idx = 0,
total_width = 0;
items.each(function (item) {
++idx;
if (flexMatrix(items, idx)) {
items.eq(idx - 1).css('flex', 1);
total_width += items.eq(idx - 1).width();
// if(drop_idx == 2) {
// console.log(total_width)
// }
}
});
if (drop_index >= 3) {
jQuery(this).find('.dropdown-shadow').css('width', total_width);
} else {
jQuery(this).find('.dropdown-shadow').css('width', total_width);
}
}
++drop_index;
});
}
var consecutive_normals = 0;
//Returns true if this menu item should flex:1, it's true if an image is the next item and this item is not a 3rd.. etc.
function flexMatrix(items, current_idx) {
var last_item = items.eq(current_idx - 2);
var next_item = items.eq(current_idx);
var item = items.eq(current_idx - 1);
//if the last item was an image we started a new col so do not break here unless its the last one
if (last_item) {
if (jQuery(last_item).find('img').length > 0 && !next_item) {
return false;
}
}
//if the next item is an image item or this is the last one
if (next_item) {
if (jQuery(next_item).find('img').length > 0) {
consecutive_normals = 0;
return true;
}
}
//last item flex it
if (items.length === current_idx) {
return true;
}
if (jQuery(item).hasClass('break-here')) {
consecutive_normals = 0;
return true;
}
//If this is an image item flex
if (jQuery(item).find('img').length > 0) {
consecutive_normals = 0;
return true;
}
++consecutive_normals;
//If this is a 3rd consecutive normal item
if (consecutive_normals == 3) {
consecutive_normals = 0;
return true;
}
}
//This adjusts the menu dropdown location to never go past the inner edge of the Donate Now button
//and line up with it if so
function lineUpThePositionsOfTheDropdowns() {
var menu_item_widths = [];
jQuery('#main-menu > li').each(function () {
menu_item_widths.push(jQuery(this).outerWidth());
});
//Remove the donate button
menu_item_widths.pop();
var idx = 0;
jQuery('#main-menu > li').each(function () {
if (jQuery(this).find('.dropdown-menu').length > 0) {
if (idx == 0) {
jQuery(this).find('.dropdown-menu').css('left', -100);
} else {
jQuery(this).find('.dropdown-menu').css('right', -100);
}
}
++idx;
});
}
var HeaderMenu = function () {
return {
alignTheSideCaptions: function () {
jQuery('.side-caption').each(function () {
var that = this;
var _bottom = jQuery(this).find('.image-side-caption').innerHeight();
if (!Responsive.isDesktop()) {
if (jQuery(that).parent().is('.entry-header') && !jQuery(that).parent().is('.no-photo')) {
jQuery(that).css('margin-bottom', -_bottom);
var _bottom = jQuery(that).parent().find('.title-container').innerHeight();
jQuery(that).css('bottom', _bottom);
setTimeout(function () {
jQuery(that).addClass('ready');
}, 500);
} else {
jQuery(that).css('bottom', -_bottom);
setTimeout(function () {
jQuery(that).addClass('ready');
}, 500);
}
} else {
jQuery(this).css('bottom', -_bottom);
setTimeout(function () {
jQuery(that).addClass('ready');
}, 500);
}
});
}
};
}();
jQuery(function ($) {
correctDropdownMenuItemGaps();
lineUpThePositionsOfTheDropdowns();
setInterval(function () {
HeaderMenu.alignTheSideCaptions();
}, 1000);
$('.copy-link').on('click', function (e) {
e.preventDefault();
});
var body = document.getElementsByTagName("BODY")[0];
body.offsetWidth;
if (window.addEventListener) {
// all browsers except IE before version 9
window.addEventListener("resize", onResizeEvent, true);
} else {
if (window.attachEvent) {
// IE before version 9
window.attachEvent("onresize", onResizeEvent);
}
}
function onResizeEvent() {
// bodyElement = document.getElementsByTagName("BODY")[0];
// newWidth = bodyElement.offsetWidth;
// if(newWidth != width){
// width = newWidth;
// }
}
});