diff --git a/3p/integration.js b/3p/integration.js index 9eb3c21c2c36..15aa9b53c7d1 100644 --- a/3p/integration.js +++ b/3p/integration.js @@ -112,6 +112,7 @@ import {amoad} from '../ads/amoad'; import {appnexus} from '../ads/appnexus'; import {appvador} from '../ads/appvador'; import {atomx} from '../ads/atomx'; +import {baidu} from '../ads/baidu'; import {bidtellect} from '../ads/bidtellect'; import {brainy} from '../ads/brainy'; import {bringhub} from '../ads/bringhub'; @@ -330,6 +331,7 @@ register('amoad', amoad); register('appnexus', appnexus); register('appvador', appvador); register('atomx', atomx); +register('baidu', baidu); register('beopinion', beopinion); register('bidtellect', bidtellect); register('bodymovinanimation', bodymovinanimation); diff --git a/ads/_config.js b/ads/_config.js index 829501bbd73f..f7018b9760a3 100644 --- a/ads/_config.js +++ b/ads/_config.js @@ -1073,4 +1073,9 @@ export const adConfig = { ], }, + 'baidu': { + prefetch: 'https://dup.baidustatic.com/js/dm.js', + renderStartImplemented: true, + }, + }; diff --git a/ads/baidu.js b/ads/baidu.js new file mode 100644 index 000000000000..4af9a0817aa3 --- /dev/null +++ b/ads/baidu.js @@ -0,0 +1,58 @@ +/** + * 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 { + loadScript, + validateData, +} from '../3p/3p'; + +/** + * @param {!Window} global + * @param {!Object} data + */ +export function baidu(global, data) { + validateData(data, ['cproid']); + + const id = '_' + Math.random().toString(36).slice(2); + const container = global.document.createElement('div'); + container.id = id; + global.document.getElementById('c').appendChild(container); + + global.slotbydup = global.slotbydup || []; + global.slotbydup.push({ + id: data['cproid'], + container: id, + display: 'inlay-fix', + async: true, + }); + + global.addEventListener('message', () => { + global.context.renderStart(); + }); + + loadScript( + global, + 'https://dup.baidustatic.com/js/dm.js', + () => {}, + () => { + // noContentAvailable should be called, + // if parent iframe receives no message. + // setTimeout can work, but it's not that reliable. + // So, only the faliure of JS loading is dealed with for now. + global.context.noContentAvailable(); + } + ); +} diff --git a/ads/baidu.md b/ads/baidu.md new file mode 100644 index 000000000000..3081d47a3d59 --- /dev/null +++ b/ads/baidu.md @@ -0,0 +1,34 @@ + + +# Baidu + +## Example + +```html + + +``` + +## Configuration + +For additional detials and support, see [baidu ad union website](http://union.baidu.com/product/prod-cpro.html). + +### Required Parameters + +* `data-cproid` - baidu union ad id diff --git a/examples/ads.amp.html b/examples/ads.amp.html index 601649968296..7ed2418a9402 100644 --- a/examples/ads.amp.html +++ b/examples/ads.amp.html @@ -102,6 +102,7 @@ + @@ -663,6 +664,12 @@

Atomx

data-id="1234"> +

Baidu

+ + + amoad + @@ -451,6 +452,12 @@

Atomx

data-id="1234">
+

Baidu

+ + +

Bidtellect

amoad | | +| | | | @@ -452,6 +453,12 @@ PASS | data-id="1234"> | | +|

Baidu

+| +| +| |

Bidtellect

|