Skip to content

Add Vue mastery Promotion Banner for Black Friday 2020 #2733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/images/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/black-hole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/images/logo-vuemastery.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/planets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions themes/vue/layout/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<script type="text/javascript" defer="defer" src="https://extend.vimeocdn.com/ga/72160148.js"></script>
</head>
<body class="<%- isIndex ? '' : 'docs' -%>">
<%- partial('partials/vuemastery_banner.ejs') %>
<div id="mobile-bar" <%- isIndex ? 'class="top"' : '' %>>
<a class="menu-button"></a>
<a class="logo" href="/"></a>
Expand Down
102 changes: 102 additions & 0 deletions themes/vue/layout/partials/vuemastery_banner.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
<div id="vm-banner" class="vuemastery-banner hide" role="banner">
<div class="vuemastery-planet"></div>
<a class="vuemastery-banner--link" href="https://www.vuemastery.com/black-friday-2020" target="_blank">
<img class="vuemastery-banner--logo" src="/images/logo-vuemastery.svg" alt="vuemastery" />
<div class="vuemastery-banner--wrapper">
<p><span>Vue Mastery's Black Friday Sale:</span>Save 50% off a year of Vue courses</p>
<button class="vuemastery-button">Get discount</button>
</div>
</a>
<div id="vm-close" class="vuemastery-banner--close"></div>
</div>

<script>
(function () {
// Get elements
var elBody = document.getElementsByTagName("body")[0];
var elBanner = document.getElementById("vm-banner");
var elClose = document.getElementById("vm-close");
var elMenu = document.getElementById("mobile-bar");

// Variable names
var nameWrapper = "vuemastery-promo";
var nameFixMenu = "vuemastery-menu-fixed";
var nameStorage = "vuemastery-black-firday-2020-banner";

// Defaults values
var isMenuFixed = false;
var posMenu = 80;

var initBanner = function () {
// Add event listeners
toggleBannerEvents(true);
// Add class to the body to push fixed elements
elBody.classList.add(nameWrapper);
// Display the banner
elBanner.style.display = "block";
// Init close button action
elClose.onclick = closeBanner;
// Get the menu position
getMenuPosition();
// Check current page offset position
isMenuFixed = isUnderBanner();
// And position menu accordingly
if (isMenuFixed) {
elBody.classList.add("fixed");
}
}

var closeBanner = function(e) {
// Prevent bubbling event that redirect to vuemastery.com
e.preventDefault();
// Remove events
toggleBannerEvents(false);
// Hide the banner
elBanner.style.display = "none";
// Remove class to the body that push fixed elements
elBody.classList.remove(nameWrapper);
// Save action in the local storage
localStorage.setItem(nameStorage, true);
}

var getMenuPosition = function() {
posMenu = elBanner.clientHeight;
}

var isUnderBanner = function() {
return window.pageYOffset > posMenu;
}

var fixMenuAfterBanner = function() {
if (isUnderBanner()) {
if (!isMenuFixed) {
// The menu will be fixed
toggleFixedPosition(true);
}
} else if (isMenuFixed) {
// The menu stay under the banner
toggleFixedPosition(false);
}
}

var toggleBannerEvents = function (on) {
// Add or remove event listerners attached to the DOM
var method = on ? "addEventListener" : "removeEventListener";
window[method]("resize", getMenuPosition);
window[method]("scroll", fixMenuAfterBanner);
}

var toggleFixedPosition = function (on) {
// Switch between relative and fixed position
var method = on ? "add" : "remove";
elBody.classList[method](nameFixMenu);
isMenuFixed = on;
}

// Load component according to user preferences
if (!localStorage.getItem(nameStorage)) {
initBanner();
}
})()
</script>
Loading