-
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
[DRAFT] <amp-embed type="insticator"> #23928
Changes from 4 commits
ce8a869
5360271
39a0491
6384f77
4b12980
f154c66
285ec22
793d332
732d146
e8ff916
232585e
6bf457a
bef3245
50d46fb
461cba4
a94add8
5902f0b
1d884c4
1e83788
78209cf
6c6ff83
3217f7e
7c5b757
c15d775
b00b29a
b1e86f7
a7a6f79
7a18c14
eb877b8
ca32ebe
253be0d
9b14ed6
b3b6a4e
80d2610
12cf618
5d092de
06f9928
6d54912
ce4f748
9df25d4
7d9f9bb
2e1361c
b73a7e3
d184d3a
44f0cae
328d501
e43fb55
cc27047
fa492de
feb6772
eeb8e18
10ae65b
11edc2f
8eed75d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// !!!!!!!!!! ---------- AMP EMBED - INSTICATOR ---------- !!!!!!!!!! // | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add the amp license header to this file. |
||
|
||
import { validateData, loadScript } from '../3p/3p'; | ||
|
||
// ------- HELPER VARIABLES ------- // | ||
//reusable URL references to ads, embed and the library | ||
//Don't forget to preconnect and prefetch as it's described in the docs | ||
//https://github.com/ampproject/amphtml/blob/master/ads/README.md | ||
const url = { | ||
ads: 'https://drhn9v8cwg89y.cloudfront.net', | ||
embed: 'https://d3lcz8vpax4lo2.cloudfront.net', | ||
lib: 'https://testthisshit.online/amp-embed-lib/insticator.js' | ||
}; | ||
|
||
// ------- HELPER FUNCTIONS ------- // | ||
function createInitialMarkup() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for flexibility in a long run, I suggest you only leave config related logic in this file, and move logic to |
||
return ` | ||
<div id="insticator-container"> | ||
<div id="div-insticator-ad-1"></div> | ||
<div id="insticator-embed"> | ||
<iframe id="insticator-iframe" scrolling="no" frameborder="0" allowtransparency="true"></iframe> | ||
</div> | ||
<div id="div-insticator-ad-2"></div> | ||
</div> | ||
`; | ||
} | ||
|
||
function createTemplate(domString) { | ||
const template = document.createElement('template'); | ||
template.innerHTML = domString; | ||
return template.content; | ||
} | ||
|
||
function appendElement(location, el) { | ||
location.appendChild(el); | ||
} | ||
|
||
function createElement(location, el, attrs) { | ||
const newEl = location.createElement(el); | ||
Object.entries(attrs).forEach(attr => newEl.setAttribute(attr[0], attr[1])); | ||
return newEl; | ||
} | ||
|
||
function getRequest(file, callback, componentContainer) { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.onreadystatechange = () => xhr.readyState == 4 && xhr.status == 200 ? callback(JSON.parse(xhr.responseText), componentContainer) : null; | ||
xhr.open('GET', file, true); | ||
xhr.send(); | ||
} | ||
|
||
function appendAds(ads, componentContainer) { | ||
Object.entries(ads).forEach(ad => appendElement(componentContainer.querySelector(`#div-insticator-ad-${ad[0][ad[0].length -1]}`), createElement(componentContainer.ownerDocument, 'amp-ad', ad[1]))); | ||
} | ||
|
||
/* | ||
* @param {!Object} componentContainer | ||
*/ | ||
function createComponent(componentContainer) { | ||
// get data attribute from the amp-insticator tag | ||
const embedId = componentContainer.getAttribute('data-embed-id'); | ||
|
||
// store DOM elements | ||
const insticatorContainer = componentContainer.querySelector('#insticator-container'); | ||
const embedIframe = componentContainer.querySelector('#insticator-iframe'); | ||
const embedApp = createElement(componentContainer.ownerDocument, 'div', { | ||
id: 'app' | ||
}); | ||
const embedScript = createElement(componentContainer.ownerDocument, 'script', { | ||
type: 'text/javascript', | ||
src: `${url.embed}/embed-code/${embedId}.js` | ||
}); | ||
|
||
// append content to iframe | ||
appendElement(embedIframe.contentWindow.document.body, embedApp); | ||
appendElement(embedIframe.contentWindow.document.head, embedScript); | ||
// append ads | ||
getRequest(`${url.ads}/test/ad_settings/${embedId}.js`, (ads, componentContainer) => appendAds(ads, componentContainer), componentContainer); | ||
} | ||
|
||
/* | ||
* @param {!Window} global | ||
* @param {!Object} data | ||
*/ | ||
export function insticator(global, data) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. code style: public function at top before all private functions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
validateData(data, ['embedId']); | ||
const componentContainer = global.document.getElementById('c'); | ||
componentContainer.setAttribute('data-embed-id', data.embedId); | ||
appendElement(componentContainer, createTemplate(createInitialMarkup())); | ||
createComponent(componentContainer); | ||
loadScript(global, url.lib); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!--- | ||
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. | ||
--> | ||
|
||
# Insticator | ||
|
||
## Example of Insticator's widget implementation | ||
|
||
|
||
```html | ||
<amp-embed | ||
type="insticator" | ||
data-embed-id="ACCOUNT-ID"> | ||
</amp-embed> | ||
``` | ||
|
||
## Configuration | ||
|
||
For details on the configuration semantics, please contact [Insticator](https://www.insticator.com/contact/). | ||
|
||
### Required parameters | ||
|
||
- `data-embed-id`: Uniquie ID of your Insticator account |
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.
would you please also implement renderStart API?
in your remote loaded
insticator.js
, it should callcontext.renderStart
once content is ready to show. This basically gives AMP runtime signal when to hide loading indicator and show your content.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.
renderStart implemented
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.
👍verified amp runtime is getting this signal.