/hrms_core/Views/Shared/_CookieConsentPartial.cshtml

https://bitbucket.org/dotnetavis/hrms · Razor · 32 lines · 30 code · 2 blank · 0 comment · 0 complexity · 1e13fa5990fcdf6e46e4e6e107b1ab3e MD5 · raw file

  1. @using Microsoft.AspNetCore.Http.Features
  2. @{
  3. var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
  4. var showBanner = !consentFeature?.CanTrack ?? false;
  5. var cookieString = consentFeature?.CreateConsentCookie();
  6. }
  7. <style>
  8. .close {
  9. right: 0px !important;
  10. color: #d73434 !important;
  11. opacity: 0.5 !important;
  12. }
  13. </style>
  14. CookiePartial
  15. @if (showBanner)
  16. {
  17. <div id="cookieConsent" style="background-color:forestgreen" class="alert alert-info alert-dismissible show" role="alert">
  18. Use this space to summarize your privacy and cookie use policy. <a asp-area="" asp-controller="Home" asp-action="Privacy">Learn More</a>.
  19. <button type="button" class="accept-policy close" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
  20. <span aria-hidden="true">Accept</span>
  21. </button>
  22. </div>
  23. <script>
  24. (function () {
  25. var button = document.querySelector("#cookieConsent button[data-cookie-string]");
  26. button.addEventListener("click", function (event) {
  27. document.cookie = button.dataset.cookieString;
  28. }, false);
  29. })();</script>
  30. }