$(function () {
const $logo = $('.brand-logo');
const $dropdown = $('#menu-dropdown');
const $dropdownParent = $dropdown.parent();
const $container = $('#menu-container');
const $menu = $('#nav-mobile');
function resizeMainMenu() {
if (!$menu.is(':visible')) {
return;
}
$dropdownParent.show();
let maxWidth = $container.width() - $logo.width() - $dropdownParent.width();
let showDropdown = false;
$menu.find('.menu-element').each(function () {
const self = $(this);
const elemId = self.data('id');
const linkedDropdown = $dropdown.find('.menu-' + elemId);
const widthDiff = maxWidth - self.width();
if (widthDiff >= 0) {
maxWidth -= self.width();
self.show();
linkedDropdown.hide();
} else {
showDropdown = true;
self.hide();
linkedDropdown.show();
}
});
if (!showDropdown) {
$dropdownParent.hide();
}
}
$(document).ready(function () {
var isRated = localStorage.getItem('user_' + Article.data().id) !== null,
articleStep = document.getElementById('article_step');
if(!isRated && articleStep){
articleStep.style.display = 'block';
}
});
$(window).load(function () {
resizeMainMenu();
});
$(window).resize(function () {
resizeMainMenu();
});
$(".article-btn_rate").click(function () {
var url = '/rate-article',
token = $('meta[name="_csrf_token"]').attr('content'),
rate = this.dataset.rate;
$.ajax({
type: 'POST',
url: url,
data: {
'id': Article.data().id,
'rate': rate,
'_csrf_token': token
},
success: function (data) {
$('meta[name="_csrf_token"]').attr('content', data);
localStorage.setItem('user_' + Article.data().id, data);
document.getElementById('article_step').style.display = 'none';
if(rate === '1'){
document.getElementById('article_step_yes').style.display = 'block';
}else{
document.getElementById('article_step_no').style.display = 'block';
$("#textarea").focus();
}
},
error: function(xhr){
document.getElementById('article_step').style.display = 'none';
document.getElementById('article_step_yes').firstElementChild.innerText = JSON.parse(xhr.responseText).text;
document.getElementById('article_step_yes').style.display = 'block';
}
});
return false;
});
$("#sendFeedbackArticle").click(function(e){
var text = '' + Article.data().title + ' ';
text += '
' + $("#textarea").val();
text = text.replace(/\n\r?/g, '
');
var url = '/send-feedback';
$.ajax({
type: 'POST',
url: url,
data: {
'id': Article.data().id,
'message': text,
},
success: function(data){
//console.log(data);
}
});
document.getElementById('article_step_no').style.display = 'none';
document.getElementById('article_step_feedback').style.display = 'block';
return false;
});
var articleData = $('#aricleData');
var Article = {
data: function() {
return {
'id': articleData.data('id'),
'base_id': articleData.data('baseid'),
'title': articleData.data('title')
}
}
};
var apiHost = articleData.data('api-host');
function addView(articleId) {
var url = '/add-view-to-article',
token = $('meta[name="_csrf_token"]').attr('content');
$.ajax({
type: 'POST',
url: url,
data: {
'id': articleId,
'_csrf_token': token
},
success: function(data){
}
});
}
if (articleData.length > 0) {
setTimeout(function (){
addView(Article.data().id);
},20000);
}
});