HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<p style="text-align: center; grid-column: 1; grid-row: 1;"><a href="https://ai.cs.cmu.edu/about" style="color: #fff;text-decoration: none;box-shadow: inset 0 -1px 0 0 #fff;line-height: 1.6;display: inline-block;" target="_blank">Live final product</a></p>
<div class="font-loaded--OpenSans">
<section class="ai-stack__outermost-wrapper">
<ul class="ai-stack__wrapper">
<li class="ai-stack__item-wrapper ai-stack__item-wrapper--autonomy">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Autonomy</h3>
<div class="ai-component__description-wrapper">
<p>AI technologies at this level focus on creating systems that make their own decisions without human intervention. These systems solve problems when humans can't. For example, robots can search through rubble for disaster survivors, or sensors in self-driving cars can respond more quickly to impending accidents than human drivers.</p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper ai-stack__item-wrapper--human-ai">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Human-AI Interaction</h3>
<div class="ai-component__description-wrapper">
<p>When we create artificial intelligence in this part of the stack, we're augmenting what humans can do. These technologies make our lives easier. One good example of work in this area is robotic arms attached to motorized wheelchairs that people with spinal cord injuries can direct with their gaze. Another exciting example is research that allows a computer system to interview a patient remotely to determine if they're depressed and need human intervention.</p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Planning & Acting</h3>
<div class="ai-component__description-wrapper">
<p>Systems in this part of the stack rely on <strong>optimization</strong>, <strong>safety</strong>, the <strong>knowledge network</strong> and <strong>strategic reasoning</strong> to make the best possible decision available and learn from the information researchers give them. Though slightly less sophisticated than systems employing the blocks at the very top of the stack, planning and acting technologies still rely on advanced systems and algorithms to positively impact the world. One great example of technology that falls into this category is the national kidney exchange —a sophisticated algorithm that matches potential kidney donors with people who need transplants.</p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Decision Support</h3>
<div class="ai-component__description-wrapper">
<p>This layer includes technologies that help humans make decisions. Where should 500 Lyft drivers be deployed, based on information we know about events and demand? How should emergency services be distributed after a disaster? Exciting examples of research in this area include work to identify instances of human trafficking, help locate victims, and collect and synthesize enough information that trends and patterns can be discovered and used to combat the problem. </p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Modeling</h3>
<div class="ai-component__description-wrapper">
<p>AI systems at the top of the stack rely on computer modeling to understand information. Models use computers to construct and manipulate abstract representations of situations and natural phenomenon in the world. For example, new research has allowed scientist to analyze photos of people to track their facial features and recognize their emotional states. </p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Machine Learning</h3>
<div class="ai-component__description-wrapper">
<p>Machine learning focuses on creating programs that learn from experience. It advances computing through exposure to new scenarios, testing and adaptation, while using pattern- and trend-detection to help the computer make better decisions in similar, subsequent situations. A relevant example of work in machine learning is using speech recognition technologies to identify the age, sex and location of the hoax callers that plague the U.S. Coast Guard.</p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Massive-Data Management</h3>
<div class="ai-component__description-wrapper">
<p>Machine learning focuses on creating programs that learn from experience. It advances computing through exposure to new scenarios, testing and adaptation, while using pattern- and trend-detection to help the computer make better decisions in similar, subsequent situations. A relevant example of work in machine learning is using speech recognition technologies to identify the age, sex and location of the hoax callers that plague the U.S. Coast Guard.</p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Devices</h3>
<div class="ai-component__description-wrapper">
<p>The device layer is all of the sensors and components needed for machines to perceive the world around them. Traffic lights, for example can observe traffic levels and negotiate with each other to improve traffic flow. Iris-detection systems can read and identify a human eye from 40 feet away. </p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">Computing</h3>
<div class="ai-component__description-wrapper">
<p><strong>All</strong> artificial intelligence is built on the computer systems that came before it. This includes the systems, networks, programming languages, operating systems and interactions between devices that make computing possible.</p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
<li class="ai-stack__item-wrapper ai-stack__item-wrapper--ethics">
<article class="ai-stack__item ai-component">
<h3 class="ai-component__title">
Ethics
</h3>
<div class="ai-component__description-wrapper">
<p>Ethics permeates the entire AI stack. The decisions people make as they build AI systems involve serious ethical questions that we can't ignore. At CMU, we believe that a vital component of AI is giving tomorrow's scientists the tools they need to perform ethical reasoning and the skills to create AI for good.</p>
<ul class="ai-component__staff-list">
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
<li><a href="#">Brad Dourif</a></li>
</ul>
</div>
</article>
</li>
</ul>
</section>
</div>
* {
box-sizing: border-box;
}
body {
background: #000;
}
.ai-stack__outermost-wrapper {
padding: 3em;
background: #bbb;
}
.ai-stack__wrapper {
list-style: none;
padding: 0;
margin: 0;
margin: 0 auto;
padding: 0.75em;
list-style: none;
background: #fff;
}
$autonomy: #944c00;
$hai: #a3722a;
.ai-stack__item-wrapper {
margin: 0 0 3em;
&:nth-child(1) {
.ai-component__title {
background: $autonomy;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken($autonomy, 7);
}
}
}
&:nth-child(2) {
.ai-component__title {
background: $hai;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken($hai, 7);
}
}
}
&:nth-child(3) {
.ai-component__title {
background: #067;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken(#067, 7);
}
}
}
&:nth-child(4) {
.ai-component__title {
background: #247;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken(#247, 7);
}
}
}
&:nth-child(5) {
.ai-component__title {
background: #085;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken(#085, 7);
}
}
}
&:nth-child(6) {
.ai-component__title {
background: #900;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken(#900, 7);
}
}
}
&:nth-child(7) {
.ai-component__title {
background: #243;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken(#243, 7);
}
}
}
&:nth-child(8) {
.ai-component__title {
background: #003d47;
}
}
&:nth-child(9) {
.ai-component__title {
background: #6b0000;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken(#6b0000, 7);
}
}
}
&:nth-child(10) {
.ai-component__title {
background: #1c96c4;
.aiStack-processed &:hover,
.aiStack-processed &:focus {
background: darken(#1c96c4, 7);
}
}
}
}
.ai-component__title {
margin: 0 0 0.75em;
padding: 0.5rem 0.75rem;
font-size: 1.5em;
font-weight: 300;
color: #fff;
transition: background 0.25s;
}
.ai-component__description-wrapper {
padding: 0.5rem 0.75rem;
}
.ai-component__staff-list {
columns: 12em auto;
margin: 0;
padding: 0;
list-style: none;
}
/**
* Styles with JS
*/
.aiStack-processed {
--stack-bg-color: #900;
&.ai-stack__outermost-wrapper {
position: relative;
display: grid;
grid-template: 1fr / 1fr;
align-items: start;
padding: 3rem;
background: #bbb;
font-size: 0.75rem;
@media (min-width: 48em) {
font-size: 1rem;
}
}
.ai-stack__wrapper,
.js-ai-stack__info-wrapper,
.js-ai-stack__overlay {
position: relative;
z-index: 1;
grid-area: 1 / 1;
max-width: 50em;
min-width: 40em;
margin: auto;
}
.ai-stack__wrapper {
display: grid;
grid-template: 1fr / auto auto 5.8125em;
grid-template-areas:
"component1 component2 ethics"
"component3 component3 ethics"
"component4 component4 ethics"
"component5 component5 ethics"
"component6 component6 ethics"
"component7 component7 ethics"
"component8 component8 ethics"
"component9 component9 ethics"
;
grid-row-gap: 0.3125em;
justify-items: stretch;
align-items: start;
padding: 0.75em;
list-style: none;
background: #fff;
}
.ai-stack__item-wrapper {
margin: 0;
&:nth-child(1) {
grid-area: component1;
}
&:nth-child(2) {
grid-area: component2;
}
&:nth-child(3) {
grid-area: component3;
}
&:nth-child(4) {
grid-area: component4;
}
&:nth-child(5) {
grid-area: component5;
}
&:nth-child(6) {
grid-area: component6;
}
&:nth-child(7) {
grid-area: component7;
}
&:nth-child(8) {
grid-area: component8;
}
&:nth-child(9) {
grid-area: component9;
}
}
.ai-component__title {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
margin: 0;
padding: 0.75em 1em;
border: 0;
box-shadow: none;
appearance: none;
font-size: 1.5em;
line-height: 1.4;
text-align: center;
> span {
display: block;
border-bottom: 0.0625rem solid rgba(255, 255, 255, 0);
transition: border-color 0.15s;
}
span span {
display: block;
transition: transform 0.5s ease-out;
}
&:hover,
&:focus {
> span {
border-bottom: 0.0625rem solid rgba(255, 255, 255, 0.4);
}
span span {
transform: translate(0, -0.125em);
}
}
}
/**
* Setup diagon line between top two items
*/
.ai-stack__item-wrapper--autonomy {
.ai-component__title {
padding-right: 1.5em;
}
}
.ai-stack__item-wrapper--human-ai {
position: relative;
.ai-component__title {
&:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: -0.5em;
display: block;
width: 0.75em;
background: $hai;
border-left: 0.3125rem solid #fff;
transform: skew(15deg);
transition: background 0.25s;
}
&:hover:before,
&:focus:before {
background: darken($hai, 7);
}
}
}
.ai-stack__item-wrapper--ethics {
grid-area: ethics;
align-self: stretch;
margin-left: 0.3125em;
.ai-component {
height: 100%;
}
.ai-component__title {
position: relative;
display: block;
height: 100%;
&:before {
content: '';
position: absolute;
top: 0.5em;
bottom: 0.5em;
left: 0;
display: block;
width: 0.75em;
border-radius: 0 0.3125em 0.3125em 0;
background: #fff;
}
> span {
position: absolute;
top: 50%;
left: 50%;
display: inline-block;
transform: translate(-50%, -50%) rotate(90deg) translate(0, -0.25em);
}
}
}
.ai-stack__item {
height: 100%;
}
.ai-component__description-wrapper {
height: 0;
overflow: hidden;
}
.js-ai-stack__info-wrapper {
position: relative;
z-index: 2;
display: none;
padding: 2em 2.5em;
align-self: center;
background: #fff;
background: rgba(255, 255, 255, 0.97);
}
.js-ai-stack__info-title {
font-size: 1.5em;
margin: 0 6rem 0 0;
padding: 0.5em 0 1rem;
}
.js-ai-stack__info-title-swatch {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 0.5rem;
background: #900;
background: var(--stack-bg-color);
}
.js-ai-stack__info-wrapper-close {
position: absolute;
top: 0;
right: 0;
z-index: 1;
width: 4.5rem;
height: 5rem;
background: transparent;
border: 0;
appearance: none;
font-size: 0.75em;
&:before,
&:after {
content: '';
position: absolute;
top: 60%;
right: 60%;
display: block;
width: 0.125em;
height: 2em;
background: #900;
background: var(--stack-bg-color);
}
&:before {
transform: translate(-50%, -50%) rotate(-45deg);
}
&:after {
transform: translate(-50%, -50%) rotate(45deg);
}
}
.js-ai-stack__overlay {
justify-self: stretch;
align-self: stretch;
width: auto;
height: auto;
max-width: 200%;
max-height: 200%;
margin: -3em; /* Negate padding */
z-index: 1;
display: none;
background: rgba(0, 0, 0, 0.3);
}
}
console.clear();
var $outerWrapper = $('.ai-stack__outermost-wrapper');
if ($outerWrapper.length && !$outerWrapper.hasClass('aiStack-processed')) {
var $ = jQuery;
var $aiStackItem = $outerWrapper.find('.ai-stack__item');
var stackHtml = {};
var stackSwatches = {};
var $infoWrapper = $('<div class="js-ai-stack__info-wrapper"></div>');
var $overlay = $('<div class="js-ai-stack__overlay"></div>');
var $infoWrapperClose = $('<button class="js-ai-stack__info-wrapper-close"><span class="element-invisible">Close</span></button>');
$outerWrapper.append($infoWrapper).append($overlay);
/**
* Closes the info wrapper
*/
function closeInfoWrapper() {
var currentStack = $outerWrapper.data('currentStack');
$infoWrapper.removeClass('js-ai-stack__info-wrapper--active');
$infoWrapper.fadeOut(250);
$overlay.fadeOut(250);
if (currentStack !== 'none' && typeof stackHtml[currentStack] === 'string') {
$outerWrapper.find('[data-stack-name="' + currentStack + '"]').focus();
}
$outerWrapper.data('currentStack', 'none');
}
$overlay.click(function() {
closeInfoWrapper();
});
/**
* Update the content in Info Wrapper
*/
function updateInfoWrapperContent(headline) {
if (typeof stackHtml[headline] === 'string') {
$infoWrapper.html(
'<h2 class="js-ai-stack__info-title">' +
headline +
'<div class="js-ai-stack__info-title-swatch"></div>' +
'</h2>' +
stackHtml[headline]
).prepend($infoWrapperClose);
if (!$infoWrapper.hasClass('js-ai-stack__info-wrapper--active')) {
$infoWrapper.attr('style', null);
$infoWrapper.fadeIn(500);
$overlay.fadeIn(250);
$infoWrapper.addClass('js-ai-stack__info-wrapper--active');
}
$outerWrapper[0].style.setProperty('--stack-bg-color', stackSwatches[headline]);
$outerWrapper.data('currentStack', headline);
// For them keyboard navigating peeps, move the focus
$infoWrapperClose.focus();
$infoWrapperClose.click(function() {
closeInfoWrapper();
});
}
}
/**
* Setup each item
*/
$aiStackItem.each(function(index, element) {
var $element = $(element);
var $headlineElement = $element.find('.ai-component__title');
var headlineText = $headlineElement.text().trim();
var $copy = $element.find('.ai-component__description-wrapper');
var buttonHtml =
'<button class="ai-component__title" data-stack-name="' + headlineText + '"><span><span>' +
$headlineElement.html() +
'</span></span></button>';
$copy.attr('hidden', 'hidden');
stackHtml[headlineText] = $copy.html();
stackSwatches[headlineText] = $headlineElement.css('background-color');
// Make headline a button to reflect functionality
$headlineElement.replaceWith(buttonHtml);
$headlineElement = $element.find('.ai-component__title');
$headlineElement.click(function() {
updateInfoWrapperContent(headlineText);
});
});
$outerWrapper.data('currentStack', 'none');
$outerWrapper.addClass('aiStack-processed');
}
Also see: Tab Triggers