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

Initial commit of amp-access-scroll #12955

Merged
merged 4 commits into from
Feb 5, 2018
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
2 changes: 2 additions & 0 deletions build-system/tasks/presubmit-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ const forbiddenTerms = {
'src/cookies.js',
'src/service/cid-impl.js',
'testing/fake-dom.js',
'extensions/amp-access-scroll/0.1/scroll-impl.js',
'extensions/amp-analytics/0.1/vendors.js',
'extensions/amp-youtube/0.1/amp-youtube.js',
],
Expand Down Expand Up @@ -448,6 +449,7 @@ const forbiddenTerms = {
whitelist: [
'build-system/amp.extern.js',
'extensions/amp-access/0.1/amp-access.js',
'extensions/amp-access-scroll/0.1/scroll-impl.js',
'src/service/url-replacements-impl.js',
],
},
Expand Down
31 changes: 31 additions & 0 deletions examples/scroll.amp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>Scroll example</title>
<link rel="canonical" href="amps.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Questrial' rel='stylesheet' type='text/css'>
<script id="amp-access" type="application/json">
{
"vendor": "scroll"
}
</script>
<script async custom-element="amp-access" src="https://cdn.ampproject.org/v0/amp-access-0.1.js"></script>
<script async custom-element="amp-access-scroll" src="https://cdn.ampproject.org/v0/amp-access-scroll-0.1.js"></script>
<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>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>

<h2>Scroll</h2>

<section amp-access="NOT scroll">
ad goes here
</section>

<amp-access-scroll>
</amp-access-scroll>

</body>
</html>
35 changes: 35 additions & 0 deletions extensions/amp-access-scroll/0.1/amp-access-scroll.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2018 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-access-scroll-bar {
height: 44px;
position: fixed;
left: 0;
width: 100%;
background: transparent;
z-index: 2147483647;
bottom: 0;
}
.amp-access-scroll-bar.scroll-bar-top {
top: 0;
bottom: auto;
}
.amp-access-scroll-placeholder {
padding-top: 8px;
padding-left: 16px;
background-color: #fff;
z-index: 11;
}
30 changes: 30 additions & 0 deletions extensions/amp-access-scroll/0.1/amp-access-scroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2018 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.
*/

import {ScrollAccessVendor} from './scroll-impl';
import {Services} from '../../../src/services';

AMP.extension('amp-access-scroll', '0.1', function(AMP) {
AMP.registerServiceForDoc(
'scroll',
function(ampdoc) {
return Services.accessServiceForDoc(ampdoc).then(accessService => {
const vendor = new ScrollAccessVendor(ampdoc, accessService);
accessService.registerVendor('scroll', vendor);
return vendor;
});
});
});
131 changes: 131 additions & 0 deletions extensions/amp-access-scroll/0.1/scroll-impl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/**
* Copyright 2018 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.
*/

import {CSS} from '../../../build/amp-access-scroll-0.1.css';
import {AccessClientAdapter} from '../../amp-access/0.1/amp-access-client';
import {installStylesForDoc} from '../../../src/style-installer';

const TAG = 'amp-access-scroll-elt';

/** @const {!JsonObject} */
const CONFIG = /** @type {!JsonObject} */ ({
'authorization': 'https://connect.scroll.com/amp/access?' +
'rid=READER_ID&o=SOURCE_URL&' +
'cid=CLIENT_ID(cid-fallback-cookie)',
'pingback': 'https://connect.scroll.com/amp/pingback?' +
'rid=READER_ID&o=SOURCE_URL&cid=CLIENT_ID(cid-fallback-cookie)&' +
'd=AUTHDATA(scroll)&v=AUTHDATA(visitId)',
'namespace': 'scroll',
});


/**
* amp-access vendor that authenticates against the scroll.com service.
* If the user is authenticated, also adds a fixed position iframe
* to the page.
*
* A little gross, but avoid some duplicate code by inheriting
* from ClientAdapter.
* @implements {../../amp-access/0.1/access-vendor.AccessVendor}
*/
export class ScrollAccessVendor extends AccessClientAdapter {
/**
* @param ampdoc {!../../../src/service/ampdoc-impl.AmpDoc}
* @param accessService {!../../amp-access/0.1/amp-access.AccessService}
*/
constructor(ampdoc, accessService) {
super(ampdoc, CONFIG, {
buildUrl: accessService.buildUrl.bind(accessService),
collectUrlVars: accessService.collectUrlVars_.bind(accessService),
});

/** @private {!../../amp-access/0.1/amp-access.AccessService} */
this.accessService_ = accessService;
}

authorize() {
return super.authorize()
.then(response => {
if (response && response.scroll) {
new ScrollElement(this.ampdoc).show(this.accessService_);
}
});
}
}

