Skip to content

Commit

Permalink
update extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mip-platform committed Jun 28, 2017
1 parent 1d1fb3c commit 3274a09
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 116 deletions.
7 changes: 2 additions & 5 deletions mip-233-tongji/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

```html

<mip-233-tongji> </mip-233-tongji>

\```


<mip-233-tongji data-host="www.233.com" data-query="?a=1"> </mip-233-tongji>

```
3 changes: 2 additions & 1 deletion mip-233-tongji/mip-233-tongji.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ define(function (require) {
// build 方法,元素插入到文档时执行,仅会执行一次
customElem.prototype.build = function () {
var element = this.element;
var src = $(element).attr('data-host') + $(element).attr('data-query');
var s = document.createElement('script');
s.src = 'https://s95.cnzz.com/stat.php?id=1254966436&web_id=1254966436';
s.src = src;
s.style.display = 'none';
s.language = 'JavaScript';
element.appendChild(s);
Expand Down
124 changes: 14 additions & 110 deletions mip-qqtn-cnzz/mip-qqtn-cnzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,119 +5,23 @@
* @version 1.0
* @copyright 2016 Baidu.com, Inc. All Rights Reserved
*/

define(function (require) {
var $ = require('zepto');
var czc = require('');
var customElement = require('customElement').create();
function mipcnzz() {
var cnzzprotocol = 'https://';
var cnzzid;
var cnzzsite;
var jsStr = '%3Cspan id=\'cnzz_stat_icon_5932461';
jsStr += cnzzid + '\'%3E%3C/span%3E%3Cscript src=\'';
jsStr += cnzzprotocol;
jsStr += cnzzsite;
jsStr += 's12.cnzz.com/stat.php%3Fid%3D593246';
jsStr += cnzzid;
jsStr += '%26show%3Dpic1\' type=\'text/javascript\'%3E%3C/script%3E';
document.write(unescape(jsStr));
}
customElement.prototype.build = function () {
var element = this.element;
var $element = $(element);
var token = element.getAttribute('token');
var setConfig = element.getAttribute('setconfig');
if (token) {
window.czc = window.czc || [];
czc.push([
'_setAccount',
token
]);

// 检测setconfig是否存在
if (setConfig) {
var setCustom = buildArry(decodeURIComponent(setConfig));
czc.push(setCustom);
}

var cnzzScript = document.createElement('script');
var src = 'https://s12.cnzz.com/z_stat.php?id=' + token
+ '&web_id=' + token;
cnzzScript.setAttribute('language', 'JavaScript');
cnzzScript.src = src;
$element.append($(cnzzScript));
bindEle();
}

mipcnzz();
};


// 绑定事件
function bindEle() {
var tagBox = document.querySelectorAll('*[data-stats-cnzz-obj]');

for (var index = 0; index < tagBox.length; index++) {
var statusData = tagBox[index].getAttribute('data-stats-cnzz-obj');

// 检测statusData是否存在
if (!statusData) {
return;
}

try {
statusData = JSON.parse(decodeURIComponent(statusData));
} catch (e) {
return;
}
var eventtype = statusData.type;
if (!statusData.data) {
return;
}
var data = buildArry(statusData.data);

if (eventtype !== 'click' && eventtype !== 'mouseup' && eventtype !== 'load') {
// 事件限制到click,mouseup,load(直接触发)
return;
}

if ($(tagBox[index]).hasClass('mip-stats-eventload')) {
return;
}

$(tagBox[index]).addClass('mip-stats-eventload');

if (eventtype === 'load') {
czc.push(data);
}
else {
tagBox[index].addEventListener(eventtype, function (event) {
var tempData = this.getAttribute('data-stats-cnzz-obj');
if (!tempData) {
return;
}
var statusJson;
try {
statusJson = JSON.parse(decodeURIComponent(tempData));
} catch (e) {
return;
}
if (!statusJson.data) {
return;
}
var attrData = buildArry(statusJson.data);
czc.push(attrData);
}, false);
}
}
}

// 数据换转
function buildArry(arrayStr) {
if (!arrayStr) {
return;
}

var strArr = arrayStr.slice(1, arrayStr.length - 1).split(',');
var newArray = [];

for (var index = 0; index < strArr.length; index++) {
var item = strArr[index].replace(/(^\s*)|(\s*$)/g, '').replace(/\'/g, '');
if (item === 'false' || item === 'true') {
item = Boolean(item);
}

newArray.push(item);
}
return newArray;
}

return customElement;
});

0 comments on commit 3274a09

Please sign in to comment.