Skip to content

Commit

Permalink
Make runtime display fallback when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
camelburrito committed Mar 11, 2016
1 parent b92ca61 commit 1d75fb9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 0 additions & 1 deletion builtins/amp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ export function installAd(win) {
this.viewer_.onVisibilityChanged(() => {
this.sendEmbedInfo_(this.isInViewport());
});

return loadPromise(this.iframe_);
});
}
Expand Down
6 changes: 6 additions & 0 deletions src/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,12 @@ export function createAmpElementProto(win, name, implementationClass) {
// element, (b) some realyout is expected and (c) fallback condition would
// be rare.
this.classList.toggle('amp-notsupported', state);
if (state == true) {
const fallbackElement = this.getFallback();
if (fallbackElement) {
this.resources_.scheduleLayout(this, fallbackElement);
}
}
};

/**
Expand Down
10 changes: 10 additions & 0 deletions test/functional/test-custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,18 @@ describe('CustomElement Service Elements', () => {
});

it('toggleFallback should toggle unsupported class', () => {
const fallback = element.appendChild(createWithAttr('fallback'));
const resourcesSpy = sandbox.spy();
element.resources_ = {
scheduleLayout: function(el, fb) {
if (el == element && fb == fallback) {
resourcesSpy();
}
},
};
element.toggleFallback(true);
expect(element).to.have.class('amp-notsupported');
expect(resourcesSpy.callCount).to.equal(1);

element.toggleFallback(false);
expect(element).to.not.have.class('amp-notsupported');
Expand Down
17 changes: 17 additions & 0 deletions test/manual/amp-ad.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,22 @@ <h1>AMP #0</h1>
data-aax_pubname="abc123"
data-aax_src="302">
</amp-embed>
<h2>Doubleclick no ad with placeholder and fallback</h2>
<amp-ad width=300 height=200
type="doubleclick"
data-slot="/4119129/doesnt-exist"
>
<div class="adv-placeholder" placeholder>
<amp-anim width=16 height=16 src="//www.repstatic.it/cless-mobile/main/amp/2016-v1//img/loader.gif">
<amp-img placeholder width=16 height=16 src="//www.repstatic.it/cless-mobile/main/amp/2016-v1//img/loader.gif">
</amp-img>
</amp-anim>
</div>
<div fallback>
<a href="http://www.repubblica.it/sport/2016/02/09/news/app_rep-133068373/">
<amp-img placeholder width=300 height=100 src="//www.repstatic.it/cless-mobile/main/amp/2016-v1/img/adv-300-100.jpg">
</a>
</div>
</amp-ad>
</body>
</html>

0 comments on commit 1d75fb9

Please sign in to comment.