diff --git a/examples/amp-story/bling-link.html b/examples/amp-story/bling-link.html new file mode 100644 index 000000000000..f0fb3d632103 --- /dev/null +++ b/examples/amp-story/bling-link.html @@ -0,0 +1,69 @@ + + + + + + + My Story + + + + + + + + + + + +

Hello World

+

This is the cover page of this story.

+
+
+ + + +

First Page

+

This is the first page of this story.

+
+
+ + + +

Second Page

+

This is the second page of this story.

+
+ + + + + +
+ +
+ + diff --git a/examples/amp-story/img/merch1.jpg b/examples/amp-story/img/merch1.jpg new file mode 100644 index 000000000000..ba924d9e4038 Binary files /dev/null and b/examples/amp-story/img/merch1.jpg differ diff --git a/extensions/amp-story/1.0/amp-story-bling-link.css b/extensions/amp-story/1.0/amp-story-bling-link.css new file mode 100644 index 000000000000..0e48dbbddc9b --- /dev/null +++ b/extensions/amp-story/1.0/amp-story-bling-link.css @@ -0,0 +1,71 @@ +/** + * 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. + */ + + .i-amphtml-story-bling-link { + position: relative !important; + width: 90px !important; + height: 90px !important; +} + +.i-amphtml-story-bling-link-circle { + 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: pulse 1.5s cubic-bezier(0.4, 0.0, 0.2, 1) infinite alternate !important; +} + +@keyframes pulse { + 0% { + transform: scale(1); + } + 100% { + transform: scale(1.2); + } +} + +.i-amphtml-story-bling-link:hover .i-amphtml-story-bling-link-circle { + background: rgba(255, 255, 255, 0.4) !important; +} + +.i-amphtml-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,') !important; +} diff --git a/extensions/amp-story/1.0/amp-story-bling-link.js b/extensions/amp-story/1.0/amp-story-bling-link.js new file mode 100644 index 000000000000..25f7f1ad7f47 --- /dev/null +++ b/extensions/amp-story/1.0/amp-story-bling-link.js @@ -0,0 +1,70 @@ +/** + * 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 {htmlFor} from '../../../src/static-template'; + +/** + * Links that are bling links. + * @const {string} + */ +export const BLING_LINK_SELECTOR = 'a.i-amphtml-story-bling-link'; + +export const BLING_LINK_BUILT = 'built'; + +export class AmpStoryBlingLink { + /** + * Builds bling link + * @param {!Element} element + */ + static build(element) { + if (element[BLING_LINK_BUILT]) { + return; + } + + this.addPulseElement_(element); + this.addIconElement_(element); + + element[BLING_LINK_BUILT] = true; + } + + /** + * Adds icon as a child element of + * @param {!Element} element + * @private + */ + static addIconElement_(element) { + const iconEl = htmlFor(element)` +
+ +
`; + element.appendChild(iconEl); + } + + /** + * Adds pulse as a child element of + * @param {!Element} element + * @private + */ + static addPulseElement_(element) { + const pulseEl = htmlFor(element)` +
`; + element.appendChild(pulseEl); + } +} diff --git a/extensions/amp-story/1.0/amp-story-page.js b/extensions/amp-story/1.0/amp-story-page.js index 865151250985..a006ceacb257 100644 --- a/extensions/amp-story/1.0/amp-story-page.js +++ b/extensions/amp-story/1.0/amp-story-page.js @@ -31,6 +31,7 @@ import { } from './amp-story-store-service'; import {AdvancementConfig} from './page-advancement'; import {AmpEvents} from '../../../src/amp-events'; +import {AmpStoryBlingLink, BLING_LINK_SELECTOR} from './amp-story-bling-link'; import { AmpStoryEmbeddedComponent, EMBED_ID_ATTRIBUTE_NAME, @@ -509,6 +510,7 @@ export class AmpStoryPage extends AMP.BaseElement { findAndPrepareEmbeddedComponents_(forceResize = false) { this.addClickShieldToEmbeddedComponents_(); this.resizeInteractiveEmbeddedComponents_(forceResize); + this.addStylesToBlingLinks_(); } /** @@ -562,6 +564,15 @@ export class AmpStoryPage extends AMP.BaseElement { }); } + /** + * Adds icon and pulse animation to bling links + */ + addStylesToBlingLinks_() { + scopedQuerySelectorAll(this.element, BLING_LINK_SELECTOR).forEach(el => { + AmpStoryBlingLink.build(el); + }); + } + /** @private */ markPageAsLoaded_() { dispatch( diff --git a/extensions/amp-story/1.0/amp-story.css b/extensions/amp-story/1.0/amp-story.css index 63e956cf01b9..630bb596d548 100644 --- a/extensions/amp-story/1.0/amp-story.css +++ b/extensions/amp-story/1.0/amp-story.css @@ -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';