-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds an access vendor named scroll - If user is authenticated, adds UI element to page
- Loading branch information
Showing
8 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
41 changes: 41 additions & 0 deletions
41
extensions/amp-access-scroll/0.1/test/validator-amp-access-scroll.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
62 changes: 62 additions & 0 deletions
62
extensions/amp-access-scroll/0.1/test/validator-amp-access-scroll.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
28 changes: 28 additions & 0 deletions
28
extensions/amp-access-scroll/validator-amp-access-scroll.protoascii
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters