-
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.
- Loading branch information
1 parent
4a23b59
commit eb98861
Showing
11 changed files
with
238 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 |
---|---|---|
|
@@ -7,4 +7,5 @@ Jake Moening | |
Jordan Adler | ||
Kent Brewster | ||
Malte Ubl | ||
Niall Kennedy | ||
Taylor Savage |
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 @@ | ||
<!doctype html> | ||
<html ⚡> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Vine examples</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 async custom-element="amp-vine" src="https://cdn.ampproject.org/v0/amp-vine-0.1.js"></script> | ||
<style>body {opacity: 0}</style><noscript><style>body {opacity: 1}</style></noscript> | ||
<script async src="https://cdn.ampproject.org/v0.js"></script> | ||
</head> | ||
<body> | ||
<h2>Vine</h2> | ||
|
||
<amp-vine | ||
data-vineid="MdKjXez002d" | ||
width="381" | ||
height="381" | ||
layout="responsive"> | ||
</amp-vine> | ||
|
||
<amp-vine | ||
data-vineid="e2eTlxAYvqO" | ||
width="400" | ||
height="400" | ||
layout="responsive"> | ||
</amp-vine> | ||
</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
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,73 @@ | ||
|
||
/** | ||
* Copyright 2015 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 {isLayoutSizeDefined} from '../../../src/layout'; | ||
import {loadPromise} from '../../../src/event-helper'; | ||
|
||
class AmpVine extends AMP.BaseElement { | ||
|
||
/** @override */ | ||
preconnectCallback(onLayout) { | ||
// the Vine iframe | ||
this.preconnect.url('https://vine.co', onLayout); | ||
// Vine assets loaded in the iframe | ||
this.preconnect.url('https://v.cdn.vine.co', onLayout); | ||
} | ||
|
||
/** @override */ | ||
isLayoutSupported(layout) { | ||
return isLayoutSizeDefined(layout); | ||
} | ||
|
||
/** @override */ | ||
layoutCallback() { | ||
const vineid = AMP.assert(this.element.getAttribute('data-vineid'), | ||
'The data-vineid attribute is required for <amp-vine> %s', | ||
this.element); | ||
const width = this.element.getAttribute('width'); | ||
const height = this.element.getAttribute('height'); | ||
|
||
const iframe = document.createElement('iframe'); | ||
iframe.setAttribute('frameborder', '0'); | ||
iframe.src = 'https://vine.co/v/' + | ||
encodeURIComponent(vineid) + '/embed/simple'; | ||
|
||
this.applyFillContent(iframe); | ||
|
||
iframe.width = width; | ||
iframe.height = height; | ||
this.element.appendChild(iframe); | ||
|
||
/** @private {?Element} */ | ||
this.iframe_ = iframe; | ||
|
||
return loadPromise(iframe); | ||
} | ||
|
||
/** @override */ | ||
documentInactiveCallback() { | ||
if (this.iframe_ && this.iframe_.contentWindow) { | ||
this.iframe_.contentWindow./*OK*/postMessage('pause', '*'); | ||
} | ||
|
||
// No need to do layout later - user action will be expect to resume | ||
// the playback | ||
return false; | ||
} | ||
} | ||
|
||
AMP.registerElement('amp-vine', AmpVine); |
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 2015 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 {createIframePromise} from '../../../../testing/iframe'; | ||
require('../amp-vine'); | ||
import {adopt} from '../../../../src/runtime'; | ||
|
||
adopt(window); | ||
|
||
describe('amp-vine', () => { | ||
function getVine(vineId, opt_responsive) { | ||
return createIframePromise().then(iframe => { | ||
const vine = iframe.doc.createElement('amp-vine'); | ||
vine.setAttribute('data-vineid', vineId); | ||
vine.setAttribute('width', 400); | ||
vine.setAttribute('height', 400); | ||
if (opt_responsive) { | ||
vine.setAttribute('layout', 'responsive'); | ||
} | ||
iframe.doc.body.appendChild(vine); | ||
vine.implementation_.layoutCallback(); | ||
return vine; | ||
}); | ||
} | ||
|
||
it('renders', () => { | ||
return getVine('MdKjXez002d').then(vine => { | ||
const iframe = vine.querySelector('iframe'); | ||
expect(iframe).to.not.be.null; | ||
expect(iframe.tagName).to.equal('IFRAME'); | ||
expect(iframe.src).to.equal('https://vine.co/v/MdKjXez002d/embed/simple'); | ||
expect(iframe.getAttribute('width')).to.equal('400'); | ||
expect(iframe.getAttribute('height')).to.equal('400'); | ||
}); | ||
}); | ||
|
||
it('renders responsively', () => { | ||
return getVine('MdKjXez002d', true).then(vine => { | ||
const iframe = vine.querySelector('iframe'); | ||
expect(iframe).to.not.be.null; | ||
expect(iframe.className).to.match(/-amp-fill-content/); | ||
}); | ||
}); | ||
|
||
it('requires data-vineid', () => { | ||
return getVine('').should.eventually.be.rejectedWith( | ||
/The data-vineid attribute is required for/); | ||
}); | ||
}); |
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,33 @@ | ||
/** | ||
* Copyright 2015 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. | ||
*/ | ||
|
||
### <a name="amp-vine"></a> `amp-vine` | ||
|
||
Displays a Vine simple embed | ||
|
||
Example: | ||
|
||
<amp-vine width="400" height="400" | ||
data-vineid="MdKjXez002d"> | ||
</amp-vine> | ||
|
||
A Vine simple embed has equal width and height. | ||
|
||
#### Attributes | ||
|
||
**data-vineid** | ||
|
||
The ID of the Vine. In a URL like https://vine.co/v/MdKjXez002d `MdKjXez002d` is the vineID. |
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
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
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,33 @@ | ||
<!doctype html> | ||
<html ⚡> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>AMP #0</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 async custom-element="amp-vine" src="../../dist/v0/amp-vine-0.1.max.js"></script> | ||
<style> | ||
body { | ||
opacity: 0; | ||
max-width: 527px; | ||
font-family: 'Questrial', Arial; | ||
} | ||
|
||
amp-vine iframe { | ||
margin: 30px; | ||
padding: 30px; | ||
border: 10px solid red; | ||
} | ||
</style><noscript><style>body {opacity: 1}</style></noscript> | ||
<script async src="../../dist/amp.js" development></script> | ||
</head> | ||
<body> | ||
<h1>amp #0</h1> | ||
<amp-vine | ||
data-vineid="MdKjXez002d" | ||
width="400" | ||
height="400" | ||
layout="responsive"></amp-vine> | ||
</body> | ||
</html> |