Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Dec 17, 2015
2 parents a7c0a36 + 23f4e5d commit 3f14c5c
Show file tree
Hide file tree
Showing 65 changed files with 3,029 additions and 1,419 deletions.
27 changes: 27 additions & 0 deletions build-system/tasks/presubmit-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ var requiresReviewPrivacy =
'being privacy sensitive. Please file an issue asking for permission' +
' to use if you have not yet done so.';

var privateServiceFactory = 'This service should only be installed in ' +
'the whitelisted files. Other modules should use a public function ' +
'typically called serviceNameFor.';

// Terms that must not appear in our source files.
var forbiddenTerms = {
'DO NOT SUBMIT': '',
Expand All @@ -44,11 +48,32 @@ var forbiddenTerms = {
'validator/validator-in-browser.js',
]
},
// Service factories that should only be installed once.
'installCidService': {
message: privateServiceFactory,
whitelist: [
'src/service/cid-impl.js',
'extensions/amp-analytics/0.1/amp-analytics.js',
'extensions/amp-analytics/0.1/test/test-amp-analytics.js',
'test/functional/test-cid.js',
'test/functional/test-url-replacements.js'
],
},
// Privacy sensitive
'cidFor': {
message: requiresReviewPrivacy,
whitelist: [
'src/cid.js',
'src/service/cid-impl.js',
'src/url-replacements.js',
'test/functional/test-cid.js',
],
},
'getBaseCid': {
message: requiresReviewPrivacy,
whitelist: [
'src/service/cid-impl.js',
'src/viewer.js',
'test/functional/test-cid.js',
],
},
Expand Down Expand Up @@ -78,13 +103,15 @@ var forbiddenTerms = {
'src/cookies.js',
'src/experiments.js',
'test/functional/test-cookies.js',
'test/functional/test-url-replacements.js',
'tools/experiments/experiments.js',
]
},
'eval\\(': '',
'localStorage': {
message: requiresReviewPrivacy,
whitelist: [
'extensions/amp-analytics/0.1/test/test-amp-analytics.js',
'test/_init_tests.js',
'src/service/cid-impl.js',
'test/functional/test-cid.js',
Expand Down
123 changes: 1 addition & 122 deletions builtins/amp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,83 +18,19 @@ import {BaseElement} from '../src/base-element';
import {assert} from '../src/asserts';
import {getIntersectionChangeEntry} from '../src/intersection-observer';
import {isLayoutSizeDefined} from '../src/layout';
import {setStyles} from '../src/style';
import {loadPromise} from '../src/event-helper';
import {registerElement} from '../src/custom-element';
import {getIframe, listenOnce, postMessage, prefetchBootstrap} from
'../src/3p-frame';
import {adPrefetch, adPreconnect} from '../ads/_prefetch';
import {timer} from '../src/timer';
import {vsyncFor} from '../src/vsync';


/**
* Preview phase only default backfill for ads. If the ad
* cannot fill the slot one of these will be displayed instead.
* @private @const
*/
const BACKFILL_IMGS_ = {
'300x200': [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
],
'320x50': [
'[email protected]',
'[email protected]',
],
};

/** @private @const */
const BACKFILL_DIMENSIONS_ = [
[300, 200],
[320, 50],
];

/** @private @const These tags are allowed to have fixed positioning */
const POSITION_FIXED_TAG_WHITELIST = {
'AMP-LIGHTBOX': true
};

/**
* Preview phase helper to score images through their dimensions.
* @param {!Array<!Array<number>>} dims
* @param {number} maxWidth
* @param {number} maxHeight
* visibleForTesting
*/
export function scoreDimensions_(dims, maxWidth, maxHeight) {
return dims.map(function(dim) {
const width = dim[0];
const height = dim[1];
const widthScore = Math.abs(width - maxWidth);
// if the width is over the max then we need to penalize it
const widthPenalty = Math.abs((maxWidth - width) * 3);
// we add a multiplier to height as we prioritize it more than width
const heightScore = Math.abs(height - maxHeight) * 2;
// if the height is over the max then we need to penalize it
const heightPenalty = Math.abs((maxHeight - height) * 2.5);

return (widthScore - widthPenalty) + (heightScore - heightPenalty);
});
}

/**
* Preview phase helper to update a @1x.png string to @2x.png.
* @param {!Object<string, !Array<string>>} images
* visibleForTesting
*/
export function upgradeImages_(images) {
Object.keys(images).forEach(key => {
const curDimImgs = images[key];
curDimImgs.forEach((item, index) => {
curDimImgs[index] = item.replace(/@1x\.png$/, '@2x.png');
});
});
}


/**
* @param {!Window} win Destination window for the new element.
Expand Down Expand Up @@ -155,9 +91,6 @@ export function installAd(win) {
/** @private {?Element} */
this.fallback_ = this.getFallback();

/** @private {boolean} */
this.isDefaultFallback_ = false;

/** @private {boolean} */
this.isInFixedContainer_ = false;

Expand All @@ -177,14 +110,6 @@ export function installAd(win) {

/** @private {boolean} */
this.shouldSendIntersectionChanges_ = false;

if (!this.fallback_) {
this.isDefaultFallback_ = true;

if (this.getDpr() >= 0.5) {
upgradeImages_(BACKFILL_IMGS_);
}
}
}

/**
Expand Down Expand Up @@ -351,56 +276,10 @@ export function installAd(win) {
* @private
*/
noContentHandler_() {
if (this.isDefaultFallback_) {
this.setDefaultFallback_();
this.element.appendChild(this.fallback_);
}
this.element.removeChild(this.iframe_);
this.toggleFallback(true);
}

/**
* This is a preview-phase only thing where if the ad says that it
* cannot fill the slot we select from a small set of default
* banners.
* @private
* visibleForTesting
*/
setDefaultFallback_() {
const a = document.createElement('a');
a.href = 'https://www.ampproject.org';
a.target = '_blank';
a.setAttribute('fallback', '');
const img = new Image();
setStyles(img, {
width: 'auto',
height: '100%',
margin: 'auto',
});

const winner = this.getFallbackImage_();
img.src = `https://ampproject.org/backfill/${winner}`;
this.fallback_ = a;
a.appendChild(img);
}

/**
* Picks a random backfill image for the case that no real ad can be
* shown.
* @private
* @return {string} The image URL.
*/
getFallbackImage_() {
const scores = scoreDimensions_(BACKFILL_DIMENSIONS_,
this.element./*REVIEW*/clientWidth,
this.element./*REVIEW*/clientHeight);
const dims = BACKFILL_DIMENSIONS_[
scores.indexOf(Math.max.apply(Math, scores))];
const images = BACKFILL_IMGS_[dims.join('x')];
// do we need a more sophisticated randomizer?
return images[Math.floor(Math.random() * images.length)];
}
};
}

