Files
tripwithbonus/static/js/global_js.js

290 lines
9.3 KiB
JavaScript

$(document).ready(function (){
hide_or_show_new_messages_marker()
checkStateCookie()
})
// window.onfocus = function () {
// getSocketState()
// }
window.onload = function (){
changeTopStrMobile()
middleWareJS()
openOrCloseCurtainSupportChat()
openOverlayOrClose()
goToChatIfChat()
// let body = document.querySelector("body")
// const viewPortH = body.getBoundingClientRect().height;
// const windowH = window.innerHeight;
// const browserUiBarsH = viewPortH - windowH;
// body.style.height = `calc(100vh - ${browserUiBarsH}px)`;
// let height = window.innerHeight
// document.querySelector('body').style.maxHeight = height + 'px'
// document.querySelector('body').style.height = height + 'px'
if (window.location.href.includes('profile') && !window.location.href.includes('login') && !window.location.href.includes('registration')){
let user_type = getInfoAboutUser()
if (user_type === 'mobile') {
open_curtain_w_btn_profile()
} else {
if (!window.location.href.includes('profile')){
open_curtain_w_btn_profile()
}
}
if (window.location.href.includes("profile")){
setStandartSettingsToBlockOverlay()
}
// if (window.location.href.includes("profile")){
// selectTabProfileIfHisNotSelected(url)
// }
let chats = document.querySelector(`[data-ajax-url='chats']`)
if (chats){
// deleteMarkerMessages()
}
}
}
function hide_or_show_new_messages_marker () {
if (getInfoAboutUser('screen_width') < 800){
if (window.location.href.includes("chat") || window.location.href.includes("support")){
setCokie(365,'twb_new_messages','false')
}
}
}
//
function goToChatIfChat () {
if (document.querySelector('.block-chat')){
let scroll_el = document.querySelector('.block-chat')
if (document.querySelector(".name_ticket")){
scroll_el = document.querySelector(".name_ticket")
}
let top = scroll_el.offsetTop
window.scrollTo({top:top})
document.addEventListener('focusout', function(e,scroll_el) {
window.scrollTo(scroll_el, 0)
});
}
}
function middleWareJS(){
let footer = document.querySelector("footer")
let body = document.querySelector("body")
let type = getInfoAboutUser()
// if (type !== 'mobile'){
if (document.querySelector(".menu_buttons.curtain.left") || window.location.href.includes('support') || window.location.href.includes('chat')){
footer.style.display = "none"
body.style.overflow = "hidden"
} else {
footer.style.display = ""
body.style.overflow = ""
}
// }/
}
function changeTopStrMobile (){
let body = document.querySelector("body")
// if (!window.location.href.includes("mobile")){
// if (!window.location.href.includes("mobile") && !window.location.href.includes("route_search_results")){
// window.location.href = window.location.href + `?mobile=${getInfoAboutUser() === 'mobile'}`
// }
body.style.opacity = ''
body.style.transition = '500ms'
// } else {
body.style.display = ''
body.style.transition = '500ms'
// }
}
function openOrCloseCurtainSupportChat (){
if (window.location.href.includes("support")){
let type_screen = getInfoAboutUser()
let chat_block = document.querySelector(".block-chat")
let name_ticket = document.querySelector(".name_ticket")
let str = 'menu_buttons curtain left'
if (type_screen === 'mobile'){
if (!chat_block){
str = `${str} open`
} else {
str = `${str} close`
}
} else {
str = `${str} open`
}
if (name_ticket){
str = `${str} margin`
}
document.querySelector(".menu_buttons").class = str
}
}
function openOverlayOrClose () {
if (window.location.href.includes("profile") && !window.location.href.includes("login") && !window.location.href.includes("registration")){
let overlay = document.querySelector('.block_overlay')
if (screen.width < 700){
if (!overlay.classList.contains("show")){
overlay.classList.add("show")
overlay.classList.remove("hidden")
}
}
}
}
function getTypeOfData (data) {
let type = typeof data
return type
}
function getInfoAboutUser (screen_width){
let user_type = ''
if (screen.width <= 700){
user_type = 'mobile'
} else if (screen.width > 1180) {
user_type = 'desctop'
} else if (screen.width > 700 && screen.width <= 1180) {
user_type = 'laptop'
}
if (screen_width){
return screen.width
} else {
return user_type
}
}
document.addEventListener('DOMContentLoaded', function() {
let img = document.getElementById('dropbtn_lang')
if (window.location.href.indexOf("ru") > -1){
img.style.background = "url('/static/img/svg/ru.svg')"
img.style.backgroundRepeat = "no-repeat"
img.style.backgroundPosition = "center"
// img.style.backgroundSize = '50%'
}else if(window.location.href.indexOf("en") > -1){
img.style.background = "url('/static/img/svg/gb.svg')"
img.style.backgroundRepeat = "no-repeat"
img.style.backgroundPosition = "center"
// img.style.backgroundSize = '50%'
}
let login_email = document.getElementById('login_email_input')
let registration_email = document.getElementById('registration_email_input')
if(login_email){
login_email.value = sessionStorage.getItem('email')
}else if(registration_email){
registration_email.value = sessionStorage.getItem('email')
}
});
// window.addEventListener('scroll', () => {
// // let headerBG = document.getElementById('header_bg')
// //
// // headerBG.style.backgroundColor = 'rgb(248 248 248 / 90%)'
// // headerBG.style.padding = '20px 40px'
// // headerBG.style.paddingBottom = 'padding: 10px 40px 10px 40px'
// // headerBG.style.paddingRight = 'padding: 10px 40px 10px 40px'
// // headerBG.style.paddingLeft = 'padding: 10px 40px 10px 40px'
// })
// Действия при изменении URL
function scroll_ev (event,el){
let curtain = document.querySelector(".menu_buttons.filters")
let user_type = getInfoAboutUser()
let ch = el.scrollY
let top = 293 - ch + 20
if (user_type !== 'mobile' && user_type !== 'laptop'){
if (el.scrollY === 300){
curtain.style.top = `${top}px`
} else if (el.scrollY < 300) {
curtain.style.top = `${top}px`
} else if (el.scrollY > 300){
top = 15
curtain.style.top = `${top}px`
}
if (el.scrollY === 0){
top = 293 - ch
curtain.style.top = `${top}px`
}
}
}
function checkStateCookie () {
if (!window.document.cookie.includes("allow_cookie=true")){
document.querySelector(".cookie_block").classList.add("show")
}
if (!window.document.cookie.includes("popup_show=false")){
setTimeout(() => {
document.querySelector('.popup_wrapper').classList.add('show');
}, 15000);
}
if(!window.document.cookie.includes("first_authorization=true") && window.document.getElementById('authenticated_img')){
document.querySelector(".popup_wrapper").classList.add("show")
}
if (window.document.cookie.includes("twb_new_messages=true")){
if (getInfoAboutUser('screen_width') < 800) {
let marker_new_messages = document.querySelector(".marker_messages_mobile");
if (marker_new_messages.classList.contains('hide')) {
marker_new_messages.classList.remove('hide')
marker_new_messages.classList.add('show')
}
}
} else if (window.document.cookie.includes("twb_new_messages=false")){
if (getInfoAboutUser('screen_width') < 800) {
let marker_new_messages = document.querySelector(".marker_messages_mobile");
if (marker_new_messages.classList.contains('show')) {
marker_new_messages.classList.add('hide')
marker_new_messages.classList.remove('show')
}
}
}
}
function getCsrfCookie () {
let str = window.document.cookie
str = str.split('; ');
let obj_cookie = {}
for (let i = 0;i < str.length;i++){
let cur = str[i].split('=');
obj_cookie[cur[0]] = cur[1]
}
let csrf = obj_cookie['csrftoken']
return csrf
}
function setCokie (days,name,val, url = null) {
let date = new Date();
// let days = 182;
date.setTime(+ date + (days * 86400000));
window.document.cookie = `${name}=${val}` + "; expires=" + date.toGMTString() + "; path=/";
if(name === 'allow_cookie' ){
document.querySelector(".cookie_block").classList.remove("show")
} else if(name === 'popup_show'){
document.querySelector(".popup_wrapper").classList.remove("show")
if(url){
window.location.href = url}
} else if (name === 'first_authorization'){
document.querySelector(".popup_wrapper").classList.remove("show")
}
// return value;
}
function getInCookieTime (time) {
return time * 24 * 60 * 60
}