Skip to content
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

New amp-story-bling-link element #22871

Merged
merged 14 commits into from Jun 24, 2019
74 changes: 74 additions & 0 deletions examples/amp-story/bling-link.html
@@ -0,0 +1,74 @@
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-story"
src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script>
<title>My Story</title>
<meta name="viewport"
content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="canonical" href="blink-link.html">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
body {
font-family: 'Roboto', sans-serif;
}
amp-story-page {
background: black;
}
h1 {
color: white;
font-size: 2.875em;
font-weight: normal;
line-height: 1.174;
text-transform: uppercase;
}
p {
color: white;
}
</style>
</head>

<body>
<amp-story standalone>

<amp-story-page id="cover">
<amp-story-grid-layer template="vertical">
<h1>Hello World</h1>
<p>This is the cover page of this story.</p>
</amp-story-grid-layer>
</amp-story-page>

<amp-story-page id="page-1">
<amp-story-grid-layer template="vertical">
<h1>First Page</h1>
<p>This is the first page of this story.</p>
</amp-story-grid-layer>
<amp-story-grid-layer template="horizontal" style="padding-top: 260px">
<amp-img
src="./img/merch1.jpg"
width="210"
height="280"
max-width="210"
layout="fixed">
</amp-img>
<amp-story-bling-link
id="blink-1"
layout="fixed"
width="90px"
height="90px">
</amp-story-bling-link>
</amp-story-grid-layer>
</amp-story-page>

<amp-story-page id="page-2">
<amp-story-grid-layer template="vertical">
<h1>Second Page</h1>
<p>This is the second page of this story.</p>
</amp-story-grid-layer>
</amp-story-page>

</amp-story>
</body>
</html>
Binary file added examples/amp-story/img/merch1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions extensions/amp-story/1.0/amp-story-bling-link.css
@@ -0,0 +1,79 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a high-level, I think we should decide exactly how templated these are supposed to be (perhaps in a separate PR). Is it okay if a publisher slaps a 6px red border around it? If they change the padding? Add a box-shadow?

We might want to think about whether it's worth either:

  • Putting this in a separate shadow DOM tree, or
  • Think through some specific properties we'd like to enforce (even if we're enforcing their default state)

* Copyright 2019 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

amp-story-bling-link {
position: relative !important;
width: 90px !important;
height: 90px !important;
}

.i-amphtml-story-bling-link-button {
estherkim marked this conversation as resolved.
Show resolved Hide resolved
position: absolute !important;
border-radius: 50% !important;
background: rgba(255, 255, 255, 1) !important;
margin: 7.5px !important;
width: 75px !important;
height: 75px !important;
}

amp-story-page[active] .i-amphtml-story-bling-link-pulse {
position: absolute !important;
border-radius: 50% !important;
background: rgba(255, 255, 255, 0.4) !important;
margin: 7.5px !important;
width: 75px !important;
height: 75px !important;
animation-name: pulse !important;
animation-duration: 1.5s !important;
animation-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1) !important;
animation-delay: 0 !important;
animation-direction: alternate !important;
animation-iteration-count: infinite !important;
animation-fill-mode: none !important;
animation-play-state: running !important;
estherkim marked this conversation as resolved.
Show resolved Hide resolved
}

@keyframes pulse {
0% {
transform: scale(1);
}
100% {
transform: scale(1.2);
}
}

amp-story-bling-link:hover .i-amphtml-story-bling-link-button {
background: rgba(255, 255, 255, 0.4) !important;
cursor: pointer !important;
}

amp-story-bling-link:hover .i-amphtml-story-bling-link-pulse {
animation: none !important;
}

.i-amphtml-story-bling-link-icon {
background-position: center !important;
background-repeat: no-repeat !important;
background-size: 36px 36px !important;
color: rgba(0, 0, 0, 0.54) !important;
width: 75px !important;
height: 75px !important;
display: flex !important;
}

