diff --git a/tools/config.json b/tools/config.json index cd38227..9d0488d 100644 --- a/tools/config.json +++ b/tools/config.json @@ -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", diff --git a/website/embed.html b/website/embed.html index 52d9b5b..2b1feca 100644 --- a/website/embed.html +++ b/website/embed.html @@ -77,6 +77,7 @@ + diff --git a/website/index.html b/website/index.html index c1479cf..30015e6 100644 --- a/website/index.html +++ b/website/index.html @@ -77,6 +77,7 @@ + diff --git a/website/o3dv/cookies.js b/website/o3dv/cookies.js new file mode 100644 index 0000000..a7f9f06 --- /dev/null +++ b/website/o3dv/cookies.js @@ -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; + } +}; diff --git a/website/o3dv/website.css b/website/o3dv/website.css index f5ac331..2c4291e 100644 --- a/website/o3dv/website.css +++ b/website/o3dv/website.css @@ -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) { diff --git a/website/o3dv/website.js b/website/o3dv/website.js index e74bdbc..3f87fc8 100644 --- a/website/o3dv/website.js +++ b/website/o3dv/website.js @@ -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 (); @@ -501,5 +503,25 @@ OV.Website = class 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 = $('
').addClass ('ov_message_popup').appendTo (document.body); + let consentText = $('
').addClass ('ov_message_popup_text').appendTo (consentPopup); + consentText.html ('This website uses cookies. See the details at the Cookies Policy page.'); + let consentButton = $('
').html ('Accept').addClass ('ov_message_popup_button').appendTo (consentPopup); + consentButton.click (function () { + obj.cookieHandler.SetBoolVal (cookieConsentKey, true); + consentPopup.remove (); + }); + } };