jQuery(document).ready(function ($){
$('.widget-header').click(function (){
$(this).parent().find('.widget-header + div').toggleClass('open');
});
const windowWidth=$(window).width();
if(windowWidth > 767){
if($('#back-to-top').length){
const scrollTrigger=1500,
backToTop=function (){
const scrollTop=$(window).scrollTop();
if(scrollTop > scrollTrigger&&windowWidth > 767){
$('#back-to-top').addClass('show');
}else{
$('#back-to-top').removeClass('show');
}};
backToTop();
$(window).on('scroll', function (){
backToTop();
});
$('#back-to-top').click(function (e){
e.preventDefault();
$('html,body').animate({
scrollTop: 0
}, 700);
});
}}
$(window).resize(function (){
const loginForm=$('.floatform');
if(windowWidth < 768){
loginForm.css('margin-left', -160 - (windowWidth * 0.03));
}});
$(window).resize();
$('input#document, input#presentation').change(function(){
const label=$(this).parent().find('label');
if(this.files.length===0){
label.text(label.data('default'));
}else{
const file=this.files[0];
const name=file.name;
const size=(file.size / 1048576).toFixed(3);
if(size > 30){
alert('Максимальний розмір файлу 30 МБ');
label.text(label.data('default'));
this.value='';
return false;
}
label.text(name + '(' + size + 'МБ)');
}});
$('#search-filter select').each(function(){
const $this=$(this);
const numberOfOptions=$(this).children('option').length;
$this.addClass('select-hidden');
$this.wrap('<div class="select"></div>');
$this.after('<div class="select-styled"></div>');
const $styledSelect=$this.next('div.select-styled');
$styledSelect.text($this.children('option').eq(0).text());
const $list=$('<ul />', {
'class': 'select-options'
}).insertAfter($styledSelect);
for (let i=0; i < numberOfOptions; i++){
$('<li />', {
text: $this.children('option').eq(i).text(),
rel: $this.children('option').eq(i).val()
}).appendTo($list);
}
if($this.val()){
const select_name=$this.attr('name');
const text=$('select[name="' + select_name + '"] :selected').text();
$styledSelect.text(text);
}
$styledSelect.click(function(e){
e.stopPropagation();
$('div.select-styled.active').not(this).each(function(){
$(this).removeClass('active').next('ul.select-options').hide();
});
$(this).toggleClass('active').next('ul.select-options').toggle();
});
const $listItems=$list.children('li');
$listItems.click(function(e){
e.stopPropagation();
$styledSelect.text($(this).text()).removeClass('active');
$this.val($(this).attr('rel'));
$this.trigger('change');
$list.hide();
});
});
});