Skip to content

Commit

Permalink
added js-cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
somratpro committed Oct 18, 2020
1 parent e59fbf7 commit 0f71f87
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
7 changes: 6 additions & 1 deletion exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ weight = 2
languageCode = "en-us"
title = "Example site multi-language"
dateFormat = "January 2, 2006"

home = "EN Home"
logo = "images/logo.png"
menufixed = false
Expand All @@ -117,6 +116,12 @@ footerQuicklinkTitle = "Quicklinks"
footerAboutTitle = "About"
footerSubscribeTitle = "Subscribe"


# cookies
[params.cookies]
enable = true
expire_days = 2

# Hero Area Section
[Languages.en.params.hero]
enable = true
Expand Down
43 changes: 43 additions & 0 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,46 @@ <h6>Design and Developed by themefisher.com
{{ "<!-- Main Script -->" | safeHTML }}
{{ $script := resources.Get "js/script.js" | minify}}
<script src="{{ $script.Permalink }}"></script>

<!-- cookie -->
{{ if site.Params.cookies.enable }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js"></script>
<div id="js-cookie-box" class="cookie-box cookie-box-hide">
This site uses cookies. By continuing to use this website, you agree to their use. <span id="js-cookie-button" class="btn btn-sm btn-outline-primary ml-2">I Accept</span>
</div>
<script>
(function ($) {
const cookieBox = document.getElementById('js-cookie-box');
const cookieButton = document.getElementById('js-cookie-button');
if (!Cookies.get('cookie-box')) {
cookieBox.classList.remove('cookie-box-hide');
cookieButton.onclick = function () {
Cookies.set('cookie-box', true, {
expires: {{ site.Params.cookies.expire_days }}
});
cookieBox.classList.add('cookie-box-hide');
};
}
})(jQuery);
</script>

<!-- cookie style -->
<style>
.cookie-box {
position: fixed;
left: 0;
right: 0;
bottom: 0;
text-align: center;
z-index: 9999;
padding: 1rem 2rem;
background: rgb(71, 71, 71);
transition: all .75s cubic-bezier(.19, 1, .22, 1);
color: #fdfdfd;
}

.cookie-box-hide {
display: none;
}
</style>
{{ end }}

0 comments on commit 0f71f87

Please sign in to comment.