Add cookie handler class.

This commit is contained in:
kovacsv 2021-06-17 15:18:55 +02:00
parent 7ba71dcf12
commit 1fd57bcbc2
6 changed files with 100 additions and 1 deletions

View File

@ -63,6 +63,7 @@
"website_files" : [
"website/o3dv/featureset.js",
"website/o3dv/utils.js",
"website/o3dv/cookies.js",
"website/o3dv/toolbar.js",
"website/o3dv/treeview.js",
"website/o3dv/modal.js",

View File

@ -77,6 +77,7 @@
<!-- website start -->
<script type="text/javascript" src="o3dv/featureset.js"></script>
<script type="text/javascript" src="o3dv/utils.js"></script>
<script type="text/javascript" src="o3dv/cookies.js"></script>
<script type="text/javascript" src="o3dv/toolbar.js"></script>
<script type="text/javascript" src="o3dv/treeview.js"></script>
<script type="text/javascript" src="o3dv/modal.js"></script>

View File

@ -77,6 +77,7 @@
<!-- website start -->
<script type="text/javascript" src="o3dv/featureset.js"></script>
<script type="text/javascript" src="o3dv/utils.js"></script>
<script type="text/javascript" src="o3dv/cookies.js"></script>
<script type="text/javascript" src="o3dv/toolbar.js"></script>
<script type="text/javascript" src="o3dv/treeview.js"></script>
<script type="text/javascript" src="o3dv/modal.js"></script>

46
website/o3dv/cookies.js Normal file
View File

@ -0,0 +1,46 @@
OV.CookieHandler = class
{
constructor ()
{
this.expirationDays = 30;
}
ClearVal (key)
{
this.SetStringVal (key, '');
}
GetBoolVal (key, defVal)
{
let stringVal = this.GetStringVal (key);
if (stringVal === null) {
return defVal;
}
return stringVal === 'true' ? true : false;
}
SetBoolVal (key, value)
{
this.SetStringVal (key, value ? 'true' : false);
}
SetStringVal (key, value)
{
let date = new Date ();
date.setTime (date.getTime () + (this.expirationDays * 24 * 60 * 60 * 1000));
document.cookie = key + '=' + value + '; expires=' + date.toUTCString () + ';';
}
GetStringVal (key)
{
let cookie = decodeURIComponent (document.cookie);
let cookieParts = cookie.split (';');
for (let i = 0; i < cookieParts.length; i++) {
let currentCookie = cookieParts[i].trim ();
if (currentCookie.startsWith (key + '=')) {
return currentCookie.substr (key.length + 1);
}
}
return null;
}
};

View File

@ -714,6 +714,34 @@ div.ov_thin_scrollbar::-webkit-scrollbar-thumb
background: #cccccc;
}
div.ov_message_popup
{
padding: 4px 10px;
position: absolute;
bottom: 15px;
right: 10px;
overflow: auto;
}
div.ov_message_popup div.ov_message_popup_text
{
padding: 3px;
float: left;
}
div.ov_message_popup div.ov_message_popup_button
{
color: #ffffff;
background: #3393bd;
text-align: center;
margin-left: 10px;
padding: 3px;
width: 60px;
border-radius: 5px;
cursor: pointer;
float: right;
}
@media (hover)
{

View File

@ -5,6 +5,7 @@ OV.Website = class
this.parameters = parameters;
this.viewer = new OV.Viewer ();
this.hashHandler = new OV.HashHandler ();
this.cookieHandler = new OV.CookieHandler ();
this.toolbar = new OV.Toolbar (this.parameters.toolbarDiv);
this.navigator = new OV.Navigator (this.parameters.navigatorDiv);
this.importSettings = new OV.ImportSettings ();
@ -28,6 +29,7 @@ OV.Website = class
this.InitDragAndDrop ();
this.InitModelLoader ();
this.InitNavigator ();
//this.InitCookieConsent ();
this.viewer.SetClickHandler (this.OnModelClicked.bind (this));
this.Resize ();
@ -502,4 +504,24 @@ OV.Website = class
}
});
}
InitCookieConsent ()
{
let cookieConsentKey = 'ov_cookie_consent';
this.cookieHandler.ClearVal (cookieConsentKey);
let accepted = this.cookieHandler.GetBoolVal (cookieConsentKey, false);
if (accepted) {
return;
}
let obj = this;
let consentPopup = $('<div>').addClass ('ov_message_popup').appendTo (document.body);
let consentText = $('<div>').addClass ('ov_message_popup_text').appendTo (consentPopup);
consentText.html ('This website uses cookies. See the details at the <a href="info/cookies.html">Cookies Policy</a> page.');
let consentButton = $('<div>').html ('Accept').addClass ('ov_message_popup_button').appendTo (consentPopup);
consentButton.click (function () {
obj.cookieHandler.SetBoolVal (cookieConsentKey, true);
consentPopup.remove ();
});
}
};