Skip to content
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

[platform] xurna123 提交组件改动:mip-qb-ad #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions mip-qb-ad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# mip-qb-ad

mip-qb-ad 组件说明

标题|内容
----|----
类型|通用
支持布局|responsive,fixed-height,fill,container,fixed
所需脚本|https://mipcache.bdstatic.com/static/v1/mip-qb-ad/mip-qb-ad.js

## 示例

### 基本用法
`<mip-qb-ad>` 具有多种类型(`type`),`type` 取值由广告分类决定。

### 1. type=default
| 参数 | 参数值 | 是否必须 |
| -------- | -------- | ------------------------|
| type | default | 是 |
| src | script中src的值 | 是 |

适用于以下广告格式:
```html
<script type="text/javascript" src="广告js地址"></script>
```
示例:
```html
<mip-qb-ad type="default" src="//fzb01.qiushibaike.com/production/sesln1.js?togl=nkpqq"></mip-qb-ad>
```

### 2. type=smua
| 参数 | 参数值 | 是否必须 |
| -------- | -------- | ------------------------|
| type | smua | 是 |
| src | script中smua的属性值 | 是 |

适用于以下广告格式:
```html
<script type="text/javascript" smua="smua属性值" src="//www.smucdn.com/smu0/o.js"></script>
```
示例:
```html
<mip-qb-ad type="smua" src="d=m&s=b&u=u3594595&h=330"></mip-qb-ad>
```

### 3. type=sogou
| 参数 | 参数值 | 是否必须 |
| -------- | -------- | ------------------------|
| type | sogou | 是 |
| src | 搜狗id | 是 |
| script | script中src的值 | 否,默认为`//theta.sogoucdn.com/wap/js/aw.js`|

适用于以下广告格式:
```html
<div id="sogou_wap_搜狗id"></div>
<script>
var sogou_div = document.getElementById("sogou_wap_搜狗id");
window.sogou_un = window.sogou_un || [];
window.sogou_un.push({id: "搜狗id",ele:sogou_div});
</script>
<script async="async" src="//theta.sogoucdn.com/wap/js/aw.js"></script>
```
示例:
```html
<mip-qb-ad type="sogou" src="1000745" script=""></mip-qb-ad>
```

### 3. type=sogou_auto
| 参数 | 参数值 | 是否必须 |
| -------- | -------- | ------------------------|
| type | sogou | 是 |
| src | 搜狗id | 是 |
| w | w值 | 是 |
| h | h值 | 是 |
| script | script中src的值 | 否,默认为`//theta.sogoucdn.com/wap/js/aw.js`|

适用于以下广告格式:
```html
<div id="sogou_wap_搜狗id"></div>
<script>
var sogou_div = document.getElementById("sogou_wap_搜狗id");
window.sogou_un = window.sogou_un || [];
window.sogou_un.push({id: "搜狗id",ele:sogou_div,w:20,h:5});
</script>
<script async="async" src="//theta.sogoucdn.com/wap/js/aw.js"></script>
```
示例:
```html
<mip-qb-ad type="sogou_auto" src="1001690" w="20" h="5" script=""></mip-qb-ad>
```

62 changes: 62 additions & 0 deletions mip-qb-ad/mip-qb-ad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @file mip-qb-ad 组件
* @author
*/

define(function (require) {
'use strict';

let customElement = require('customElement').create();

/**
* 第一次进入可视区回调,只会执行一次
*/
customElement.prototype.firstInviewCallback = function () {
};
/**
* 构造元素,只会运行一次
*/
// build说明: 异步广告备用组件
customElement.prototype.build = function () {
let el = this.element;
let type = el.getAttribute('type') || '';
let src = el.getAttribute('src') || '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mip 组件禁止动态插入 script

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

除了官网提供的广告代码格式,如果有其他格式的广告代码,是不是不能通过自定义组件创建?

let sogouW = el.getAttribute('w') || '';
let sogouH = el.getAttribute('h') || '';
let script = el.getAttribute('script') || '';
let innerScriptNode = document.createElement('script');
let adScriptLoaderNode = document.createElement('script');
let container = document.createElement('div');
container.style.minHeight = '50px';
let scriptHtml = '';
if (type === 'default') {
// 适合只有src属性的单条script
adScriptLoaderNode.src = src;
} else if (type === 'smua') {
// 适合 <script type="text/javascript" smua="d=m&s=b&u=u3687389&h=106" src="//www.smucdn.com/smu0/o.js"></script>
adScriptLoaderNode.src = '//www.smucdn.com/smu0/o.js';
adScriptLoaderNode.setAttribute('smua', src);
} else if (type === 'sogou') {
// 适合异步的sogou广告
container.id = 'sogou_wap_' + src;
scriptHtml = 'var sogou_div = document.getElementById("sogou_wap_' + src + '"); ';
scriptHtml += 'window.sogou_un = window.sogou_un || [];';
scriptHtml += 'window.sogou_un.push({id: ' + src + ',ele:sogou_div});';
adScriptLoaderNode.src = script || '//theta.sogoucdn.com/wap/js/aw.js';
} else if (type === 'sogou_auto') {
// 适合需要自定义配置w和h的搜狗广告
container.id = 'sogou_wap_' + src;
scriptHtml = 'var sogou_div = document.getElementById("sogou_wap_' + src + '"); ';
scriptHtml += 'window.sogou_un = window.sogou_un || [];';
scriptHtml += 'window.sogou_un.push({id: ' + src + ',ele:sogou_div,w:' + sogouW + ',h:' + sogouH + '});';
adScriptLoaderNode.src = script || '//theta.sogoucdn.com/wap/js/aw.js';
}
innerScriptNode.innerHTML = scriptHtml;
// adScriptLoaderNode.onload = () => el.customElement.applyFillContent(container, true)
container.appendChild(innerScriptNode);
container.appendChild(adScriptLoaderNode);
el.appendChild(container);
};

return customElement;
});
7 changes: 7 additions & 0 deletions mip-qb-ad/mip-qb-ad.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @file mip-qb-ad样式文件
*/

mip-qb-ad {
// TODO
}
14 changes: 14 additions & 0 deletions mip-qb-ad/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "mip-qb-ad",
"version": "1.0.0",
"description": "支持smua,sogou等广告代码",
"contributors": [
{
"name": "Xurna Yang",
"email": "565627595@qq.com"
}
],
"engines": {
"mip": ">=1.1.0"
}
}