registerElement(win, 'amp-ad', AmpAd);
}
21 changes: 11 additions & 10 deletions builtins/amp-pixel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ export function installPixel(win) {

/** @override */
layoutCallback() {
let src = this.element.getAttribute('src');
src = urlReplacementsFor(this.getWin()).expand(this.assertSource(src));
const image = new Image();
image.src = src;
image.width = 1;
image.height = 1;
// Make it take zero space
this.element.style.width = 0;
this.element.appendChild(image);
return Promise.resolve();
const src = this.element.getAttribute('src');
return urlReplacementsFor(this.getWin()).expand(this.assertSource(src))
.then(src => {
const image = new Image();
image.src = src;
image.width = 1;
image.height = 1;
// Make it take zero space
this.element.style.width = 0;
this.element.appendChild(image);
});
}

assertSource(src) {
Expand Down
13 changes: 0 additions & 13 deletions examples/ads.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,5 @@ <h2>Doubleclick no ad with placeholder and fallback</h2>
<p>You got lucky! We have no ad to show to you!</p>
</div>
</amp-ad>

<h2>Doubleclick no ad default fallback</h2>
<amp-ad width=300 height=200
type="doubleclick"
data-slot="/4119129/doesnt-exist">
</amp-ad>

<h2>Doubleclick no ad default fallback</h2>
<amp-ad width=300 height=50
type="doubleclick"
data-slot="/4119129/doesnt-exist">
</amp-ad>

</body>
</html>
39 changes: 36 additions & 3 deletions examples/analytics.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@
<title>AMP Analytics</title>
<link rel="canonical" href="analytics.amp.html" >
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-custom>
.box {
background: #ccc;
border: 1px solid #aaa;
padding: 10px;
margin: 10px;
}
</style>
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-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>

<amp-analytics id="analytics1">
<script type="application/json">
{
"host": "example.com",
"requests": {
"base": "/log?domain=DOMAIN&amp;path=PATH&amp;title=${title}",
"event": "${base}&amp;name=${eventName}&amp;type=${eventId}"
"base": "?domain=${canonicalHost}&path=${canonicalPath}&title=${title}",
"event": "${base}&name=${eventName}&type=${eventId}&time=${timestamp}&tz=${timezone}&pid=${pageViewId}&screenSize=${screenWidth}x${screenHeight}"
},
"vars": {
"title": "Example Request"
Expand All @@ -30,25 +39,49 @@
}
}]
}
</script>
</amp-analytics>

<amp-analytics type="googleanalytics" id="analytics2">
<script type="application/json">
{
"vars": {
"account": "UA-XXXX-Y"
},
"triggers": [{
"on": "visible",
"request": "pageview",
"vars" : {
"vars": {
"title": "Example Pageview"
}
}, {
"on": "click",
"selector": "#test1",
"request": "event",
"vars": {
"eventCategory": "examples",
"eventAction": "clicked-test1"
}
}, {
"on": "click",
"selector": "#top",
"request": "event",
"vars": {
"eventCategory": "examples",
"eventAction": "clicked-header"
}
}]
}
</script>
</amp-analytics>

<div class="logo"></div>
<h1 id="top">AMP Analytics</h1>

<span id="test1" class="box">
Click here to generate an event
</span>

</body>
</html>

14 changes: 14 additions & 0 deletions examples/pinterest.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,19 @@ <h4>Large Circle (Red Only, Count Not Available)</h4>
data-description="Next stop: Pinterest">
</amp-pinterest>

<h4>Follow Button</h4>

<amp-pinterest height=20 width=87
data-do="buttonFollow"
data-href="https://www.pinterest.com/zackargyle/"
data-label="Zack Argyle">
</amp-pinterest>

<amp-pinterest height=20 width=87
data-do="buttonFollow"
data-href="https://www.pinterest.com/zackargyle"
data-label="Zack Argyle">
</amp-pinterest>

</body>
</html>
Loading

0 comments on commit 3f14c5c

Please sign in to comment.