-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,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%'); | ||
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)); | ||
}); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
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,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> |
43 changes: 43 additions & 0 deletions
43
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,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> |
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 @@ | ||
- kushal |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be fine