Add cookie handler class.
This commit is contained in:
parent
7ba71dcf12
commit
1fd57bcbc2
@ -63,6 +63,7 @@
|
|||||||
"website_files" : [
|
"website_files" : [
|
||||||
"website/o3dv/featureset.js",
|
"website/o3dv/featureset.js",
|
||||||
"website/o3dv/utils.js",
|
"website/o3dv/utils.js",
|
||||||
|
"website/o3dv/cookies.js",
|
||||||
"website/o3dv/toolbar.js",
|
"website/o3dv/toolbar.js",
|
||||||
"website/o3dv/treeview.js",
|
"website/o3dv/treeview.js",
|
||||||
"website/o3dv/modal.js",
|
"website/o3dv/modal.js",
|
||||||
|
|||||||
@ -77,6 +77,7 @@
|
|||||||
<!-- website start -->
|
<!-- website start -->
|
||||||
<script type="text/javascript" src="o3dv/featureset.js"></script>
|
<script type="text/javascript" src="o3dv/featureset.js"></script>
|
||||||
<script type="text/javascript" src="o3dv/utils.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/toolbar.js"></script>
|
||||||
<script type="text/javascript" src="o3dv/treeview.js"></script>
|
<script type="text/javascript" src="o3dv/treeview.js"></script>
|
||||||
<script type="text/javascript" src="o3dv/modal.js"></script>
|
<script type="text/javascript" src="o3dv/modal.js"></script>
|
||||||
|
|||||||
@ -77,6 +77,7 @@
|
|||||||
<!-- website start -->
|
<!-- website start -->
|
||||||
<script type="text/javascript" src="o3dv/featureset.js"></script>
|
<script type="text/javascript" src="o3dv/featureset.js"></script>
|
||||||
<script type="text/javascript" src="o3dv/utils.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/toolbar.js"></script>
|
||||||
<script type="text/javascript" src="o3dv/treeview.js"></script>
|
<script type="text/javascript" src="o3dv/treeview.js"></script>
|
||||||
<script type="text/javascript" src="o3dv/modal.js"></script>
|
<script type="text/javascript" src="o3dv/modal.js"></script>
|
||||||
|
|||||||
46
website/o3dv/cookies.js
Normal file
46
website/o3dv/cookies.js
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -714,6 +714,34 @@ div.ov_thin_scrollbar::-webkit-scrollbar-thumb
|
|||||||
background: #cccccc;
|
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)
|
@media (hover)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ OV.Website = class
|
|||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
this.viewer = new OV.Viewer ();
|
this.viewer = new OV.Viewer ();
|
||||||
this.hashHandler = new OV.HashHandler ();
|
this.hashHandler = new OV.HashHandler ();
|
||||||
|
this.cookieHandler = new OV.CookieHandler ();
|
||||||
this.toolbar = new OV.Toolbar (this.parameters.toolbarDiv);
|
this.toolbar = new OV.Toolbar (this.parameters.toolbarDiv);
|
||||||
this.navigator = new OV.Navigator (this.parameters.navigatorDiv);
|
this.navigator = new OV.Navigator (this.parameters.navigatorDiv);
|
||||||
this.importSettings = new OV.ImportSettings ();
|
this.importSettings = new OV.ImportSettings ();
|
||||||
@ -28,6 +29,7 @@ OV.Website = class
|
|||||||
this.InitDragAndDrop ();
|
this.InitDragAndDrop ();
|
||||||
this.InitModelLoader ();
|
this.InitModelLoader ();
|
||||||
this.InitNavigator ();
|
this.InitNavigator ();
|
||||||
|
//this.InitCookieConsent ();
|
||||||
|
|
||||||
this.viewer.SetClickHandler (this.OnModelClicked.bind (this));
|
this.viewer.SetClickHandler (this.OnModelClicked.bind (this));
|
||||||
this.Resize ();
|
this.Resize ();
|
||||||
@ -501,5 +503,25 @@ OV.Website = class
|
|||||||
return GetModelInfo (obj.model, obj.viewer);
|
return GetModelInfo (obj.model, obj.viewer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ();
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user