.i-amphtml-story-bling-link-shopping-cart {
background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M7 18c-1.1 0-1.99.9-1.99 2S5.9 22 7 22s2-.9 2-2-.9-2-2-2zM1 2v2h2l3.6 7.59-1.35 2.45c-.16.28-.25.61-.25.96 0 1.1.9 2 2 2h12v-2H7.42c-.14 0-.25-.11-.25-.25l.03-.12.9-1.63h7.45c.75 0 1.41-.41 1.75-1.03l3.58-6.49c.08-.14.12-.31.12-.48 0-.55-.45-1-1-1H5.21l-.94-2H1zm16 16c-1.1 0-1.99.9-1.99 2s.89 2 1.99 2 2-.9 2-2-.9-2-2-2z"/><path d="M0 0h24v24H0z" fill="none"/></svg>') !important;
}
79 changes: 79 additions & 0 deletions extensions/amp-story/1.0/amp-story-bling-link.js
@@ -0,0 +1,79 @@
/**
* Copyright 2019 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview Bling link component that turns into a tooltip when clicked.
*/

import {Layout} from '../../../src/layout';

/** @const */
const CLASS_PREFIX = 'i-amphtml-story-bling-link';

/** @const */
const BUTTON_CLASS = `${CLASS_PREFIX}-button`;

/** @const */
const ICON_CLASS = `${CLASS_PREFIX}-icon`;

/** @const */
const SHOPPING_CART_ICON_CLASS = `${CLASS_PREFIX}-shopping-cart`;

/** @const */
const PULSE_CLASS = `${CLASS_PREFIX}-pulse`;

export class AmpStoryBlingLink extends AMP.BaseElement {
/** @param {!AmpElement} element */
constructor(element) {
super(element);
}

/** @override */
isLayoutSupported(layout) {
return layout == Layout.FIXED;
}

/** @override */
buildCallback() {
this.addPulseElement_();
this.addIconElement_();
}

/**
* Adds icon as a child element of <amp-story-bling-link>
* @private
*/
addIconElement_() {
const buttonEl = this.win.document.createElement('div');
estherkim marked this conversation as resolved.
Show resolved Hide resolved
buttonEl.classList.add(BUTTON_CLASS);

const iconEl = this.win.document.createElement('i');
iconEl.classList.add(ICON_CLASS, SHOPPING_CART_ICON_CLASS);

buttonEl.appendChild(iconEl);
this.element.appendChild(buttonEl);
}

/**
* Adds pulse as a child element of <amp-story-bling-link>
* @private
*/
addPulseElement_() {
const pulseEl = this.win.document.createElement('div');
pulseEl.classList.add(PULSE_CLASS);
this.element.appendChild(pulseEl);
}
}
1 change: 1 addition & 0 deletions extensions/amp-story/1.0/amp-story.css
Expand Up @@ -15,6 +15,7 @@
*/

@import './amp-story-access.css';
@import './amp-story-bling-link.css';
@import './amp-story-desktop-panels.css';
@import './amp-story-page-attachment.css';
@import './amp-story-templates.css';
Expand Down
2 changes: 2 additions & 0 deletions extensions/amp-story/1.0/amp-story.js
Expand Up @@ -41,6 +41,7 @@ import {AdvancementMode, getAnalyticsService} from './story-analytics';
import {AmpEvents} from '../../../src/amp-events';
import {AmpStoryAccess} from './amp-story-access';
import {AmpStoryBackground} from './background';
import {AmpStoryBlingLink} from './amp-story-bling-link';
import {AmpStoryBookend} from './bookend/amp-story-bookend';
import {AmpStoryConsent} from './amp-story-consent';
import {AmpStoryCtaLayer} from './amp-story-cta-layer';
Expand Down Expand Up @@ -2699,6 +2700,7 @@ export class AmpStory extends AMP.BaseElement {
AMP.extension('amp-story', '1.0', AMP => {
AMP.registerElement('amp-story', AmpStory, CSS);
AMP.registerElement('amp-story-access', AmpStoryAccess);
AMP.registerElement('amp-story-bling-link', AmpStoryBlingLink);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for now, but I suspect we don't actually want to call it this 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to ideas haha.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not saying I actually have any 😅

I'll sync with some folks on the monetization side who may be a bit closer to what publishers would actually expect. Definitely not blocking for now

AMP.registerElement('amp-story-bookend', AmpStoryBookend);
AMP.registerElement('amp-story-consent', AmpStoryConsent);
AMP.registerElement('amp-story-cta-layer', AmpStoryCtaLayer);
Expand Down