Skip to content

add xiejing.com #838

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

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
50 changes: 50 additions & 0 deletions sites/xiejing.com/mip-adsense/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# mip-adsense

mip-adsense 用来添加谷歌广告

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

## 示例

MIP提供谷歌广告的扩展组件,代码示例:

```
<mip-adsense ad-client="ca-pub-4188721439221378" ad-slot="7961173011" ad-format="auto">
</mip-adsense>
```

## 属性

### ad-client

说明:用户
必选项:是
类型:字符串

### ad-slot

说明:位置
必选项:是
类型:字符串

### ad-format

说明:格式
必选项:否
类型:字符串

### ad-width

说明:宽度
必选项:否
类型:字符串

### ad-height

说明:高度
必选项:否
类型:字符串
46 changes: 46 additions & 0 deletions sites/xiejing.com/mip-adsense/mip-adsense.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file
* 谷歌广告
* @author smileU
* @version 1.1.1
*/
define(function (require) {
var customElement = require('customElement').create();
customElement.prototype.createdCallback = function () {
var ele = this.element;
var adClient = ele.getAttribute('ad-client');
var adSlot = ele.getAttribute('ad-slot');
var adFormat = ele.getAttribute('ad-format');
var insTag = document.createElement('ins');
var width = ele.getAttribute('ad-width');
var height = ele.getAttribute('ad-height');
var scriptTag1 = document.createElement('script');
scriptTag1.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js',
scriptTag1.setAttribute('async', 'true');
var scriptTag2 = document.createElement('script');
if (!(adSlot)) {
scriptTag2.innerHTML = '(adsbygoogle=window.adsbygoogle||[]).push({google_ad_client:"'
+ '' + adClient + '",enable_page_level_ads:true});';
ele.appendChild(scriptTag1);
ele.appendChild(scriptTag2);
}
else {
if (adFormat) {
insTag.setAttribute('data-ad-format', adFormat);
insTag.setAttribute('style', 'display:block');
}
else {
insTag.setAttribute('style', 'display:inline-block;width:' + width + 'px;height:'
+ height + 'px');
}
insTag.classList.add('adsbygoogle');
insTag.setAttribute('data-ad-client', adClient);
insTag.setAttribute('data-ad-slot', adSlot);
scriptTag2.innerHTML = '(adsbygoogle = window.adsbygoogle || []).push({});';
ele.appendChild(scriptTag1);
ele.appendChild(insTag);
ele.appendChild(scriptTag2);
}
};
return customElement;
});
12 changes: 12 additions & 0 deletions sites/xiejing.com/mip-adsense/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "mip-adsense",
"version": "1.0.0",
"description": "sample component",
"author": {
"name": "smileU",
"email": "[email protected]"
},
"engines": {
"mip": ">=1.1.0"
}
}