Skip to content

Commit

Permalink
Merge pull request #109 from tinkbell/master
Browse files Browse the repository at this point in the history
增加mip-wkfun-club组件,更新其它组件功能
  • Loading branch information
PEI WANG authored Nov 26, 2016
2 parents 5c63d00 + 2752e35 commit eff037d
Show file tree
Hide file tree
Showing 6 changed files with 889 additions and 39 deletions.
43 changes: 34 additions & 9 deletions mip-wkad-config/mip-wkad-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/**
* 寻医问药mip改造 广告配置组件
* @file 脚本支持
* @author [email protected]
* @time 2016.11.25
* @version 1.0.0
*/
define(function (require) {

var $ = require('zepto');
var customElem = require('customElement').create();
var loadJs = function(elem, url, callback){
Expand All @@ -8,26 +14,24 @@ define(function (require) {
script.src = url;
$(elem).append(script);
if(typeof callback != 'function'){

return false;

}else{
script.onload = function(){

callback();
}

}
};
// build 方法,元素插入到文档时执行,仅会执行一次
customElem.prototype.build = function () {
// this.element 可取到当前实例对应的 dom 元素
var elem = this.element;
var attr = $(elem).attr('aid');

var channel = $(elem).attr('channel');
var department = $(elem).attr('department');
switch(attr){
case 'take_ip':
loadJs(elem, 'http://ip.display.xywy.com/take_ip', function(){
loadJs(elem, 'http://ip.display.xywy.com/take_ip', function(){
if(typeof channel == 'undefined'){
loadJs(elem, 'http://a.xywy.com/display/display_load.js', function(){
var ggArr = {};
var string = '';
Expand All @@ -37,18 +41,39 @@ define(function (require) {
ggArr['ad_key'] = string.substr(1);
mobileAd.getAd( ggArr );
});
});
}else{
loadJs(elem, 'http://a.xywy.com/mobile_v3.js', function(){
var ggArr = {};
var string = '';
$.each( keys_arr, function(index, value) {
string = string +'|'+ value;
});
ggArr['ad_key'] = string.substr(1);
ggArr['department'] = department;
mobileAd.getAd( ggArr );
});
}
});
break;
case 'stat':
loadJs(elem, 'http://a.xywy.com/stat.js');
break;
case 'tongji':
loadJs(elem, 'http://stat.xywy.com/a.js');
break;
case 'odm':
loadJs(elem, 'http://stat.xywy.com/odm.js');
break;
case 'visit':
loadJs(elem, 'http://stat.xywy.com/visit.js');
break;
case 'get_ip':
loadJs(elem, 'http://page.xywy.com/get_ip');
break;
default:
break;
}

}

return customElem;
});
62 changes: 58 additions & 4 deletions mip-wkad/mip-wkad.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,80 @@
/**
* 寻医问药mip改造 广告组件
* @file 脚本支持
* @author [email protected]
* @time 2016.11.25
* @version 1.0.0
*/
define(function(require){

var $ = require('zepto');
var customElem = require('customElement').create();
var ua = navigator.userAgent;
var loadAd = function(elem, className, content){
var el = document.createElement('div');
var script = document.createElement('script');
var json = JSON.parse(content);
if(typeof window['keys_arr'] == 'undefined'){
window['keys_arr'] = {};
}
el.className = className;
script.type = 'text/javascript';
script.innerHTML = json.join('');
$(elem).append(el);
$(el).append(script);
};

var parse = function (obj,userAgent,subject) {
if(typeof obj != 'object'){
return;
}
var tmp =obj;
var x;
for( x in tmp){
if(x.substr(0,2) == 'if'){
if(tmp[x].hasOwnProperty('condition_type')){
if(tmp[x]['condition_type'] == 'ua'){
var reg = new RegExp(tmp[x]['condition']);
if(reg.test(userAgent)){
if(tmp[x].hasOwnProperty('return')){
return JSON.stringify(tmp[x]['return']);
}else{
return parse(tmp[x]['body'],userAgent,subject);
}
}
}else if(tmp[x]['condition_type'] == 'in_array'){
if(tmp[x]['condition'].indexOf(subject)>-1){
if(tmp[x].hasOwnProperty('return')){
return JSON.stringify(tmp[x]['return']);
}else{
return parse(tmp[x]['body'],userAgent,subject);
}
}
}
}
}else {
if(tmp[x].hasOwnProperty('return')){
return JSON.stringify(tmp[x]['return']);
}else{
return parse(tmp[x]['body'],userAgent,subject);
}
}
}
}
// build 方法,元素插入到文档时执行,仅会执行一次
customElem.prototype.build = function () {
// this.element 可取到当前实例对应的 dom 元素
var elem = this.element;
var elStr = $(elem).attr('el');
var adStr = $(elem).attr('ads');
loadAd(elem, elStr, adStr);
var complex = $(elem).attr('complex');
var subject = $(elem).attr('subject');
var adJson = null;
if(complex == 'on'){
adJson = JSON.parse($(elem).attr('adJson'));
loadAd(elem, elStr, parse(adJson, ua, subject));
}else{
loadAd(elem, elStr, adStr);
}

}

return customElem;
});
61 changes: 61 additions & 0 deletions mip-wkfun-club/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# mip-wkfun-club

寻医问药页面功能组件

描述|提供了一些dom操作功能
----|----
类型|dom操作组件
支持布局| N/S
所需脚本|https://mipcache.bdstatic.com/static/v1/mip-wkfun-club/mip-wkfun-club.js

## 示例

只需要一个`mip-wkfun-club标签即可`,无须其他填充dom

```
<mip-wkfun-club url="http://3g.xywy.com" pid="110" subject="110" subject_pid="115" qtagname="" sta="1"></mip-wkfun-club>
```

## 属性

### url

说明:数据url
必填:是
格式:字符串
取值:合法的url

### pid

说明:提问id
必填:是
格式:数字
取值:数字

### subject

说明:二级科室id
必填:是
格式:数字
取值:数字

### subject_pid

说明:一级科室id
必填:是
格式:数字
取值:数字

### qtagname

说明:广告tagname
必填:否
格式:字符串
取值:字符串

### sta

说明:广告状态码
必填:是
格式:数字
取值:数字
Loading

0 comments on commit eff037d

Please sign in to comment.