/**
* UI for logged-in Scroll users.
*
* Presents a fixed bar at the bottom of the screen.
*/
class ScrollElement {
/**
* @param ampdoc {!../../../src/service/ampdoc-impl.AmpDoc}
*/
constructor(ampdoc) {
installStylesForDoc(ampdoc, CSS, () => {}, false, TAG);

/** @const {!../../../src/service/ampdoc-impl.AmpDoc} */
this.ampdoc = ampdoc;

/** @const {!Element} */
this.wrapper_ = document.createElement('div');
this.wrapper_.classList.add('amp-access-scroll-bar');
ampdoc.getBody().appendChild(this.wrapper_);

/** @const {!Element} */
this.placeholder_ = document.createElement('div');
this.placeholder_.classList.add('amp-access-scroll-placeholder');
this.wrapper_.appendChild(this.placeholder_);

const img = document.createElement('img');
img.setAttribute('src',
'https://static.scroll.com/assets/icn-scroll-logo.svg');
img.setAttribute('layout', 'fixed');
img.setAttribute('width', 26);
img.setAttribute('height', 26);
this.placeholder_.appendChild(img);

/** @const {!Element} */
this.iframe_ = document.createElement('iframe');
this.iframe_.setAttribute('scrolling', 'no');
this.iframe_.setAttribute('frameborder', '0');
this.iframe_.setAttribute('allowtransparency', 'true');
this.iframe_.setAttribute('title', 'Scroll');
this.iframe_.setAttribute('width', '100%');
this.iframe_.setAttribute('height', '100%');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to set sandbox for this iframe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be fine

this.iframe_.setAttribute('sandbox', 'allow-scripts allow-same-origin ' +
'allow-top-navigation allow-popups ' +
'allow-popups-to-escape-sandbox');
this.wrapper_.appendChild(this.iframe_);

}

/**
* @param accessService {!../../amp-access/0.1/amp-access.AccessService}
*/
show(accessService) {
accessService.getAccessReaderId()
.then(readerId => {
this.iframe_.onload = () => {
this.wrapper_.removeChild(this.placeholder_);
};
this.iframe_.setAttribute('src',
'https://connect.scroll.com/amp/scrollbar?readerId=' +
encodeURIComponent(readerId));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--
Copyright 2018 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.
-->
<!--
Test Description:
Tests support for the amp-access-scroll tag and authentication.
-->
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<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>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<script async custom-element="amp-access" src="https://cdn.ampproject.org/v0/amp-access-0.1.js"></script>
<script async custom-element="amp-access-scroll" src="https://cdn.ampproject.org/v0/amp-access-scroll-0.1.js"></script>
<script id="amp-access" type="application/json">
{
"vendor": "scroll"
}
</script>
</head>
<body>
<section amp-access="NOT scroll">
ad goes here
</section>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
PASS
| <!--
| Copyright 2018 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.
| -->
| <!--
| Test Description:
| Tests support for the amp-access-scroll tag and authentication.
| -->
| <!doctype html>
| <html ⚡>
| <head>
| <meta charset="utf-8">
| <link rel="canonical" href="./regular-html-version.html">
| <meta name="viewport" content="width=device-width,minimum-scale=1">
| <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>
| <script async src="https://cdn.ampproject.org/v0.js"></script>
| <script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
| <script async custom-element="amp-access" src="https://cdn.ampproject.org/v0/amp-access-0.1.js"></script>
| <script async custom-element="amp-access-scroll" src="https://cdn.ampproject.org/v0/amp-access-scroll-0.1.js"></script>
| <script id="amp-access" type="application/json">
| {
| "vendor": "scroll"
| }
| </script>
| </head>
| <body>
| <section amp-access="NOT scroll">
| ad goes here
| </section>
| </body>
| </html>
1 change: 1 addition & 0 deletions extensions/amp-access-scroll/OWNERS.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- kushal
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2018 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.
#

tags: { # amp-access-scroll
html_format: AMP
tag_name: "SCRIPT"
requires_extension: "amp-access"
extension_spec: {
name: "amp-access-scroll"
allowed_versions: "0.1"
allowed_versions: "latest"
requires_usage: NONE
}
attr_lists: "common-extension-attrs"
}
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var unminified3pTarget = 'dist.3p/current/integration.js';
declareExtension('amp-3q-player', '0.1', {hasCss: false});
declareExtension('amp-access', '0.1', {hasCss: true});
declareExtension('amp-access-laterpay', '0.1', {hasCss: true});
declareExtension('amp-access-scroll', '0.1', {hasCss: true});
declareExtension('amp-accordion', '0.1', {hasCss: false});
declareExtension('amp-ad', '0.1', {hasCss: true});
declareExtension('amp-ad-network-adsense-impl', 0.1, {hasCss: false});
Expand Down
8 changes: 7 additions & 1 deletion validator/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"name": "amphtml-validator",
"version": "1.0.21",
"description": "Official validator for AMP HTML (www.ampproject.org)",
"keywords": ["AMP", "validator", "validate", "AMP HTML", "Accelerated Mobile Pages"],
"keywords": [
"AMP",
"validator",
"validate",
"AMP HTML",
"Accelerated Mobile Pages"
],
"engines": {
"node": ">=0.10.25"
},
Expand Down