Skip to content

Commit

Permalink
Merge pull request #268 from jennyliang220/ad-qwang
Browse files Browse the repository at this point in the history
Ad qwang
  • Loading branch information
Pearl Wang authored Dec 26, 2016
2 parents c2aa149 + 8905d4d commit 3089de2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 88 deletions.
112 changes: 42 additions & 70 deletions mip-ad/mip-ad-qwang.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,65 @@
/**
* @file 全网推荐
*
* @author [email protected], liangjiaying<jennyliang220@github>
* 全网推荐
*
* @author [email protected]
* @version 1.0
* @copyright 2016 Baidu.com, Inc. All Rights Reserved
*/


define(function (require) {

/**
* 渲染广告
*
* @param {obj} domEle [description]
* @param {obj} mipEle [description]
*/
function render(domEle, mipEle) {
var cpropsid = domEle.getAttribute('cpro_psid');
var cpropswidth = domEle.getAttribute('cpro_pswidth') || 'auto';
var cpropsheight = domEle.getAttribute('cpro_psheight') || '230';
var cpropstype = domEle.getAttribute('cpro_pstype') || 'embed';

var scriptHtml = '';
if (cpropstype === 'embed') {
scriptHtml = [
'var cpro_psid ="' + cpropsid + '";',
'var cpro_pswidth ="' + cpropswidth + '";',
'var cpro_psheight="' + cpropsheight + '";'
].join('');
}
else {
scriptHtml = 'var cpro_psid ="' + cpropsid + '";';
}

var scriptNode = document.createElement('script');
function render(_this, me) {

var cpropsid = _this.getAttribute("cpro_psid");
var cpropswidth = _this.getAttribute("cpro_pswidth") || "auto";
var cpropsheight = _this.getAttribute("cpro_psheight") || "230";

var scriptHtml = [
'var cpro_psid ="' + cpropsid + '";',
'var cpro_pswidth ="' + cpropswidth + '";',
'var cpro_psheight="' + cpropsheight + '";'
].join('');

var scriptNode = document.createElement("script");
scriptNode.innerHTML = scriptHtml;

var node = document.createElement('div');
var node = document.createElement("div");
node.appendChild(scriptNode);
domEle.appendChild(node);
initJs(node, mipEle, cpropstype);

_this.appendChild(node);
initJs(node, me);
}


/**
* initJs JS初始化函数
*
* @param {dom} node 盛放script的div
* @param {Object} mipEle mip元素
* @param {string} type embed/suspend
* [initJs JS初始化函数]
*
* @return
*/
function initJs(node, mipEle, type) {
var adScript;
if (type === 'embed') {
adScript = addScriptOnce('MIP_ADQW_EMBED', '//su.bdimg.com/static/dspui/js/um_mip.js');
}
else if (type === 'suspend') {
adScript = addScriptOnce('MIP_ADQW_SUSP', '//su.bdimg.com/static/dspui/js/umf_mip.js');
}

if (!adScript) {
return;
}

node.appendChild(adScript);
adScript.onload = function () {
mipEle.applyFillContent(node, true);
};
}
function initJs(node, me) {

/**
* 仅引入一次脚本
*
* @param {string} scriptId 广告脚本标识ID
* @param {string} scriptSrc 广告脚本地址
* @return {obj} false/scriptElement
*/
function addScriptOnce(scriptId, scriptSrc) {
var jsdom = document.getElementById(scriptId);
if (jsdom) {
return false;
}
var WEBADVISEJS = document.getElementById('MIP_WEBADVISE_JS');

if(WEBADVISEJS) return;

var script = document.createElement('script');
script.src = scriptSrc;
script.id = scriptId;
return script;
script.src = '//su.bdimg.com/static/dspui/js/um.js';
script.id = "WEBADVISEJS";

document.body.appendChild(script);

script.onload = function(){

me.applyFillContent(node, true);

};
}

return {
render: render
render:render
};

});


18 changes: 0 additions & 18 deletions mip-ad/mip-ad-qwang.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,16 @@
</mip-ad>
```

### 组件 layout="fixed" 布局

```html
<mip-ad
layout="fixed"
width="414"
height="80"
type="ad-qwang"
cpro_psid="u2619809"
cpro_pswidth="auto"
cpro_psheight="230">
</mip-ad>
```


### 悬浮广告 position="fixed” 布局

如果在广告配置时选择了`单行文字悬浮``双行文字悬浮``图文悬浮`,则应该将`<mip-ad>`嵌入在`<mip-fixed>`中使用,[mip-fixed使用文档](https://www.mipengine.org/doc/3-widget/3-customize-widget/fixed-widget.html)

mip-ad的height对应[组件布局](https://www.mipengine.org/doc/3-widget/11-widget-layout.html)的fixed-height,需要根据广告真实高度填写

```html
<mip-fixed type="bottom">
<mip-ad
type="ad-qwang"
cpro_psid="u2619809"
cpro_pstype="suspend"
height="90"
>
</mip-ad>
</mip-fixed>
Expand Down

0 comments on commit 3089de2

Please sign in to comment.