Last active
March 27, 2019 14:52
-
-
Save yongzhihuang/a883d40c5c3d395c608d5a53a47b9fbd to your computer and use it in GitHub Desktop.
growler_mobile_1-article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>TNY Growler</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1.0,width=device-width"> | |
<style> | |
@font-face { | |
font-family: "Graphik Web"; | |
font-stretch: normal; | |
font-style: normal; | |
font-weight: 500; | |
src: url('/fonts/Graphik-Medium.eot'); | |
src: url('/fonts/Graphik-Medium.eot?#iefix') format('embedded-opentype'), url('/fonts/Graphik-Medium.woff2') format('woff2'), url('/fonts/Graphik-Medium.woff') format('woff'); | |
} | |
@font-face { | |
font-family: "Adobe Caslon"; | |
font-style: normal; | |
font-weight: normal; | |
src: url('/fonts/AdobeCaslonPro-Regular.woff2') format('woff2'), url('/fonts/AdobeCaslonPro-Regular.woff') format('woff'); | |
} | |
@font-face { | |
font-family: "Adobe Caslon Italic"; | |
font-style: normal; | |
font-weight: normal; | |
src: url('/fonts/AdobeCaslonPro-Italic.woff2') format('woff2'), url('/fonts/AdobeCaslonPro-Italic.woff') format('woff'); | |
} | |
body, | |
html { | |
font-family: "Graphik Web", "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-size: 14px; | |
font-weight: 500; | |
line-height: 1.57; | |
height: 100%; | |
width: 100%; | |
padding: 0; | |
margin: 0; | |
-webkit-font-smoothing: antialiased; | |
} | |
em { | |
font-style: normal; | |
font-family: "Adobe Caslon Italic", Georgia, "Times New Roman", Times, serif; | |
} | |
#growler-wrapper { | |
background: #333; | |
bottom: 0; | |
color: #fff; | |
height: 50px; | |
left: 0; | |
min-width: 320px !important; | |
position: absolute; | |
width: 100%; | |
z-index: 1; | |
transition: height 0.5s ease-in-out, transform 0.5s ease-in-out; | |
transform-origin: bottom center; | |
overflow: hidden; | |
} | |
#growler-wrapper.expanded { | |
height: 240px; | |
} | |
#growler-wrapper:not(.expanded) .expanded-msg { | |
display: none; | |
} | |
#growler-wrapper.slide-in { | |
transform: translateY(100%); | |
} | |
.collapsed-msg { | |
display: table; | |
height: 50px; | |
width: 100%; | |
} | |
.collapsed-msg > span { | |
display: table-cell; | |
padding: 0 148px; | |
text-align: center; | |
vertical-align: middle; | |
} | |
.expanded-msg { | |
background: url('/images/CM/growler/[email protected]') 177px 8px no-repeat; | |
background-size: 163px 142px; | |
font-family: "Adobe Caslon", Georgia, "Times New Roman", Times, serif; | |
font-size: 17px; | |
font-weight: normal; | |
height: 165px; | |
line-height: 1.5; | |
padding: 10px 34px 0 392px; | |
} | |
#cta { | |
top: 0; | |
color: #fff; | |
height: 50px; | |
font-size: 13px; | |
line-height: 50px; | |
position: absolute; | |
right: 30px; | |
z-index: 999; | |
} | |
#cta::after { | |
background-size: 100%; | |
background: url('/images/svg/arrow-white.svg') top left no-repeat; | |
content: ''; | |
display: inline-block; | |
height: 10px; | |
margin-left: 15px; | |
transform-origin: center; | |
transition: transform 0.5s ease-in-out; | |
vertical-align: baseline; | |
width: 18px; | |
} | |
#growler-wrapper.expanded #cta::after { | |
transform: rotate(180deg); | |
} | |
#growler-wrapper.expanded #cta > a { | |
display: none; | |
} | |
.expanded-msg > span:not(.header) { | |
display: inline-block; | |
margin-right: 95px; | |
padding-bottom: 1em; | |
} | |
.header { | |
display: block; | |
font-weight: normal; | |
font-family: "Adobe Caslon", Georgia, "Times New Roman", Times, serif; | |
font-size: 30px; | |
line-height: 1.13; | |
margin-bottom: 5px; | |
} | |
.strike-through { | |
text-decoration: line-through; | |
} | |
.expanded-msg > span.signin-copy { | |
font-family: "Graphik Web", "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-size: 13px; | |
line-height: 1.6; | |
display: none; | |
} | |
.collapsed-msg a.subscribe-cta, | |
.expanded-msg .signin-copy a, | |
#cta a { | |
color: #fff; | |
text-decoration: underline; | |
} | |
.expanded-msg > a.subscribe-cta { | |
background: #087cc3; | |
color: #fff; | |
display: inline-block; | |
font-family: "Graphik Web", "Helvetica Neue", Helvetica, Arial, sans-serif; | |
font-size: 13px; | |
height: 48px; | |
line-height: 48px; | |
text-align: center; | |
text-decoration: none; | |
width: 255px; | |
border-radius: 2px; | |
position: relative; | |
bottom: 1em; | |
} | |
.hide { | |
display: none; | |
} | |
@media screen and (max-width: 768px) { | |
.collapsed-msg > span { | |
padding: 0 65px 0 20px; | |
} | |
.expanded-msg { | |
padding: 0 5px 0 300px; | |
background-position: 96px 8px; | |
font-size: 19px; | |
} | |
#cta { | |
right: 15px; | |
} | |
#cta span { | |
display: none; | |
} | |
#cta::before { | |
display: inline-block; | |
content: ''; | |
width: 1px; | |
height: 22px; | |
background: #737373; | |
vertical-align: middle; | |
} | |
#cta::after { | |
width: 14px; | |
height: 8px; | |
vertical-align: middle; | |
} | |
.expanded-msg > span:not(.header) { | |
padding-bottom: 10px; | |
} | |
.header { | |
font-size: 24px; | |
} | |
.sales-copy { | |
font-size: 17px; | |
} | |
.expanded-msg > a.subscribe-cta { | |
bottom: 0; | |
} | |
.expanded-msg > .signin-copy { | |
padding-top: 10px; | |
padding-bottom: 0; | |
} | |
} | |
@media screen and (max-width: 600px) { | |
body, html { | |
font-size: 13px; | |
} | |
#growler-wrapper { | |
height: 70px; | |
} | |
#growler-wrapper.expanded { | |
height: 300px; | |
} | |
#growler-wrapper .collapsed-msg > span { | |
text-align: left; | |
} | |
.collapsed-msg { | |
height: 70px; | |
} | |
.collapsed-msg > span { | |
padding: 0 60px 0 15px; | |
} | |
.expanded-msg { | |
background: none; | |
padding: 12px 26px 42px 26px; | |
height: 176px; | |
text-align: center; | |
} | |
.expanded-msg > span:not(.header) { | |
margin: 10px auto auto auto; | |
padding-bottom: 10px; | |
} | |
.expanded-msg > a.subscribe-cta { | |
display: block; | |
margin: auto; | |
} | |
.expanded-msg > span.signin-copy { | |
display: block; | |
} | |
#cta { | |
height: 70px; | |
} | |
#cta::before { | |
height: 42px; | |
} | |
#cta::before, | |
#cta::after { | |
margin-top: 1em; | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<div id="growler-wrapper" class="expanded"> | |
<div class="collapsed-msg"> | |
<span>You have 3 free articles left this month. <br><span class="save-text hide">Get 12 weeks for just $12.</span> <a href="%%CLICK_URL_UNESC%%%%DEST_URL%%" target="_blank" class="subscribe-cta hide">Subscribe now.</a></span> | |
</div> | |
<div class="expanded-msg"> | |
<span class="header">Go beyond the headlines.</span> | |
<span class="sales-copy">Get <em>The New Yorker </em> for $1 a week, plus a free tote.</span> | |
<a href="%%CLICK_URL_UNESC%%%%DEST_URL%%" target="_blank" class="subscribe-cta">Subscribe Now</a> | |
<span class="signin-copy">Already have an account? <a href="javascript:void(0);return;" target="_top">Sign in</a>.</span> | |
</div> | |
<div id="cta"><span>Collapse</span></div> | |
</div> | |
<script> | |
(function () { | |
'use strict'; | |
var growlerFrame = window.frameElement; | |
var growler = document.getElementById('growler-wrapper'); | |
var collapsedMsgCta = growler.querySelector('.collapsed-msg .subscribe-cta'); | |
var saveText = growler.querySelector('.save-text'); | |
var signInCta = growler.querySelector('.signin-copy a'); | |
var cta = document.getElementById('cta'); | |
var ctaMsg = cta.querySelector('span'); | |
// Constants | |
var INIT = { | |
load: 'load-init', | |
remove: 'remove-init', | |
slideInOffset: 0.2 | |
}; | |
var CTA_MESSAGE = { | |
collapsed: 'Expand', | |
expanded: ctaMsg.innerHTML | |
}; | |
var GROWLER_HEIGHT = { | |
hidden: '0px', | |
collapsed: '70px', | |
expanded: '320px', | |
waitTime: 500 | |
}; | |
// ANALYTICS | |
try { | |
window.top.dataLayer.push({'event': 'growler impression'}); | |
} catch (e) { | |
console.error('Error in growler ad tracking calls', e); | |
} | |
// Methods | |
var toggle = function (e, init) { | |
e = e || undefined; | |
init = init || undefined; | |
if (e) { | |
e.cancelBubble = true; | |
} | |
msgToggle(); | |
if (!init) { | |
if (!growler.classList.contains('expanded')) { | |
growler.classList.add('expanded'); | |
ctaMsg.innerHTML = CTA_MESSAGE.expanded; | |
} else if (growler.classList.contains('expanded')) { | |
growler.classList.remove('expanded'); | |
ctaMsg.innerHTML = CTA_MESSAGE.collapsed; | |
} | |
frameToggle(); | |
} | |
}; | |
var msgToggle = function () { | |
if (growler.classList.contains('expanded')) { | |
collapsedMsgCta.classList.add('hide'); | |
saveText.classList.add('hide'); | |
} else { | |
collapsedMsgCta.classList.remove('hide'); | |
saveText.classList.remove('hide'); | |
} | |
}; | |
var frameToggle = function (init) { | |
if (!growlerFrame) return; | |
init = init || undefined; | |
var gfParent = growlerFrame.parentElement; | |
if (init) { | |
if (init === INIT.load) { | |
// Start hidden | |
growlerFrame.style.setProperty('height', GROWLER_HEIGHT.hidden, 'important'); | |
gfParent.style.setProperty('height', GROWLER_HEIGHT.hidden, 'important'); | |
growlerFrame.classList.add('init'); | |
growler.classList.add('slide-in'); | |
toggle(null, INIT.load); | |
} else if (init === INIT.remove) { | |
growlerFrame.style.setProperty('height', GROWLER_HEIGHT.expanded, 'important'); | |
gfParent.style.setProperty('height', GROWLER_HEIGHT.expanded, 'important'); | |
growlerFrame.classList.remove('init'); | |
growler.classList.remove('slide-in'); | |
} | |
} else if (growler.classList.contains('expanded')) { | |
growlerFrame.style.setProperty('height', GROWLER_HEIGHT.expanded, 'important'); | |
gfParent.style.setProperty('height', GROWLER_HEIGHT.expanded, 'important'); | |
} else { | |
// Wait for animation to finish | |
var cllpsTime = setTimeout(function () { | |
growlerFrame.style.setProperty('height', GROWLER_HEIGHT.collapsed, 'important'); | |
gfParent.style.setProperty('height', GROWLER_HEIGHT.collapsed, 'important'); | |
clearTimeout(cllpsTime); | |
}, GROWLER_HEIGHT.waitTime); | |
} | |
}; | |
var linkNoBubble = function (e) { | |
e.cancelBubble = true; | |
}; | |
var scrollMonitor = function (e) { | |
var shouldSlideIn = window.top.scrollY >= Math.floor(window.top.innerHeight * INIT.slideInOffset); | |
if (growlerFrame.classList.contains('init') && shouldSlideIn) { | |
frameToggle(INIT.remove); | |
window.top.removeEventListener('scroll', scrollMonitor); | |
} | |
}; | |
// Bind Events | |
cta.addEventListener('click', toggle); | |
growler.addEventListener('click', toggle); | |
growler.querySelectorAll('a').forEach(function (link) { | |
link.addEventListener('click', linkNoBubble); | |
}); | |
// NOTE: Sign-in link only shows up on mobile view | |
signInCta.addEventListener('click', function (e) { | |
e.preventDefault(); | |
window.top.location.href = `https://account.newyorker.com/?retURL=${window.top.location.href}&reload=true&utm=AMS_NYR_MOBILE_PAYWALL_METER_ARTICLE_1`; | |
}); | |
window.top.addEventListener('scroll', scrollMonitor); | |
frameToggle(INIT.load); | |
console.log('***GROWLER_WORKING_SLIDE_IN_ANIMATION***'); | |
if (!growlerFrame) console.warn('GROWLER WARNING: Growler does not have access to parent frame.'); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment