-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from jennyliang220/ad-qwang
Ad qwang
- Loading branch information
Showing
2 changed files
with
42 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
|
||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters