Skip to content

Commit

Permalink
Initial commit of amp-access-scroll
Browse files Browse the repository at this point in the history
- Adds an access vendor named scroll
- If user is authenticated, adds UI element to page
  • Loading branch information
kushal committed Jan 22, 2018
1 parent 1943c6e commit 66b9aa1
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 0 deletions.
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;
});
});
});
116 changes: 116 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,116 @@
/**
* 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 {Services} from '../../../src/services';
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 {
constructor(ampdoc, accessService) {
super(ampdoc, CONFIG, {
buildUrl: accessService.buildUrl.bind(accessService),
collectUrlVars: accessService.collectUrlVars_.bind(accessService),
});
this.element_ = null;
}

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

/**
* @extends {HTMLElement}
*/
class ScrollElement extends HTMLElement {
constructor(ampdoc) {
super();
installStylesForDoc(ampdoc, CSS, () => {}, false, TAG);

this.ampdoc = ampdoc;

this.wrapper_ = document.createElement('div');
this.wrapper_.classList.add('amp-access-scroll-bar');
this.appendChild(this.wrapper_);


this.placeholder_ = document.createElement('div');
this.placeholder_.classList.add('amp-access-scroll-placeholder');
this.wrapper_.appendChild(this.placeholder_);

const img = document.createElement('amp-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);

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%');
this.wrapper_.appendChild(this.iframe_);
}

show() {
Services.accessServiceForDoc(this.ampdoc)
.then(accessService => accessService.getAccessReaderId())
.then(readerId => {
this.iframe_.onload = () => {
this.wrapper_.removeChild(this.placeholder_);
};
this.iframe_.setAttribute('src',
'https://connect.scroll.com/amp/scrollbar?readerId=' + readerId);
});
}
}

customElements.define('amp-access-scroll-elt',
/** @type {function(new:HTMLElement)} */ (ScrollElement));
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
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-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,62 @@
<!--
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-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>

</script>
</head>
<body>

<amp-access
data-account="906043040001"
data-video-id="1401169490001"
data-player-id="180a5658-8be8-4f33-8eba-d562ab41b40c"
layout="responsive" width="480" height="270">
</amp-access>
<!-- Valid: data-video-id, data-player-id are optional;
leaving them out results in the default config. -->
<amp-brightcove
data-account="906043040001"
layout="responsive" width="480" height="270">
</amp-brightcove>
<!-- Valid: most "data-*" attributes are bindable. -->
<amp-brightcove
data-account="906043040001"
layout="responsive" width="480" height="270"
[data-account]="foo.bar" [data-embed]="foo.bar" [data-player]="foo.bar"
[data-player-id]="foo.bar" [data-playlist-id]="foo.bar"
[data-video-id]="foo.bar">
</amp-brightcove>
<!-- Invalid: data-account is mandatory;
leaving them out results in an error. -->
<amp-brightcove
layout="responsive" width="480" height="270">
</amp-brightcove>
</body>
</html>
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 @@ -63,6 +63,7 @@ var unminified3pTarget = 'dist.3p/current/integration.js';
declareExtension('amp-3q-player', '0.1', false);
declareExtension('amp-access', '0.1', true);
declareExtension('amp-access-laterpay', '0.1', true);
declareExtension('amp-access-scroll', '0.1', true);
declareExtension('amp-accordion', '0.1', false);
declareExtension('amp-ad', '0.1', true);
declareExtension('amp-ad-network-adsense-impl', 0.1, false);
Expand Down

0 comments on commit 66b9aa1

Please sign in to comment.